Select to view content in your preferred language

Problem Selecting Point Features

677
2
10-20-2010 01:14 PM
MattMoyles
Occasional Contributor
I'm having a problem selecting Point features on my feature layer.  I'm using code which worked for me selecting polygons and other features but I can't seem to make it work for points on this widget.

When my widget opens it loads the FeatureService layer and I see all the points.  On widget init I set an event listener like so:

map.addEventListener(MapMouseEvent.MAP_CLICK, map_mapClickHandler);
lnoLayer.addEventListener(FeatureLayerEvent.SELECTION_COMPLETE, featureLayer_selectionComplete, false, 1);

private function map_mapClickHandler(event:MapMouseEvent):void
            {
                trace("mapClickHandler()");
                
                var queryMapClick:Query = new Query();
                queryMapClick.geometry = event.mapPoint;
                lnoLayer.selectFeatures(queryMapClick);
            }

private function featureLayer_selectionComplete(event:FeatureLayerEvent):void
            {                
                trace("called selection complete");
                status1.text = "";
                status2.text = "";
                status3.text = "";
                status4.text = "";
                status5.text = "";
                status6.text = "";
                
                //a feature was found
                if (event.featureLayer.selectedFeatures.length > 0)
                {                    
                    event.featureLayer.selectionColor = 0x000000;                    
                    refreshFieldsFromServer();
                }    
            }


When I click the map I can see that the function is being called by the trace(), but it will not select the features and I do not see "called selection complete" since the feature never gets selected.  Also I will note that if I change my mapClickHandler function to something like the code below it will select the features fine.  So I has to be some problem with setting the right geometry.

private function map_mapClickHandler(event:MapMouseEvent):void
            {
                trace("mapClickHandler()");
                
                var queryMapClick:Query = new Query();
                //queryMapClick.geometry = event.mapPoint;
                queryMapClick.where = "OBJECTID = 3";
                lnoLayer.selectFeatures(queryMapClick);
                
            }



If anyone could point me in the right direction I owe you many thanks.
Tags (2)
0 Kudos
2 Replies
Drew
by
Frequent Contributor
Matt,
Could it be because your "map point" is just an X,Y and not an envelope?
When using an point as the geometry you have to be very accurate when clicking on the map so the query can find the feature:)
You might want to convert the point to an envelope/extent then expand(..) it a little.

I am not 100% sure this is your problem, but from a quick glance at the code it looks like it.


Drew
0 Kudos
MattMoyles
Occasional Contributor
hey thanks Andrew that worked great, feel like I should have known that was the problem... 😮
0 Kudos