Select to view content in your preferred language

Query a point on a layer

735
5
02-01-2012 12:22 AM
StevenColeman-Williams
Emerging Contributor
So I have a layer with contains points (yay)

I currently have

private function findAddressPoint(geom:Geometry):void {
 var q:Query = new Query();
 q.geometry = geom;
 q.spatialRelationship = Query.SPATIAL_REL_CONTAINS;
 q.returnGeometry = true;
 q.outFields = ["*"];

 var task:QueryTask = new QueryTask();
 task.url = "http://svr-met-gisdev1:8399/arcgis/rest/services/M4/GIS_MasterMap/MapServer/1";
 task.execute(q, new AsyncResponder(onResult, onFail));
}


but no matter how acuratly i click i never get any results back, what am i doing wrong

it should be a point - point comparison (does geomA == geomB)

is there a nice quick easy way to add a 5px tolerance around the point thats clicked?
Tags (2)
0 Kudos
5 Replies
IvanBespalov
Frequent Contributor
Steven,

is there a nice quick easy way to add a 5px tolerance around the point thats clicked?


var q:Query = new Query();
if (yourgeometry is MapPoint)
{
    var mappoint:MapPoint = yourgeometry as MapPoint;
    var newextent:Extent = new Extent(); // not a buffered point, but it works
    var delta:Number = 10;
    newextent.minx = mappoint.xvalue -delta;
    newextent.miny = mappoint.yvalue -delta;
    newextent.maxx = mappoint.xvalue +delta;
    newextent.maxy = mappoint.yvalue +delta;
    q.geometry = newextent;
}
else
{
    q.geometry = yourgeometry;
}


You can also buffer your geometry using GeometryService - http://help.arcgis.com/en/webapi/flex/samples/01nq/01nq00000023000000.htm
0 Kudos
StevenColeman-Williams
Emerging Contributor
Ivan,
thanks that worked
but what is delta?
is that 10 whats?

i only need 10px worth where as yours i think will be doing close to 1km, but i need to be reasonably precise
0 Kudos
KenBuja
MVP Esteemed Contributor
Have you considered using IdentifyTask instead? IdentifyParameters contains a property for setting the tolerance in screen pixels.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Steven,

   Or you could use a function like this to add pixels to the map point instead of map units:

            private function createExtentAroundMapPoint(centerPoint:MapPoint, tolerance:Number):Extent
            {
                var screenPoint:Point = map.toScreen(centerPoint as MapPoint);
                
                var upperLeftScreenPoint:Point = new Point(screenPoint.x - tolerance, screenPoint.y - tolerance);
                var lowerRightScreenPoint:Point = new Point(screenPoint.x + tolerance, screenPoint.y + tolerance);
                
                var upperLeftMapPoint:MapPoint = map.toMap(upperLeftScreenPoint);
                var lowerRightMapPoint:MapPoint = map.toMap(lowerRightScreenPoint);
                
                return new Extent(upperLeftMapPoint.x, upperLeftMapPoint.y, lowerRightMapPoint.x, lowerRightMapPoint.y, map.spatialReference);
            }
0 Kudos
StevenColeman-Williams
Emerging Contributor
Thank's guys
i managed to get buffered point working in the end 🙂
0 Kudos