Created
May 21, 2010 16:25
-
-
Save newsomc/409049 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function write_latitude_and_longitude(lat_long) { | |
var coordinates = String(lat_long).replace(/\(/, ""); | |
coordinates = String(coordinates).replace(/\)/, ""); | |
var coordiantes_array = String(coordinates).split(","); | |
$("#lat_long_container").html("<div class='lat_long_div'><span class='label'>Latitude: </span>" + coordiantes_array[0] + "</div><div class='lat_long_div'><span class='label'>Longitude: </span>" + coordiantes_array[1] + "</div>"); | |
} | |
function generate_xml_doc(lat_long){ | |
var coordinates = String(lat_long).replace(/\(/, ""); | |
coordinates = String(coordinates).replace(/\)/, ""); | |
var coordiantes_array = String(coordinates).split(","); | |
$.post('../xml.php', { | |
lat: coordinates_array[0] , | |
long: coordinates_array[1] | |
}); | |
} | |
var map; | |
var lat_array = []; | |
var lng_array = []; | |
var latlng_counter = 0; | |
var first; | |
function initialize(reset_array, lat, lng) { | |
if (GBrowserIsCompatible()) { | |
if(!lat) | |
lat = 42.276388; | |
if(!lng) | |
lng = -83.737106; | |
if(reset_array == true){ | |
lat_array = []; | |
lng_array = []; | |
} | |
map = new GMap2(document.getElementById("map_canvas")); | |
map.setCenter(new GLatLng(lat, lng), 17); | |
map.addControl(new GSmallMapControl()); | |
map.addControl(new GMapTypeControl()); | |
first = true; | |
} | |
} | |
function add_point() { | |
GEvent.addListener(map, 'click', function(overlay, point) { | |
if(first) { | |
var marker; | |
if (point) { | |
marker = new GMarker(point, {draggable: true}); | |
map.addOverlay(marker); | |
} | |
write_latitude_and_longitude(marker.getLatLng()); | |
$("#map_canvas").mouseup(function() { | |
write_latitude_and_longitude(marker.getLatLng()); | |
}); | |
generate_xml_doc(marker.getLatLng()); | |
first = false; | |
} | |
}); | |
} | |
function update_polygon_lat_lng_container() { | |
$("#polygon_lat_lng_container").html(""); | |
for(i in lat_array) { | |
$("#polygon_lat_lng_container").append(lat_array[i] + " " + lng_array[i] + "<br>"); | |
} | |
} | |
var polygon; | |
function add_polygon() { | |
GEvent.addListener(map, "click", function(overlay, point) { | |
var marker = new GMarker(point); | |
var latlng = marker.getLatLng(); | |
var polygon_array = []; | |
polygon_array.push(latlng); | |
update_polygon_lat_lng_container(); | |
if(latlng_counter == 0) { | |
polygon = new GPolygon(polygon_array, "#f33f00", 5, 1, "#ff0000", 0.2); | |
} | |
else { | |
polygon.insertVertex(latlng_counter, latlng); | |
} | |
latlng_counter = latlng_counter + 1; | |
map.addOverlay(polygon); | |
}); | |
} | |
function remove_last_vertice() { | |
// delete lat_array[latlng_counter]; | |
// delete lng_array[latlng_counter]; | |
polygon.deleteVertex(latlng_counter); | |
latlng_counter = latlng_counter - 1; | |
} | |
function choose_add_type() { | |
if($("#select").val() == "point") { | |
add_point(); | |
} | |
else { | |
add_polygon(); | |
} | |
} | |
$(function() { | |
$(document).keypress(function(e) { | |
remove_last_vertice(); | |
}); | |
initialize(true); | |
choose_add_type(); | |
$("#select").change(function(){ | |
initialize(false); | |
choose_add_type(); | |
}); | |
$(document).keyup(function(e) { | |
if(e.which == 27) { | |
initialize(true); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment