2015-01-20 87 views
0

這裏是休息的服務,我從工作: http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3地塊多邊形

我當前呼叫顯示功能層如下:

var recLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3",{ 
    infoTemplate: recParkTemplate, 
    outFields: ["STATE_NAME"] 
    }); 
map.addLayer(recLayer); 

然而,代替繪圖地圖上的多邊形,因爲這是一個esriGeometricPolygon。我寧願讓它像esriGeometryPoint一樣在地圖上繪製。我知道在得到具體的多邊形的質心這個方法:

https://developers.arcgis.com/javascript/jsapi/polygon-amd.html#getcentroid

我的問題是我不能在功能層的所有多邊形中找出如何循環,然後畫出那些多邊形。我只能點擊並顯示類似於此ESRI示例的工作方式:https://developers.arcgis.com/javascript/jssamples/util_label_point.html

感謝您的幫助。 這是目前的網站,如果你想看看它:http://joshferrell.net/ece_project/

回答

0

循環中的功能層的所有幾何圖形,你可以做這樣的事情之中:

  recLayer.on("update-end", function changeHandler(evt) { 
      require(["dojo/_base/array"], function (array) { 

       array.forEach(recLayer.graphics, function (entry, i) { 
        console.debug(entry, "at index", i); 
       }); 
      }); 
     }); 

內循環使用getCentroid並將結果添加到地圖