Select to view content in your preferred language

v2.0 - Setting extent with projection on map with bound layers throwing exception.

406
1
05-03-2010 09:30 AM
BrandonCopeland
Emerging Contributor
Just updated updated to v2.0 and encountering exception when trying to set the spatial reference and extent on map with layers set via data binding. Any suggestions?

Exception...

{System.Windows.Markup.XamlParseException: Set property 'ESRI.ArcGIS.Client.Map.Extent' threw an exception. [Line: 89 Position: 85] ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at ESRI.ArcGIS.Client.Map.getSpatialReferenceFromLayers()
   at ESRI.ArcGIS.Client.Map.get_SpatialReference()
   at ESRI.ArcGIS.Client.Map.set_Extent(Envelope value)
   --- End of inner exception stack trace ---
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at LJA.Client.RCP.QBMapFull.MapModule.MapView.InitializeComponent()
   at LJA.Client.RCP.QBMapFull.MapModule.MapView..ctor()}

<esri:Envelope x:Key="InitialExtent" XMax="-10539988" XMin="-10681703" YMax="3541573" YMin="3405056">
    <esri:Envelope.SpatialReference>
        <esri:SpatialReference WKID="102113"/>
    </esri:Envelope.SpatialReference>
</esri:Envelope>

<esri:Map x:Name="TheMap" Layers="{Binding Layers, Mode=OneWay}" Extent="{StaticResource InitialExtent}">
</esri:Map>



On view model...

public LayerCollection Layers
{
    get { return _layers ?? (_layers = new LayerCollection()); }
    set
    {
        if (value == _layers) return;

        _layers = value;
        OnPropertyChanged("Layers");
    }
}
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
You are right, it looks like there is an issue in this case.

As a temporarly workaround, you can initialize the extent by code when the map is loaded :

       <esri:Map x:Name="MyMap" Layers="{Binding Layers, Mode=OneWay}" Loaded="MyMap_Loaded" />


 void MyMap_Loaded(object sender, System.Windows.RoutedEventArgs e)
 {
  MyMap.Extent = (ESRI.ArcGIS.Client.Geometry.Envelope)LayoutRoot.Resources["InitialExtent"];
 }


/Dominique
0 Kudos