新的图标上去。 // Create a base icon for all of our markers that specifies the shadow,
icon // dimensions, etc. var baseIcon = new GIcon(); baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png"; baseIcon.iconSize = new GSize(20, 34); baseIcon.shadowSize = new GSize(37, 34); baseIcon.iconAnchor = new GPoint(9, 34); baseIcon.infoWindowAnchor = new GPoint(9, 2); baseIcon.infoShadowAnchor = new GPoint(18, 25); // 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 a marker whose info window displays the letter corresponding
to // the given index function createMarker(point, index) { // Create a lettered icon for this point using our icon class from above var letter = String.fromCharCode("A".charCodeAt(0) + index); var icon = new GIcon(baseIcon); icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png"; var marker = new GMarker(point, icon); // Show this marker's index in the info window when it is clicked var html = "Marker <b>" + letter + "</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); map.addOverlay(marker);
}
在地图上使用XML和异步远程方法调用Using XML and Asynchronous RPC('AJAX') 在这个例子中,我们下载了一个静态文件"data.xml",这个文件包含有一系列以XML存储的经纬度坐标。当下载完成后,我们解析这个XML文件并在每个经­-纬度交汇处,创建一个图标。