[GIS] How to find whether a Point lies inside a Polygon using ArcGIS JavaScript API

arcgis-javascript-api

We want to find whether a Point lies inside a Polygon.

var point = new esri.geometry.Point(-85.91,25.68,this.parent.esriMap.spatialReference);    

var polygon = new esri.geometry.Polygon(this.parent.esriMap.spatialReference);

polygon .addRing([contains the lat and long]);

boolean result=polygon .contains(point);   

The moment I add the contains method call (polygon .contains(point);), I get an error stating that ESRIMapViewer does not have a constructor. ESRIMapViewer.js is the file which contains the above code.

Best Answer

i've posted a working sample here

var polygon = new Polygon(new SpatialReference({wkid:4326}));
polygon.addRing([[-120,30],[-120,40],[-110,40],[-110,30],[-120,30]])

var point = new Point(-115, 35, {"spatialReference":{"wkid":4326 }})
polygon.contains(point); //returns true

are you sure that the SpatialReference you are digging out of your map is WGS84 and not WebMercator?