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
var map; | |
var poly; | |
var count = 0; | |
var points = new Array(); | |
var markers = new Array(); | |
var lineColor = "#0000af"; | |
var fillColor = "#335599"; | |
var lineWeight = 3; | |
var lineOpacity = .8; | |
var fillOpacity = .2; | |
var divIdName = "divMap"; | |
var divInfoName = "divInfo"; | |
var zoomLevel = 14; | |
map = new MMap2(document.getElementById(divIdName), { draggableCursor: "auto", draggingCursor: "move" }); | |
map.setCenter(new MPoint(-46.6520066, -23.5650127), zoomLevel); | |
map.addControl(new GLargeMapControl()); | |
LBS.Event.addListener(map, "click", leftClick); | |
function leftClick(e, point) { | |
var point = map.getLatLngFromPixel(e.xy); | |
if (!point) | |
return; | |
count++; | |
var marker = new MMarker(point, { | |
icon: G_DEFAULT_ICON, | |
draggable: true, bouncy: false, | |
dragCrossMove: true | |
}); | |
marker.content = count; | |
markers.push(marker); | |
marker.tooltip = "Point " + count; | |
LBS.Event.addListener(marker, "mouseover", function () { }); | |
LBS.Event.addListener(marker, "mouseout", function () { }); | |
// Drag listener | |
LBS.Event.addListener(marker, "drag", function (e) { | |
drawOverlay(); | |
}); | |
LBS.Event.addListener(marker, "click", function (e) { | |
}); | |
// Second click listener | |
LBS.Event.addListener(marker, "click", function (e) { | |
// Find out which marker to remove | |
for (var n = 0; n < markers.length; n++) { | |
if (markers[n] == marker) { | |
map.removeOverlay(markers[n]); | |
break; | |
} | |
} | |
// Shorten array of markers and adjust counter | |
markers.splice(n, 1); | |
if (markers.length == 0) { | |
count = 0; | |
} | |
else { | |
count = markers[markers.length - 1].content; | |
drawOverlay(); | |
} | |
}); | |
map.addOverlay(marker); | |
drawOverlay(); | |
} | |
function clearMap() { | |
map.clearOverlays(); | |
points.length = 0; | |
markers.length = 0; | |
count = 0; | |
document.getElementById("status").innerHTML = " "; | |
} | |
function drawOverlay() { | |
if (poly) { map.removeOverlay(poly); } | |
points.length = 0; | |
for (i = 0; i < markers.length; i++) { | |
points.push(markers[i].getLatLng()); | |
poly = new GPolygon(points, lineColor, lineWeight, lineOpacity, "#AAA", 0.5); | |
} | |
map.addOverlay(poly); | |
} | |
function toggleMode() { | |
if (markers.length > 1) drawOverlay(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment