Select to view content in your preferred language

Sending a new query from FlexViewer.

1229
4
Jump to solution
01-25-2012 05:28 AM
SaugatJoshi
Deactivated User
Hi all,

I have two buttons(button1 and button 2) in my layer list widget. The purpose of the buttons is to send a different query to ArcGIS Server and get a map returned. For this purpose I have

var data:Object = {       newqr:(state[index].toString())    } ViewerContainer.dispatchEvent( new AppEvent("newQuery",data));
and in Mapmanager.mxml init() I have

ViewerContainer.addEventListener("newQuery", chgQuery);


private function chgQuery(event:AppEvent):void    {     var lquery:String = new String();     lquery=(event.data.newqr.toString());     newSDEquery= "STATE=" +  lquery;             }




Once I receive this from layerlist widget in Mapmanager.mxml I try to plug it in function
addLayerToMap(layerObject:Object)
under case dynamic as
dynLayer.layerDefinitions= newSDEquery;


However I never get the map with new query results. I just need the map with query results. However I still have the same old map before I send a query. It would be great if someone could enlighten me to what needs to be done. I am using Flex Viewer 2.3.1. Thank you.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Sagaut,

   The dynamic layer is already loaded in the map correct? And all you are trying to do is apply a layer definition to layer 3 of the dynamic map service right?

As far as the map.getLayer you need to use the label of the dynamic map service as it is specified in the main config.xml

            private function chgQuery(event:AppEvent):void             {                 var lquery:String = new String();                 lquery = (event.data.newqr.toString());                 var layerDefArr:Array = [];                 layerDefArr[2] = "STATE=" +  lquery; //the number 2 is for the 3rd layr in the dynamic map service                 var dLayer:ArcGISDynamicMapServiceLayer = map.getLayer("Police Stations") as ArcGISDynamicMapServiceLayer                 dLayer.layerDefinitions = layerDefArr;             }

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Saugat,

   The issue with what you are attempting is that the addLayerToMap in the map manager is only called when the map is being loaded initially. What you probably need to do is something like this:

            private function chgQuery(event:AppEvent):void
            {
                var lquery:String = new String();
                lquery = (event.data.newqr.toString());
                var layerDefArr:Array = [];
                layerDefArr[2] = "STATE=" +  lquery; //the number 2 is for the 3rd layr in the dynamic map service
                var dLayer:ArcGISDynamicMapServiceLayer = map.getLayer("yourlayerID") as ArcGISDynamicMapServiceLayer
                dLayer.layerDefinitions = layerDefArr;
            }


Don't forget to click the top arrow (promote) and to click the Mark as answer check as shown below:
0 Kudos
SaugatJoshi
Deactivated User
Robert,

In
 var dLayer:ArcGISDynamicMapServiceLayer = map.getLayer("yourlayerID") as ArcGISDynamicMapServiceLayer


Does getLayer("yourlayerID") need to have ID of all the layers? For eg: If my dynamic map service has 5 layers and I want all the layers but the query applied only to layer 3.  I still want the other layers only layer 3 with a different query. Is this correct below?

  private function chgQuery(event:AppEvent):void
            {
                var lquery:String = new String();
                lquery = (event.data.newqr.toString());
                var layerDefArr:Array = [];
                layerDefArr[2] = "STATE=" +  lquery; //the number 2 is for the 3rd layr in the dynamic map service
                var dLayer:ArcGISDynamicMapServiceLayer = map.getLayer("0,1,2,3,4") as ArcGISDynamicMapServiceLayer
                dLayer.layerDefinitions = layerDefArr;
            }


Do we also need
map.addLayer(dLayer);
in the end?

Thank you.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Sagaut,

   The dynamic layer is already loaded in the map correct? And all you are trying to do is apply a layer definition to layer 3 of the dynamic map service right?

As far as the map.getLayer you need to use the label of the dynamic map service as it is specified in the main config.xml

            private function chgQuery(event:AppEvent):void             {                 var lquery:String = new String();                 lquery = (event.data.newqr.toString());                 var layerDefArr:Array = [];                 layerDefArr[2] = "STATE=" +  lquery; //the number 2 is for the 3rd layr in the dynamic map service                 var dLayer:ArcGISDynamicMapServiceLayer = map.getLayer("Police Stations") as ArcGISDynamicMapServiceLayer                 dLayer.layerDefinitions = layerDefArr;             }
0 Kudos
SaugatJoshi
Deactivated User
Robert Thanks, it works great.
0 Kudos