Odd FeatureLayer Implementation Behavior

437
6
07-08-2010 06:11 AM
DonnieHolmes
New Contributor III
I have a need to implement the FeatureLayer class so that i can add my own DependencyProperties, events, etc. I've finally been able to get this to work, but i've noticed some odd behavior. If you:

   1. Implement the FeatureLayer class as "MyFeatureLayer" (do nothing else in the class)
   2. Add your "MyFeatureLayer" class to the map as you would a regular FeatureLayer (make all the required settings so that data should load)
   3. Notice that when you load the app the FeatureLayer never completely loads


Somehow i stumbled upon the workaround that if you set the map extent explicitly on the map itself rather than letting it pick up from the first layer that loads, everything seems to work fine.

So, am i try to do something that's not really supported, or is this a bug? I haven't upgraded to the 2.0 RC as we haven't yet upgraded our ArcGIS Server to the 10.0 release version. (currently using beta versions of both)
0 Kudos
6 Replies
dotMorten_esri
Esri Notable Contributor
You can still use v2.0 with an ArcGIS 9.3.1 server.

If you want to create your own featurelayer, you should
1) Inherit from GraphicsLayer
2) Internally add a querytask that populates the Graphics collection with whatever comes back from the QueryTask.

In other words, all a featurelayer is (at least at v1.x) is just a graphicslayer with a built-in querytask.
0 Kudos
DonnieHolmes
New Contributor III
Thanks for the reply Morten. Sorry, i should have been more clear about the versions we are using. We currently are running ArcGIS Server 10 (just not the final release) and we are using the 2.0 WPF/Silverlight SDK (beta).

I would like to take advantage of the editing goodness and ondemand feature loading that comes with the 2.0 FeatureLayer - which is why i chose that route rather than GraphicsLayer. Are you saying that we shouldn't attempt to inherit from FeatureLayer at all?
0 Kudos
dotMorten_esri
Esri Notable Contributor
Sorry I misunderstood. Inheriting from FeatureLayer should be fine. But you could be overriding some methods incorrectly. Are you overriding anything? (if you are make sure you call the base method as well).
0 Kudos
DonnieHolmes
New Contributor III
I finally figured out what is wrong, and it doesn't appear related to implementing the FeatureLayer class. It seems that if there is only a FeatureLayer in the map, then it won't pay any attention to it unless you explicitly set the map extent. Using data from the ESRI sample services:

This loads as expected:

<esri:Map x:Name="MyMap">
            <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                    Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
            <esri:FeatureLayer ID="MyFeatureLayer"
                    Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0"/>
</esri:Map>


Nothing loads for this scenario:

<esri:Map x:Name="MyMap">            
            <esri:FeatureLayer ID="MyFeatureLayer"
                    Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0"/>
</esri:Map>


However, this does work (which does nothing more than set the map to the extent and spatial ref of the feature layer):

<esri:Map x:Name="MyMap">
            <esri:Map.Extent>
                <esri:Envelope XMin="-158.064605712891" YMin="19.6961498260498" XMax="-67.986768734036" YMax="64.8691042579708" >
                    <esri:Envelope.SpatialReference>
                        <esri:SpatialReference WKID="4326"/>
                    </esri:Envelope.SpatialReference>
                </esri:Envelope>
            </esri:Map.Extent>
            <esri:FeatureLayer ID="MyFeatureLayer"
                    Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0"/>
        </esri:Map>


This seems like a bug to me.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You are right the map extent is not initialized from the feature layer.

You can initialize the map extent in the featurelayer initialized event:

 
private void FeatureLayer_Initialized(object sender, System.EventArgs e)
{
FeatureLayer featureLayer = sender as FeatureLayer;
MyMap.Extent = featureLayer.LayerInfo.Extent;
}
0 Kudos
DonnieHolmes
New Contributor III
Thanks Dominique. Is this behavior by design? I'm just curious as to why the map would ignore feature layers for its extent and spatial reference info.
0 Kudos