Last active
August 4, 2017 22:03
-
-
Save maplinkapi/5490562 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
var divIdName = "divMap"; | |
var zoomLevel = 14; | |
var map; | |
var points = []; | |
var polygon; | |
var lineColor = "#0000af"; | |
var lineWeight = 3; | |
var lineOpacity = .8; | |
map = new MMap2(document.getElementById(divIdName)); | |
map.setCenter(new MPoint(-46.6520066, -23.5650127), zoomLevel); | |
fillPoints(); | |
drawOverlay(); | |
LBS.Event.addListener(map, "click", leftClick); | |
function fillPoints() { | |
points.push(new MPoint("-46.665053144064", "-23.566272129476")); | |
points.push(new MPoint("-46.649603620139", "-23.559270111905")); | |
points.push(new MPoint("-46.640848889914", "-23.5705990324")); | |
points.push(new MPoint("-46.656040921775", "-23.576341792472")); | |
} | |
function drawOverlay() { | |
for (var i = 0; i < points.length; i++) { | |
polygon = new GPolygon(points, lineColor, lineWeight, lineOpacity, "#AAA", 0.5); | |
} | |
map.addOverlay(polygon); | |
} | |
function leftClick(e, point) { | |
var point = map.getLatLngFromPixel(e.xy); | |
var getPoints = function (points) { | |
var pointsLatLngs = ""; | |
for (var i = 0; i < points.length; i++) { | |
pointsLatLngs += "X=" + polygon.latlngs[i].x; | |
pointsLatLngs += ",Y=" + polygon.latlngs[i].y; | |
pointsLatLngs += "<br>"; | |
} | |
return pointsLatLngs; | |
} | |
var isWithinPolygon = function (polygon, point) { | |
return polygon.atPoint(point); | |
} | |
var openInfoWindow = function (map, content) { | |
map.closeInfoWindow(); | |
map.infoWindow = new LBS.InfoWindow(map.getCenter(), content); | |
map.infoWindow.map = map; | |
var infoDiv = map.infoWindow.draw(); | |
if (infoDiv) { | |
infoDiv.style.zIndex = map.Z_INDEX_BASE['InfoWindow']; | |
map.layerContainerDiv.appendChild(infoDiv); | |
} | |
} | |
if (isWithinPolygon(polygon, point)) { | |
var points = getPoints(polygon.latlngs); | |
openInfoWindow(map, points); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment