简体   繁体   中英

Arcgis javascript api-Getting polygon geometry

I am working with 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...

1)Create a new IdentifyTask() by passing the MapService as the parameter.

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

2)Create a new IdentifyParameters() and set the following attributes.

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. You can do that like

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

4) When a polygon is clicked, uponClick() method will be called. Inside the uponClick() method, call the identifyTask.execute by passing identifyParams as parameter.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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