Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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