ArcGis javascriptapi3.2を使用しています。マップとその上にレイヤーがあります。マウスクリックイベントが発生するポリゴンジオメトリを取得するにはどうすればよいですか?
1864 次
1 に答える
0
ポリゴンIDだけでなく、これを行うことでマップサービスから任意のパラメータを取得できます...
1)MapServiceをパラメーターとして渡して、新しい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()メソッドが呼び出されます。uponClick()メソッド内で、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は、マップサービスが返すメソッドの1つです。
このリンクで詳細なサンプルを見つけることができます
于 2012-12-28T03:26:47.500 に答える