Select to view content in your preferred language

Iimprove this query

898
2
08-25-2010 07:24 AM
CarlosRiano
Emerging Contributor
Hey friends,

I am working in flex 1.3 doing a web map to obtain a tooltip from a polygon when I roll my Mouse over it. However, the query that i already have is taking a lot of time, since the service has many polygons. There is a way to make a query just for the polygon doing a MouseOver, instead of the current query for all the polygons' layer?

I appreciate your help

This is my Code


<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:esri="http://www.esri.com/2008/ags" 
    pageTitle="Nationality Representation for UNV" creationComplete="doQuery()" layout="horizontal" >
 
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.AsyncResponder;
            import mx.events.ListEvent;
            import mx.controls.Alert;
            import com.esri.ags.Graphic;
            import com.esri.ags.tasks.FeatureSet;
 
            private function doQuery() : void
            {
                queryTask.execute(query, new AsyncResponder(onResult, onFault));
                function onResult(featureSet : FeatureSet, token : Object = null) : void
                {                                  
                    for each(var graphic : Graphic in featureSet.features)
                    {
                        graphic.toolTip = graphic.attributes.Country + "\n" + graphic.attributes.Continent;
                        myGraphicsLayer.add(graphic);                
                    }                                       
                }
                function onFault(info : Object, token : Object = null) : void
                {
                    Alert.show(info.toString());
                }
            }
        ]]>
    </mx:Script>
 
    <esri:QueryTask id="queryTask"
        url="http://atlas/ArcGIS/rest/services/unv_by_country/MapServer/0" />
    <esri:Query id="query" where="1=1" returnGeometry="true" outSpatialReference="{map.spatialReference}" 
        outFields="['Country','Continent','number']"/>
       <esri:Map id="map" panStart="myGraphicsLayer.mouseChildren = false" panEnd="myGraphicsLayer.mouseChildren = true">
            <esri:ArcGISTiledMapServiceLayer
                url="http://atlas/ArcGIS/rest/services/unv_by_country/MapServer"/>
            <esri:GraphicsLayer id="myGraphicsLayer" />
        </esri:Map> 

</mx:Application>
Tags (2)
0 Kudos
2 Replies
AlexJones
Emerging Contributor
Assuming that your users are zooming in on a certain area first you could use the extent of the map to limit the query. Robert helped me with something like this in the past and this is the basic code from that. Maybe you can use this to outline the process. This code used a config file, but you can just hard code to get it started.

private var scaleThresholdLevel:Number;

private function init():void{
         this.map.addEventListener(ExtentEvent.EXTENT_CHANGE, extentChange);
}

private function extentChange(event:ExtentEvent):void
{
if( map.scale <= scaleThresholdLevel )
    {
     //Get all the polygons in the current extent
     var queryTask:QueryTask = new QueryTask( queryLayerUrl );
     var query:Query = new Query();
     query.returnGeometry = true;
     query.geometry = map.extent;
     query.outSpatialReference = map.spatialReference;
     query.outFields = queryLayerFields;
     queryTask.execute(query, new AsyncResponder(queryResultHandler, queryFaultHandler));
    }else{
     graphicsLayer.visible = false;
    }                                                                              
   }
0 Kudos
BjornSvensson
Esri Regular Contributor
If you upgrade to 2.x of the API, you could take advantage of the different modes of the FeatureLayer to either get all features (too slow in your case) or to only get the ones that are in the current extent ("on demand").

If using 1.3, the following sample might be useful since it's doing a basic version of the "on demand" functionality:
http://resources.esri.com/help/9.3/arcgisserver/apis/flex/samples/index.html?sample=ShowPointsWithin...
0 Kudos