Select to view content in your preferred language

User-defined Layer Definition

2625
7
Jump to solution
09-23-2013 09:54 AM
JonBarlett
Deactivated User
I am trying to create an application where a user can define the layer definition for a map service.  I can it get it work if I add the layer in the action script, but I would really like to apply the layer definition to an existing map layer.  Here is the code that works (adds a layer and applies the query):

private function PerformQuery():void  {                     var dLayer:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://apdpdgismap01:6080/arcgis/rest/services/GISDPD01/CrimePart1_28Days/MapServer");       map.addLayer(dLayer);       dLayer.visible = true;             //var dLayer:ArcGISDynamicMapServiceLayer = map.getLayer("CrimePart1_28Days") as ArcGISDynamicMapServiceLayer;       dLayer.name = "CrimePart1_28Days"          var layerDefs:Array = new Array();       var layerStr:String = new String();       layerStr = "DIVISION = '" + Offense.text + "'"       layerDefs[0] = layerStr;       dLayer.layerDefinitions = layerDefs;       dLayer.refresh();     }       ]]>     </fx:Script>     <viewer:WidgetTemplate id="DPD_Crime_Data"                            width="300" height="300">         <viewer:layout>             <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>         </viewer:layout>          <s:Label id="lbl"                  width="100%"                  fontSize="18"                  fontStyle="italic"                  fontWeight="bold"/>   <s:TextInput id="Offense"       width="100%" />     <s:Button label="Query Crime" click="PerformQuery();"/>     </viewer:WidgetTemplate> </viewer:BaseWidget>


I can't get the layer definition to work using an existing layer.  Here is the code that doesn't work:

   private function PerformQuery():void  {                     //var dLayer:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://apdpdgismap01:6080/arcgis/rest/services/GISDPD01/CrimePart1_28Days/MapServer");       //map.addLayer(dLayer);       //dLayer.visible = true;             var dLayer:ArcGISDynamicMapServiceLayer = map.getLayer("CrimePart1_28Days") as ArcGISDynamicMapServiceLayer;       dLayer.name = "CrimePart1_28Days"          var layerDefs:Array = new Array();       var layerStr:String = new String();       layerStr = "DIVISION = '" + Offense.text + "'"       layerDefs[0] = layerStr;       dLayer.layerDefinitions = layerDefs;       dLayer.refresh();     }       ]]>     </fx:Script>     <viewer:WidgetTemplate id="DPD_Crime_Data"                            width="300" height="300">         <viewer:layout>             <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>         </viewer:layout>          <s:Label id="lbl"                  width="100%"                  fontSize="18"                  fontStyle="italic"                  fontWeight="bold"/>   <s:TextInput id="Offense"       width="100%" />     <s:Button label="Query Crime" click="PerformQuery();"/>     </viewer:WidgetTemplate> </viewer:BaseWidget>   This is how the layer is added in the config file:  <layer label="CrimePart1_28Days" id="CrimePart1_28Days" type="feature" visible="true" alpha="1.0"                    url="http://apdpdgismap01:6080/arcgis/rest/services/GISDPD01/CrimePart1_28Days/MapServer/0"/>          </operationallayers>


The layer does appear on the map, but nothing happens when the layer definition is applied.

I am a FLEX newbie, so any insight would be appreciated.

Jon Barlett
GIS Analyst
Dallas PD
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Jon,

   This is how I would do the code (BTW, I do apply layer definitions dynamically to layers already in the Viewer without issue):

<?xml version="1.0" encoding="utf-8"?> <viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"                     xmlns:s="library://ns.adobe.com/flex/spark"                     xmlns:mx="library://ns.adobe.com/flex/mx"                    xmlns:viewer="com.esri.viewer.*"                    layout="absolute" creationComplete="init()">     <fx:Script>         <![CDATA[             import com.esri.ags.layers.FeatureLayer;                          private var FeatLay:FeatureLayer;                          private function init():void             {                 FeatLay = map.getLayer("CrimePart1_28Days") as FeatureLayer;             }                          private function PerformQuery():void             {                 FeatLay.definitionExpression = "";                 FeatLay.definitionExpression = "DIVISION = '" + Offense.text + "'";                 FeatLay.refresh();             }         ]]>     </fx:Script>     <viewer:WidgetTemplate id="DPD_Crime_Data"                            width="300" height="300">         <viewer:layout>             <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>         </viewer:layout>                  <s:Label id="lbl"                  width="100%"                  fontSize="18"                  fontStyle="italic"                  fontWeight="bold"/>         <s:TextInput id="Offense"                      width="100%" />                  <s:Button label="Query Crime" click="PerformQuery();"/>     </viewer:WidgetTemplate> </viewer:BaseWidget>

View solution in original post

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
Jon,

   This is how I would do the code (BTW, I do apply layer definitions dynamically to layers already in the Viewer without issue):

<?xml version="1.0" encoding="utf-8"?> <viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"                     xmlns:s="library://ns.adobe.com/flex/spark"                     xmlns:mx="library://ns.adobe.com/flex/mx"                    xmlns:viewer="com.esri.viewer.*"                    layout="absolute" creationComplete="init()">     <fx:Script>         <![CDATA[             import com.esri.ags.layers.FeatureLayer;                          private var FeatLay:FeatureLayer;                          private function init():void             {                 FeatLay = map.getLayer("CrimePart1_28Days") as FeatureLayer;             }                          private function PerformQuery():void             {                 FeatLay.definitionExpression = "";                 FeatLay.definitionExpression = "DIVISION = '" + Offense.text + "'";                 FeatLay.refresh();             }         ]]>     </fx:Script>     <viewer:WidgetTemplate id="DPD_Crime_Data"                            width="300" height="300">         <viewer:layout>             <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>         </viewer:layout>                  <s:Label id="lbl"                  width="100%"                  fontSize="18"                  fontStyle="italic"                  fontWeight="bold"/>         <s:TextInput id="Offense"                      width="100%" />                  <s:Button label="Query Crime" click="PerformQuery();"/>     </viewer:WidgetTemplate> </viewer:BaseWidget>
0 Kudos
JonBarlett
Deactivated User
Robert,

That code code worked like a charm.  Thank you so very much!

Jon Barlett
GIS Analyst
Dalals PD
0 Kudos
MichaelVolz
Esteemed Contributor
Robert:

How do you currently apply layer definitions dynamically to layers in a FlexViewer app?  Is this a configurable item in the xml file?  Or does the layer definition need to be built into the mxd that is the source of the mapservice?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Michael,

   Through a custom built widget, just like Jon is doing.
0 Kudos
MichaelVolz
Esteemed Contributor
Robert:

Is this functionality available with any of the custom widgets you have distributed?  If so, which ones and is there documentation on how to correctly set this up in the xml file?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Michael,

   I do not have a public widget that supports this. You can add a static layer definition to the viewers layer in the main config though.
0 Kudos
MichaelVolz
Esteemed Contributor
Robert:

Would this functionality ever be available in a public widget?  Or is it too business specific to make it a one size fits all configurable variable?
0 Kudos