Select to view content in your preferred language

bug in/ or wrong usage of Navigation control using FullExtent button

1675
11
03-21-2011 12:18 PM
BKuiper
Frequent Contributor
Hi,

I'm doing the following

I've cleared the Map layers collection, set the map extent to the extent and spatialreference of my second layer. Then add both my layers. The first layer originally has a different spatialreference but now is reprojected by the Map control to match the spatialreference of my second layer.

Now, my program will crash if I click "FullExtent" in the Navigation control.

Looking at the code the following happens:

FullExtent Button Click handler:
  private void ZoomFullExtent_Click(object sender, RoutedEventArgs e)
  {
   if (Map != null)
    Map.ZoomTo(Map.Layers.GetFullExtent());
  }


this calls Map.Layers.GetFullExtent() where the "error" occurs:
public Envelope GetFullExtent()
{
    if (base.Count == 0)
    {
        return null;
    }
    Envelope extent = null;
    SpatialReference spatialReference = null;
    foreach (Layer layer in this)
    {
        if ((layer != null) && (layer.SpatialReference != null))
        {
            spatialReference = layer.SpatialReference;
            break;
        }
    }
    foreach (Layer layer2 in this)
    {
        Envelope fullExtent = layer2.FullExtent;
        if (((fullExtent != null) && SpatialReference.AreEqual(fullExtent.SpatialReference, spatialReference, true)) && (fullExtent != null))
        {
            extent = fullExtent.Union(extent);
        }
    }
    return extent;
}


The following piece of code sets the extent to which the map should zoom to but uses the original spatialreference of the first layer:
        if ((layer != null) && (layer.SpatialReference != null))
        {
            spatialReference = layer.SpatialReference;
            break;
        }


Shouldn't this code get the spatialreference from the Map control itself (when it contains layers)
spatialReference = Map.FullExtent.SpatialReference


?

I'm I correct or just doing stuff the wrong way?

My idea was that the Map control would do the reprojection of the basemap for me, so i don't have to create a basemap for each different spatialreference.


EDIT:

I forgot to mention that the Map.ZoomTo() operation will fail because the SpatialReference doesn't match the spatial reference currently used by the map, thus crashing the app.
0 Kudos
11 Replies
BKuiper
Frequent Contributor
where is this code that you're editing? all I do to use the navigation control is

<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Grid.Row="2" VerticalAlignment="Bottom">
                        <esri2:Navigation x:Name="MyNavigation" Margin="5"></esri2:Navigation>
                    </StackPanel>

and I assign the map from the codebehind.


See the attachment. It has a default Esri Map Application. The Navigation control uses a (WPF) Style. The style is specified in the NavigationStyle.xaml file.

I'm just using WPF Styling to change the look and feel of the Navigation control.
0 Kudos
SangamLama
Emerging Contributor
Handy workaround. I couldn't get that zoom slider to appear, but the rest was pretty useful.

Appreciate your help!

See the attachment. It has a default Esri Map Application. The Navigation control uses a (WPF) Style. The style is specified in the NavigationStyle.xaml file.

I'm just using WPF Styling to change the look and feel of the Navigation control.
0 Kudos