Select to view content in your preferred language

Feature Layer is not adding to map.

1135
7
Jump to solution
02-16-2012 04:05 PM
N_Young
Deactivated User
I am trying to replace the "attribute inspector outside of the map" flex sample with some local data.  The parcels layer I want to add does not appear on the map.  It works fine as a dynamic layer in another map I have. 

Perhaps I am not understanding how to create a feature layer based on a dynamic web service.  This is possible, right?

Here is what I've tried, just the map section of it:

 <esri:Map id="myMap"       mapClick="map_mapClickHandler(event)"      openHandCursorVisible="false"      wrapAround180="true">   <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>   <esri:ArcGISDynamicMapServiceLayer    load="{myMap.extent=useforextentLayer.fullExtent}"    id="useforextentLayer"    url="http://gis.chcity.org/CHwebMaps/rest/services/CityData/CityBoundary_SD/MapServer" />   <esri:FeatureLayer id="fLayer"          definitionExpression="STATE_NAME='North Carolina'"          fault="fLayer_faultHandler(event)"          graphicAdd="fLayer_graphicAddHandler(event)"          mode="snapshot"          outFields="[Address,own_name,own_addr]"          symbol="{countySymbol}"          url="http://gis.chcity.org/CHwebMaps/rest/services/CityData/Parcels_SD/MapServer/0"/>   <esri:GraphicsLayer id="highlightGraphicsLayer"/>  </esri:Map>


I am not sure what the definition expression does.
Also, does outFields require the field name or field alias?

I may just be not understanding how to make a feature layer.  I didn't find this page particularly helpful.  It has samples but does not give any step-by-step direction on how to correctly create a feature layer.

Any help appreciated.  Thanks.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
IvanBespalov
Frequent Contributor
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/FeatureLayer.html#definitionExpress...

... 
The definition expression limits the FeatureLayer to a subset of the available features in the map service layer.   It is similar to the definition query for a layer in ArcMap.
...


servise you are using has no "STATE_NAME" field

definitionExpression="STATE_NAME='North Carolina'" - never returns data
definitionExpression="OBJECTID<100" - returns features where OBJECTID smaller when 100

http://gis.chcity.org/CHwebMaps/rest/services/CityData/Parcels_SD/MapServer/0  Fields: OBJECTID (Type: esriFieldTypeOID, Alias: OBJECTID) Sidwell10 (Type: esriFieldTypeString, Alias: Sidwell10, Length: 10 ) Sidwell14 (Type: esriFieldTypeString, Alias: Sidwell14, Length: 14 ) tax_dist (Type: esriFieldTypeString, Alias: tax_dist, Length: 3 ) Address (Type: esriFieldTypeString, Alias: Address, Length: 25 ) Acreage (Type: esriFieldTypeDouble, Alias: Acreage) Adjusted (Type: esriFieldTypeSmallInteger, Alias: Adjusted, Domain: Coded Values: [0: No], [1: Yes] ) Shape (Type: esriFieldTypeGeometry, Alias: Shape) own_name (Type: esriFieldTypeString, Alias: Owner Name, Length: 30 ) own_name_c (Type: esriFieldTypeString, Alias: Additional Owner Name, Length: 30 ) own_addr (Type: esriFieldTypeString, Alias: Owner Address, Length: 25 ) own_cityst (Type: esriFieldTypeString, Alias: Owner City/State, Length: 22 ) own_zip (Type: esriFieldTypeString, Alias: Owner Zip, Length: 5 ) own_zip_fo (Type: esriFieldTypeString, Alias: Owner Zip4, Length: 4 ) Shape_Area (Type: esriFieldTypeDouble, Alias: Area)


:confused:

P.S. finally your question is not correct - feature layer is added, but it has no features in its graphicProvider, because you did not test def.query before use it

View solution in original post

0 Kudos
7 Replies
IvanBespalov
Frequent Contributor
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/FeatureLayer.html#definitionExpress...

... 
The definition expression limits the FeatureLayer to a subset of the available features in the map service layer.   It is similar to the definition query for a layer in ArcMap.
...


servise you are using has no "STATE_NAME" field

definitionExpression="STATE_NAME='North Carolina'" - never returns data
definitionExpression="OBJECTID<100" - returns features where OBJECTID smaller when 100

http://gis.chcity.org/CHwebMaps/rest/services/CityData/Parcels_SD/MapServer/0  Fields: OBJECTID (Type: esriFieldTypeOID, Alias: OBJECTID) Sidwell10 (Type: esriFieldTypeString, Alias: Sidwell10, Length: 10 ) Sidwell14 (Type: esriFieldTypeString, Alias: Sidwell14, Length: 14 ) tax_dist (Type: esriFieldTypeString, Alias: tax_dist, Length: 3 ) Address (Type: esriFieldTypeString, Alias: Address, Length: 25 ) Acreage (Type: esriFieldTypeDouble, Alias: Acreage) Adjusted (Type: esriFieldTypeSmallInteger, Alias: Adjusted, Domain: Coded Values: [0: No], [1: Yes] ) Shape (Type: esriFieldTypeGeometry, Alias: Shape) own_name (Type: esriFieldTypeString, Alias: Owner Name, Length: 30 ) own_name_c (Type: esriFieldTypeString, Alias: Additional Owner Name, Length: 30 ) own_addr (Type: esriFieldTypeString, Alias: Owner Address, Length: 25 ) own_cityst (Type: esriFieldTypeString, Alias: Owner City/State, Length: 22 ) own_zip (Type: esriFieldTypeString, Alias: Owner Zip, Length: 5 ) own_zip_fo (Type: esriFieldTypeString, Alias: Owner Zip4, Length: 4 ) Shape_Area (Type: esriFieldTypeDouble, Alias: Area)


:confused:

P.S. finally your question is not correct - feature layer is added, but it has no features in its graphicProvider, because you did not test def.query before use it
0 Kudos
by Anonymous User
Not applicable

   url="http://gis.chcity.org/CHwebMaps/rest/services/CityData/Parcels_SD/MapServer/0


Not sure if you noticed this yet or not but you want to use FeatureServer, not MapServer in this context ...
0 Kudos
IvanBespalov
Frequent Contributor
Bob, thx - we noticed (it does not matter in this context).

We talk about FeatureLayer (not FeatureService) and its properties.

Yes you can create FeatureLayer based on MapService - http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=FeatureLayerBasedOnMapServerLayer
0 Kudos
IvanBespalov
Frequent Contributor
<?xml version="1.0" encoding="utf-8"?>
<s:Application 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">
 
 <!-- Flex SDK v.4.5.1 -->
 <!-- ArcGIS API v.2.5 -->
 
 <s:layout>
  <s:VerticalLayout paddingBottom="10"
        paddingTop="10"
        paddingLeft="10"
        paddingRight="10" />
 </s:layout>
 <fx:Script>
  <![CDATA[
   import com.esri.ags.Graphic;
   import com.esri.ags.events.GraphicEvent;
   import com.esri.ags.events.LayerEvent;
   
   import mx.utils.StringUtil;

   protected function onGraphicAdd(event:GraphicEvent):void
   {
    var gr:Graphic = event.graphic;
    var attr:Object = gr.attributes;
    gr.toolTip = StringUtil.substitute("Address: {0}\nOwner Name: {1}", attr.Address, attr.own_name);
    
    gr.addEventListener(MouseEvent.MOUSE_OVER, function():void{
     gr.symbol = overSymbol;
    });
    
    gr.addEventListener(MouseEvent.MOUSE_OUT, function():void{
     gr.symbol = normalSymbol;
    });
   }

  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <esri:SimpleFillSymbol id="normalSymbol" 
         color="0xFF0000"
         alpha="0.8"
         style="cross">   
   <esri:outline>    
    <esri:SimpleLineSymbol color="0xFF0000"
            width="2" />    
   </esri:outline>   
  </esri:SimpleFillSymbol>
  
  <esri:SimpleFillSymbol id="overSymbol" 
          color="0x0000FF"
          alpha="0.8"
          style="cross">   
   <esri:outline>    
    <esri:SimpleLineSymbol color="0x0000FF"
            width="4" />    
   </esri:outline>   
  </esri:SimpleFillSymbol>
  
 </fx:Declarations>
 
 <esri:Map id="map">
  
  <esri:extent>
   
   <esri:Extent xmax="-111.834" 
       xmin="-111.837" 
       ymax="40.6316" 
       ymin="40.6312">
    
    <esri:SpatialReference>
     
     <esri:wkid>4326</esri:wkid>
     
    </esri:SpatialReference>
    
   </esri:Extent>
   
  </esri:extent>
  
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
  
  <esri:FeatureLayer mode="snapshot"
         id="fLayer"
         graphicAdd="onGraphicAdd(event)"
         outFields="[Address,own_name,own_addr]"
         symbol="{normalSymbol}"
         url="http://gis.chcity.org/CHwebMaps/rest/services/CityData/Parcels_SD/MapServer/0" />
  
 </esri:Map>
 
</s:Application>
0 Kudos
N_Young
Deactivated User
Thanks.  You are right about the definitionExpression being wrong because it was made for the counties layer.  However, I had problems even when I removed the definitionExpression completely.  I found out that the mode="snapshot" setting on my feature layer was causing problems.    When I remove that and either fix or remove the definitionExpression, it works.  Thank you!
0 Kudos
N_Young
Deactivated User
Huh.  Actually the way you put it (below) does work even though it has snapshot mode in it:

  <esri:FeatureLayer mode="snapshot"
         id="fLayer"
         graphicAdd="onGraphicAdd(event)"
         outFields="[Address,own_name,own_addr]"
         symbol="{normalSymbol}"
         url="http://gis.chcity.org/CHwebMaps/rest/services/CityData/Parcels_SD/MapServer/0" />



This is what I have, which works for me, UNLESS i add mode="snapshot" to it.

  <esri:FeatureLayer id="fLayer"
         definitionExpression="Acreage>=0"
         fault="fLayer_faultHandler(event)"
         graphicAdd="fLayer_graphicAddHandler(event)"
         outFields="[Address,own_name,own_addr]"
         symbol="{countySymbol}"
         url="http://gis.chcity.org/CHwebMaps/rest/services/CityData/Parcels_SD/MapServer/0"/>


I don't know why that is.  ?
0 Kudos
IvanBespalov
Frequent Contributor
Service has some limits:

Min. Scale: 15000

Max. Scale: 0


May be you need to configure services before use it?

My sample works, because
1 - i know extent where features are
2 - map scale where features visible

API help. http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/FeatureLayer.html#mode

Good luck.
0 Kudos