javascriptarcgis-js-apiesri-maps

finding is point laying on line or not in esri map using arcgis API


I am trying to find whether the point lies on the line or not as below

 function identifyFeatures(evt){
     var extentGeom = pointToExtent(map,evt.mapPoint,10);
     var filteredGraphics = dojo.filter(testLayer.graphics, function(gg) {
         if(extentGeom.contains(gg.geometry.getExtent())){
             return extentGeom.contains(gg.geometry.getExtent());
         } else {
             return gg.geometry.getExtent().contains(extentGeom);
         } 
      });
      var content = "";
      content = "<i>Total Features: " + filteredGraphics.length + "</i>";
      map.infoWindow.setContent(content);
      map.infoWindow.setTitle("Identify Results");
      var anchor = map.getInfoWindowAnchor(evt.screenPoint);
      map.infoWindow.show(evt.screenPoint,anchor);
 };

I am using contains method of extent and trying to check whether clicked point extent is falling on line extent or line extent is falling on clicked point extent.But if I click on the center of the line then only I am getting features. You can see the code fiddle

can any one suggest me is there any other way to check whether point lies on line or not?


Solution

  • You should just filter graphics if the extent of the point (padded with your extentToPoint() function) intersects() with the geometry of the line.

      function identifyFeatures(evt){
          var extentGeom = pointToExtent(map,evt.mapPoint,10);
          var filteredGraphics = dojo.filter(testLayer.graphics, function(gg) {
            return extentGeom.intersects(gg.geometry);
          });
          var content = "<i>Total Features: " + filteredGraphics.length + "</i>";
          map.infoWindow.setContent(content);
          map.infoWindow.setTitle("Identify Results");
          map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
      };
    

    see a working demo: https://jsfiddle.net/q68rzde2/1/