2012-12-21 24 views
0

我正在使用ArcGis javascript api 3.2。我有一張地圖和一個圖層。 我將如何獲得鼠標點擊事件發生在其中的多邊形幾何?Arcgis javascript api-獲取多邊形幾何體

+0

你並不需要在您的文章署名找到詳細的樣本。閱讀[常見問題](http://stackoverflow.com/faq#signatures)瞭解更多詳情。 – Artemix

回答

0

不僅僅是多邊形ID,你可以通過這樣得到的地圖服務的任何參數...

1)通過將地圖服務作爲參數創建一個新的IdentifyTask()。

identifyTask = new esri.tasks.IdentifyTask("<Map Service URL should go here>"); 

2)創建一個新的IdentifyParameters()並設置下列屬性。

identifyParams = new esri.tasks.IdentifyParameters(); 
identifyParams.tolerance = 2; 
identifyParams.returnGeometry = true; 
identifyParams.layers = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL; 
identifyParams.layerIds = [0,1,2,3,4]; 
identifyParams.sr=map.spatialreference; 
identifyParams.width = map.width; 
identifyParams.height = map.height; 

3)應在鼠標單擊時調用方法。你可以這樣做

dojo.connect(map, "onClick", uponClick); 

4)當一個多邊形被點擊時,onClick()方法將被調用。在onClick()方法中,通過傳遞identifyParams作爲參數來調用identifyTask.execute。

function uponClick(evt){ 
    identifyParams.geometry = evt.mapPoint; 
    identifyParams.mapExtent = map.extent; 
    identifyTask.execute(identifyParams, function(result) { 
    for(var i=0; i<result.length; i++){       
     polyId=result[i].feature.attributes["UNIQPOLYID"]; 
    }//end of for 
    });//end of execute 
}//end of uponClick 

UNIQPOLYID是地圖服務將返回的方法之一。您的用戶卡被自動添加 -

你可以在這個環節

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/find_drilldown.html

相關問題