Query Graphic

721
4
Jump to solution
12-27-2017 07:11 PM
chengyiwang
New Contributor

HI

How  to query  graphiclayer  with polygon ?

                   Thank you.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Chengyi,

  Well then you need to do exactly what I mentioned then.

require(["esri/geometry/geometryEngine"], function(geometryEngine) { 
  view.graphics.forEach(function(gra){
    if(geometryEngine.intersects(gra, userDrawnGraphic)){
      /* now do something */
    }
  });
});

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

To query a graphics layer you have to loop through the layers graphics and perform your operation on each graphic.

You can use GeometryEngine methods like intersects:

https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#intersects 

Or if the geometry you want to check is a point geometry, to check if it is inside a polygon then you can use Polygon.contains

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

0 Kudos
chengyiwang
New Contributor

Thank you very much !

      Let me explain. Many ploygon are drawn on the graphic when the map is initialized,then I want to draw a new ploygon to search the old ploygon with 4.5 arcgis api for javascript . How to do?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chengyi,

  Well then you need to do exactly what I mentioned then.

require(["esri/geometry/geometryEngine"], function(geometryEngine) { 
  view.graphics.forEach(function(gra){
    if(geometryEngine.intersects(gra, userDrawnGraphic)){
      /* now do something */
    }
  });
});
chengyiwang
New Contributor

Scheitlin

year,this is I needed. thankyou verymuch.

0 Kudos