简体   繁体   English

Arcgis JavaScript API-获取多边形几何

[英]Arcgis javascript api-Getting polygon geometry

I am working with ArcGis javascript api 3.2. 我正在使用ArcGis javascript API 3.2。 I have a map and a layer over it. 我有一张地图,上面有一层。 How would i get the polygon geometry inside which the mouse click event occurs? 如何获得发生鼠标单击事件的多边形几何?

Not just the polygon id, you could get any parameter from a map service by doing this... 不仅是多边形ID,执行此操作还可以从地图服务中获取任何参数...

1)Create a new IdentifyTask() by passing the MapService as the parameter. 1)通过传递MapService作为参数来创建一个新的IdentifyTask()。

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

2)Create a new IdentifyParameters() and set the following attributes. 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) A method should be invoked upon mouse click. 3)鼠标单击时应调用一种方法。 You can do that like 你可以那样做

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

4) When a polygon is clicked, uponClick() method will be called. 4)单击多边形时,将调用onClick()方法。 Inside the uponClick() method, call the identifyTask.execute by passing identifyParams as parameter. 在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 is one of those methods that the map service would return. UNIQPOLYID是地图服务将返回的那些方法之一。

You could find a detailed sample at this link 您可以在此链接中找到详细的示例

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM