1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| var infowindow = new google.maps.InfoWindow();
function loadZone() {
if(typeof(json_string) !== 'undefined') {
shapes = new google.maps.MVCArray;
var shapesOptions = {
fillColor: '#0000FF',
strokeWeight: 1,
clickable: true,
zIndex: 1,
editable: false
};
var json_data_object = eval("(" + json_string + ")");
for(var i in json_data_object) {
var zone = json_data_object[i];
if(zone.id == document.getElementById("siteid").value) continue;
if(zone.show == '0') continue;
if(zone.type == "circle") {
var shapeCircle = new google.maps.Circle({
center: new google.maps.LatLng(zone.data.lat, zone.data.lng),
radius: parseFloat(zone.data.rad),
options: shapesOptions
});
shapes.push(shapeCircle);
addInfowindowToShape(shapeCircle, zone);
shapeCircle.setMap(map);
}
if(zone.type == "polygon") {
var path = new google.maps.MVCArray;
for(var j in zone.data) {
path.insertAt(j, new google.maps.LatLng(zone.data[j].lat, zone.data[j].lng));
}
var shapePolygon = new google.maps.Polygon({
path: path,
options: shapesOptions
});
shapes.push(shapePolygon);
addInfowindowToShape(shapePolygon, zone);
shapePolygon.setMap(map);
}
}
}
}
function addInfowindowToShape(theShape, zoneData) {
google.maps.event.addListener(shapes.getAt(shapes.getLength() - 1), 'click', function(event) {
infowindow.setPosition(event.latLng);
infowindow.setContent('<h3>' + zoneData.name + '</h3><small>' + zoneData.desc + '</small>' );
infowindow.open(map);
});
} |
Partager