var html = "Marker #<b>" + number + "</b>"; GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); return marker;
}
// Add 10 random markers in the map viewport var bounds = map.getBoundsLatLng(); var width = bounds.maxX - bounds.minX; var height = bounds.maxY - bounds.minY; for (var i = 0; i < 10; i++) { var point = new GPoint(bounds.minX + width * Math.random(), bounds.minY + height * Math.random()); var marker = createMarker(point, i + 1); map.addOverlay(marker);
信息窗口。 // Create our "tiny" marker icon var icon = new GIcon(); icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png"; icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; icon.iconSize = new GSize(12, 20); icon.shadowSize = new GSize(22, 20); icon.iconAnchor = new GPoint(6, 20); icon.infoWindowAnchor = new GPoint(5, 1); // Center the map on Palo Alto var map = new GMap(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.centerAndZoom(new GPoint(-122.141944, 37.441944), 4); // Creates one of our tiny markers at the given point function createMarker(point) { var marker = new GMarker(point, icon); map.addOverlay(marker); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml("You clicked me!"); });
}
// Place the icons randomly in the map viewport var bounds = map.getBoundsLatLng(); var width = bounds.maxX - bounds.minX; var height = bounds.maxY - bounds.minY; for (var i = 0; i < 10; i++) { createMarker(new GPoint(bounds.minX + width * Math.random(), bounds.minY + height * Math.random()));