Yahoo Maps 範例六 - 地圖上任意的置放五個點 | 回上頁 |
別忘了, 你可以利用瀏覽器上的 "檢視" -> "原始檔" (Internet Explorer) 或 "檢視" -> "此頁原始內容" (Firefox), 來觀看程式.
<script type="text/javascript"> var myPoint = new YGeoPoint(25.047795,121.5169); var map = new YMap(document.getElementById('mapContainer'),YAHOO_MAP_REG,new YSize(600,360)); map.drawZoomAndCenter(myPoint, 8); map.addZoomLong(); function createYahooMarker(geopoint, num) { var myImage = new YImage(); myImage.src = 'http://us.i1.yimg.com/us.yimg.com/i/us/map/gr/mt_ic_c.gif'; myImage.size = new YSize(20,20); myImage.offsetSmartWindow = new YCoordPoint(0,0);
var marker = new YMarker(geopoint,myImage);
var label = "<img src=http://us.i1.yimg.com/us.yimg.com/i/us/ls/gr/" + num + ".gif>"; marker.addLabel(label);
var swtext = "Marker <b> " + num + "</b>"; YEvent.Capture(marker,EventsList.MouseClick, function() {marker.openSmartWindow(swtext) }); return marker;
} var bounds = map.getBoundsLatLon();
var height = bounds.LatMax - bounds.LatMin;
var width = bounds.LonMax - bounds.LonMin;
for (var i = 1; i <= 5; i++) { var GeoPoint = new YGeoPoint(bounds.LatMin + height * Math.random(), bounds.LonMin + width * Math.random());
var marker = createYahooMarker(GeoPoint,i);
map.addOverlay(marker);
</script> |