Here's what I do:
Setup a PointToExtent Function that allows you pass a pointer tolerance in as a parameter base on map extent width in map coordintates thus:
Function pointToExtent (mapMain, point, toleranceInPixel) {
var pixelWidth = mapMain.extent.getWidth() / mapMain.width;
var toleranceInMapCoords = toleranceInPixel * pixelWidth;
return new Extent(point.x - toleranceInMapCoords,
point.y - toleranceInMapCoords,
point.x + toleranceInMapCoords,
point.y + toleranceInMapCoords,
mapMain.spatialReference);
}
then, in on-style wiring of your feature layers' query, pass the function to the geometry property of your query, along with a tolerance setting in pixels. Keep in mind that pixel tolereances change depending on resolution and scale, so you'll have to make some adjustments. Also, Jeff Pace employes a slightly different method that is not as resolution depenedent as what I'm showing here, so I would search his posts as well-
|
on(lyrName, 'click', function (event) { //mapMain |
var query = new Query();
query.geometry = pointToExtent(mapMain, event.mapPoint, 10);
var deferred = lyrF.selectFeatures(query, //featurelayer
FeatureLayer.SELECTION_NEW);
mapMain.infoWindow.setFeatures([deferred]);
mapMain.infoWindow.show(event.mapPoint);
});
Here, '10' is my pixel tolerance in map coords, (meters) and seems to work pretty well for line features in WebMercator