From c62351aaafaea25dea1688ad23f7b23c3e113b15 Mon Sep 17 00:00:00 2001 From: jonsowman Date: Tue, 8 Jun 2010 15:16:20 +0100 Subject: [PATCH] Draws a lat-lon delta square around launch position closes #40 --- predict/index.php | 6 ++++++ predict/js/pred.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/predict/index.php b/predict/index.php index d5b33c7..6e02dfa 100644 --- a/predict/index.php +++ b/predict/index.php @@ -120,6 +120,12 @@ function initialize() { $("#about_window_show").click(function() { $("#about_window").fadeIn(); }); + $("#delta_lat").change(function() { + drawDeltaSquare(map); + }); + $("#delta_lon").change(function() { + drawDeltaSquare(map); + }); // plot the initial launch location plotClick(); google.maps.event.addListener(map, 'mousemove', function(event) { diff --git a/predict/js/pred.js b/predict/js/pred.js index c3fde14..26d8866 100644 --- a/predict/js/pred.js +++ b/predict/js/pred.js @@ -293,6 +293,19 @@ function parseCSV(lines) { } +function drawPolygon(points, gmap_object) { + var newPoly = new google.maps.Polygon({ + paths: points, + strokeColor: "#FF0000", + strokeOpacity: 0.4, + fillColor: "#FFFFFF", + fillOpacity: 0, + strokeWeight: 2, + }); + map_items['delta_square'] = newPoly; + newPoly.setMap(gmap_object); +} + function plotClick() { // clear the old marker clearMapItems(); @@ -307,10 +320,30 @@ function plotClick() { title: 'Currently selected launch location ('+click_lat+', '+click_lon+')' }); map_items['clickMarker'] = clickMarker; + // redraw the delta square + drawDeltaSquare(map); map.panTo(click_pt); map.setZoom(8); } +function drawDeltaSquare(map) { + // clear any old squares + if ( map_items['delta_square'] ) map_items['delta_square'].setMap(null); + // get the values from the form + var lat = parseFloat($("#lat").val()); + var lon = parseFloat($("#lon").val()); + var dlon = parseFloat($("#delta_lat").val()); + var dlat = parseFloat($("#delta_lon").val()); + // make a rectange of points + var points = [ + new google.maps.LatLng(lat+dlat, lon+dlon), + new google.maps.LatLng(lat-dlat, lon+dlon), + new google.maps.LatLng(lat-dlat, lon-dlon), + new google.maps.LatLng(lat+dlat, lon-dlon) + ] + // write the poly to the map + drawPolygon(points, map); +} function setFormLatLon(GLatLng) { $("#lat").val(GLatLng.lat().toFixed(4));