Select to view content in your preferred language

featuredatagrid and binding with graphicslayers & featurelayers

1830
17
08-11-2010 09:19 AM
MichaelBlom
Deactivated User
Hi there,

I'm creating a featuredatagrid that I want to link with my map (select grid, map graphic selected and vice versa a la this example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid)

but I need my featuredatagrid to reference a GraphicsLayer, not a FeatureLayer

...I create my GraphicsLayer in the xaml:
<esri:GraphicsLayer ID="StormRegions"/>

...do the binding in the xaml:
<esri:FeatureDataGrid Grid.Row="2" x:Name="stormsDataGrid" Visibility="Visible"
    Map="{Binding ElementName=RiskMap}"
                GraphicsLayer="{Binding ElementName=RiskMap, Path=Layers.[StormRegions]}"

...and then reference in my code behind:
stormPolys = RiskMap.Layers["StormRegions"] as GraphicsLayer;

...and then populate the GraphicsLayer:
stormPolys.Graphics.Insert(0, feature);

The problem is, in binding a GraphicsLayer, I don't seem to get the same kind of map-datagrid-selection-interaction that binding a FeatureLayer to a FeatureDataGrid seems to acheive.

Has anyone managed to achieve this someone?

Thanks in Advance,
Mike
0 Kudos
17 Replies
AliMirzabeigi
Emerging Contributor
Have you verified whether graphic collection in your feature set have their geometry set? If that's the case then you have issues in your service. I would also suggest to check whether there is an extent associated with each graphic returned by your service as they may have NULL extents (another possible issue).
0 Kudos
MichaelBlom
Deactivated User
Browsing to the layer in my service, the SHAPE field exists.

Debugging features from the service in .net, geometery is defined (web mercator), extent is defined... see image attached.

Does anything look suspect in here to you?
0 Kudos
AliMirzabeigi
Emerging Contributor
It could also be the case that the spatial reference of your map doesn't match the spatial reference of your GraphicsLayer. You can explicitly set the spatial reference of your map control by defining an extent with an envelope in which its spatial reference is explicitly defined (if you're doing this in the code-behind make sure it's done before any of your layers getting initialized).
0 Kudos
MichaelBlom
Deactivated User
Hi Ali,

You've pointed me in the right direction.

My problem was that the base layer which I was using was in WGS84 projection (ESRI_StreetMap_World_2D,4326) and my service was in web mercator (102113). 

When I switched my base map to Worrld_Street_Map (Web Mercator Auxilary - 10211), the graphics rendered.

It's a bit odd that my dynamicMapServiceLayer will render over the WGS84 Map, but create a graphicsLayer from this dynamicService and the graphics won't renender.

Anyhow, your transparent symbology xaml code works a treat!

Thanks again.
Mike
0 Kudos
AliMirzabeigi
Emerging Contributor
Hello Mike,

I'm glad that you figured out the problem! Just for your reference I'm adding a quote from ESRI API reference in regards to this issue:


Spatial Reference: The Map's spatial reference is determined by the               first layer in the map that has this property set. However, it can be overridden              by explicitly setting the Extent property with an envelope              that has a SpatialReference defined. This has to be done              before any layers will be initalized by the map. Once the spatial               reference of a map has been set and the layers has loaded, the spatial               reference can no longer be changed. If you need to change spatial reference               on the fly, you can instead create a new map instance, move the layers               to this map, and replace the previous map instance.              Also note that tiled layers does not support reprojection, and will              not be displayed if the Map's SpatialReference does not              match the spatial reference of the tiled layer.
0 Kudos
MichaelBlom
Deactivated User
Thanks Ali,

what does this look like in code: "envelope that has a SpatialReference defined"?

because I thought envelope just allows you to define a north,east, south, west but not a spatial reference.

Thanks,
Mike
0 Kudos
AliMirzabeigi
Emerging Contributor
Here is a sample:

<esri:Map x:Name="MyMap">
            <esri:Map.Extent>
                <esri:Envelope XMin="661140" YMin="-1420246" XMax="3015668" YMax="1594451" >
                    <esri:Envelope.SpatialReference>
                        <esri:SpatialReference WKID="26777"/>
                    </esri:Envelope.SpatialReference>
                </esri:Envelope>
            </esri:Map.Extent>
            <!-- Layer definitions here -->
</esri:Map>
0 Kudos
stefanschlaefli
Regular Contributor
I use a Classbreak renderer on my featurelayer. The featurelayer is bound to the featuredatagrid.  More or less like in example http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid  When I do it like this, I then only see the graphicslayer (all features with the same symbol, except the selected one) but not anymore the featurelayer with it's classbreakrenderer. I also tried with Ali's example (transparent symbology with blue border of the selected object), but then also, I only see the selected graphics of the graphic layer, but not the featurelayer class breaks. How would you do that to combine a classbreakrenderer and a featuredatagrid? Would you add the same featurelayer twice and bind the featuredatagrid to one of them? Or would I have to add the controltemplate by code when i generate the class breaks? Thanks for any suggestions.
0 Kudos