Select to view content in your preferred language

definition expression by search/query

2338
7
08-13-2012 01:32 PM
RhettZufelt
MVP Notable Contributor
Hi All,

I would like to have the ability to search my service layer for field1="some item", and then have it only display the items that match the query on the map.

So, either turn off any features that do not match the current query, or turn on the features that do, either will work.

Does anyone know if this capability is out there in an existing widget?  If not, has anyone attempted this and have any suggestions/snippets?

Thanks again,

R_

Of course, ideal solution would be to somehow integrate this with the eSearch widget (or the existing eSearch selection) so that only the currently selected items are drawn.
Tags (2)
0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   The eSearch already use a layers definition expression from the main config.xml of the viewer...
0 Kudos
RhettZufelt
MVP Notable Contributor
It is my understanding that the definition expression in the config.xml dictates which features of the service are drawn on map load.

I am looking for a way to modify/change the definition expression to represent the currently selected features.

In other words, I have a ton of polygons in an area, many of which overlap.  I have a status field with a value of "complete",  "incomplete", or "in process".

I would like the user to be able to pick the "complete" (or whichever they are interested in) from the dropdown (like a userlist eSearch query) and have it ONLY display the polygons with status='complete' and no other polygons drawn.
The eSearch widget is nice that you can highlight the selected features, but this it too busy and too much overlap.  Need to figure out how to only display the polygons where status="your query".

Thanks again,

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   For that then you will have to create a custom widget for your needs. The widget could very simply have a dropdown and that drop down would set/modify a layer in the map by applying a definition query.
0 Kudos
RhettZufelt
MVP Notable Contributor
Was afraid you were going to say that.

You don't happen to have an example you could point me at as how to set/change layerdefinition for layers currently loaded in the map do you?

Guess I'ts time for me to "expand" my flex capabilities 😮

R_

Eventually, if I figure this out, would like to have it display only the features that meet my search AND populate the DG with the selected attributes.
0 Kudos
PaulLang
Deactivated User
The LayerDefinition Widget will get you started!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Paul,

   Have I missed a widget that is available???
LayerDefinition Widget
Do you have a link?
0 Kudos
PaulLang
Deactivated User
This is what I did, using code from samples posted and some editing.  Built in FlexViewer 2.2

When users select one of these layers within the TOC,
Bldg Quality Code, Depreciation, or Structure Code.  Opens the Unique Neighborhood widget, enters number, clicks submit.  Layer select is displayed for that Neighborhood only.

Within Config.xml

Use these three layers within the widget

<layer label="Bldg Quality Code" type="feature" visible="false" alpha="0.4" mode="onDemand"
url="http://gcgis/ArcGIS/rest/services/Monthly/NeighborhoodGroup/MapServer/8" />
        
<layer label="Depreciation" type="feature" visible="false" alpha="0.4" mode="onDemand"
         url="http://gcgis/ArcGIS/rest/services/Monthly/NeighborhoodGroup/MapServer/4" />
        
<layer label="Structure Code" type="feature" visible="false" alpha="0.4" mode="onDemand"
         url="http://gcgis/ArcGIS/rest/services/Monthly/NeighborhoodGroup/MapServer/6" />
        
<layer label="Parcel Info" type="feature" visible="false" alpha="0.4" mode="onDemand"
         url="http://gcgis/ArcGIS/rest/services/Daily/ParcelA/MapServer/2" />


<widget label="Unique Neighborhood"  x="550" y="260"
  icon="assets/images/i_lego.png"
               config="widgets/Samples/LayerDefinition/LayerDefinition.xml"
               url="widgets/Samples/LayerDefinition/LayerDefinition.swf"/>

Widget name LayerDefinition
Two files:  LayerDefinition.mxml & LayerDefinition.xml
LayerDefinition.mxml

<?xml version="1.0" encoding="utf-8"?>
<!--
     ////////////////////////////////////////////////////////////////////////////////
     //
  // LayerDefinition Widget for FlexViewer 2.2
     //
     ////////////////////////////////////////////////////////////////////////////////
-->
<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:esri="http://www.esri.com/2008/ags"
                   xmlns:viewer="com.esri.viewer.*"
                   widgetConfigLoaded="init()">
<fx:Script>
  <![CDATA[
   import com.esri.ags.layers.FeatureLayer;
   import com.esri.ags.layers.Layer;
   import com.esri.viewer.AppEvent;
   import com.esri.viewer.ViewerContainer;
  
   import flash.utils.flash_proxy;
  
   import mx.controls.Alert;
  
   [Bindable]
   private var oplList:Array;
  
   //this function called when the widget's configuration is loaded
   private function init():void
   {
    if (configXML) // checking for valid content in the configuration file
    {
     fieldlbl.text = configXML.field = "NBHDNUM";
    }
   }
  
   private function submitButton_clickHandler(event:Event):void
   { 
    ViewerContainer.dispatchEvent(new AppEvent(AppEvent.DATA_OPT_LAYERS, null, getOplayers));
   }
  
   private function getOplayers(event:AppEvent):void
   {
    oplList = event.data as Array;
   
    if (oplList && oplList.length > 0)
    {
     for (var j:int = 0; j < oplList.length; j++)
     {
      var opLayerName:String = oplList.label;

      if (opLayerName == "Bldg Quality Code" || opLayerName == "Depreciation" || opLayerName == "Structure Code")
      {
       //Alert.show(opLayerName);
       oplList.layer.definitionExpression = configXML.field + "='" + definitionText.text + "'";
       //Alert.show(oplList.layer.definitionExpression);
      }
     }
    }
   }
  
  ]]>
</fx:Script>
<viewer:WidgetTemplate id="layerDefinition"
         width="235" height="150">
  <viewer:layout>
   <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>
  </viewer:layout>
  <s:Label id="fieldlbl"/>
  <s:TextInput id="definitionText"/>
  <s:Button label="Submit"
      click="submitButton_clickHandler(event)"/>

    </viewer:WidgetTemplate>
</viewer:BaseWidget>



LayerDefinition.xml

<configuration>
<layer>Bldg Quality Code</layer>
     <field>BLDQUAL_CODE</field>
        <field>DEPR</field>
        <field>STRCODE</field>
            <field>AKPAR</field>
    <layer>Depreciation</layer>
     <field>BLDQUAL_CODE</field>
        <field>DEPR</field>
        <field>STRCODE</field>
            <field>AKPAR</field>
    <layer>Structure Code</layer>
     <field>BLDQUAL_CODE</field>
        <field>DEPR</field>
        <field>STRCODE</field>
        <field>AKPAR</field>
</configuration>
0 Kudos