2015-11-03 41 views
0

下面的代碼創建一個新的地圖並添加一個圖層。我不想創建一個新的地圖,我想通過一個id添加一個webmap。我如何使用我的ID加載一個webmap?我還想來加載,而不是創建一個新的地圖我webmap:Arcgis Javascript Api - 通過Id顯示WebMap

var initExtent = new esri.geometry.Extent({ "xmin": -89.26, "ymin": 15.85, "xmax": -88.13, "ymax": 18.75, "spatialReference": { "wkid": 5326 } }); 


    map = new esri.Map("map",{ 
     extent:esri.geometry.geographicToWebMercator(initExtent), 
     wrapAround180 : true 
    }); 

    dojo.connect(map, 'onLoad', onMapLoaded); 

    //Add the topographic layer to the map. View the ArcGIS Online site for services http://arcgisonline/home/search.html?t=content&f=typekeywords:service 
    var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer", { 
      id: 'basemap' 
     }); 
    currentBasemap = basemap; 
    map.addLayer(currentBasemap); 

    //Add some basic layers 
    var rivers = new esri.layers.FeatureLayer("http://services.arcgis.com/LxfKOYkTamDQYlsa/arcgis/rest/services/PollingStations2015/FeatureServer/0", { 
     mode: esri.layers.FeatureLayer.MODE_ONDEMAND, 
     outFields: ["*"] 
    }); 


    map.addLayers([rivers]); 

回答

0

使用createMap功能esri.arcgis.utilsThis sample顯示如何。這裏是最相關的代碼:

arcgisUtils.createMap("4778fee6371d4e83a22786029f30c7e1","map") 
.then(function(response) { 
    var map = response.map; 
    //The map is loaded, so you can directly call your onMapLoaded function... 
    onMapLoaded(map);  
}); 

你需要包括"esri/arcgis/utils"作爲arcgisUtils在您需要的模塊列表。

+0

該示例不會在我的瀏覽器上運行。你試過了嗎? – ivias

+0

是的,使用Chrome。 –

+0

我使用Chrome和Firefox以及Internet Explorer嘗試了它。它不加載地圖。我沒有得到任何錯誤,我使用我的webap id沒有運氣。你知道你鏈接的樣本有問題嗎? – ivias