2010-10-04 34 views

回答

0

我已經創建了雅虎動態地圖,該地址可以作爲頁面中隱藏字段的值傳遞。隱藏字段的值可以在page_load事件中動態傳遞。我在ASP.Net的母版頁封裝的子頁面中創建了這個。

在開始之前,用戶必須通過登錄您的雅虎ID並導航到此鏈接https://login.yahoo.com/config/login_verify2?.src=devnet&.done=http://developer.apps.yahoo.com/wsregapp/並提供我們的網站URL來生成使用雅虎地圖的應用程序ID。

用於顯示雅虎地圖的代碼如下給出:

.MAP { 高度:400像素; 寬度:700px; font-family:Verdana; font-size:11px; font-weight:bold; }

<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=YourAPPID"> 
</script> 

<script type="text/javascript"> 

    // Capture the user mouse-click and expand the SmartWindow 
    function onSmartWinEvent() { 


     // Create a map object 
     var map = new YMap(document.getElementById('<%= map.ClientID %>')); 
     // Add a pan control 
     map.addPanControl(); 
     // Add a slider zoom control 
     map.addZoomLong(); 
     // Display the map centered on the address specified   
     map.drawZoomAndCenter(document.getElementById('<%= HiddenField1.ClientID %>').value, 3); 
     // Create a marker positioned at the address specified 
     var marker = new YMarker(document.getElementById('<%= HiddenField1.ClientID %>').value, createCustomMarkerImage()); 
     // Add a label to the marker 
     //marker.addLabel("<blink>*</blink>"); 
     // Call onSmartWinEvent when the user clicks on the marker 
     YEvent.Capture(marker, EventsList.MouseClick, onSmartWinEvent); 
     // Display the marker 
     map.addOverlay(marker); 


     var words = document.getElementById('<%= HiddenField1.ClientID %>').value; 
     marker.openSmartWindow(words); 

     // Add map type control 
     map.addTypeControl(); 
     // Default map to satellite (YAHOO_MAP_REG) -- other opts: YAHOO_MAP_HYB,YAHOO_MAP_SAT 
     map.setMapType(YAHOO_MAP_REG); 
    } 

    function createCustomMarkerImage() { 
     var myImage = new YImage(); 
     myImage.src = 'http://l.yimg.com/www.flickr.com/images/dot_splat.png'; 
     myImage.size = new YSize(30, 31); 
     myImage.offsetSmartWindow = new YCoordPoint(15, 15); 
     return myImage; 
    } 
</script> 

<table width="100%" align="left">   
    <tr> 
     <td> 
      <body onload="onSmartWinEvent()"> 
       <div id="map" class="map" runat="server"> 
       </div> 
       <asp:HiddenField ID="HiddenField1" runat="server" /> 
      </body> 
     </td> 
    </tr> 
</table> 

注:速率限制:在雅虎AJAX Maps API每天每IP限制爲50,000個查詢。查看該鏈接 http://developer.yahoo.com/search/rate.html