Help with Extent

1041
3
12-11-2013 02:09 PM
AngusHenderson
New Contributor
I downloaded the ArcGIS Runtime SDK for WPF, did the 1st step of creating a new c# project, everything OK, I see a map

Then I went to the 'Creating a map' tutorial and tried setting an Extent, in xaml in c# two or three different ways. The ESRI.Map shows the correct extents in debug, but the map always zooms to 0,0 latitude,longitude.

Help a noobie out please?

Angus Henderson
0 Kudos
3 Replies
DavidLednik
Occasional Contributor II
Angus,

Make sure the SpatialReference of your extent is the same as from your base map (or 1st Layer that is added to the map).

If you run the sample app that is delivered with WPF SDK, under Geocoding section there is a sample called
"Reverse Geocoding Online". If you look at the C# code from the sample, you will notice that Envelope is reprojected to Basemaps SpatialReference. In this case from geographic to webmercator.

private static ESRI.ArcGIS.Client.Projection.WebMercator _mercator =
                                new ESRI.ArcGIS.Client.Projection.WebMercator();
        GraphicsLayer _locationGraphicsLayer;

        public LocationToAddress()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                    new ESRI.ArcGIS.Client.Geometry.Envelope(
            _mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.387, 33.97)) as MapPoint,
            _mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.355, 33.988)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(3857);

            MyMap.Extent = initialExtent;

            _locationGraphicsLayer = MyMap.Layers["LocationGraphicsLayer"] as GraphicsLayer;
        }


Regards,
David
0 Kudos
AngusHenderson
New Contributor
Thank you so much; that worked for me. I am also trying to understand the xaml version. I have seen snippets that look like...

          
            <esri:Map.Extent >
                <esri:Envelope XMin="-117.387" YMin="33.97" XMax="-117.355" YMax="33.988" >
                    <esri:Envelope.SpatialReference>
                        <esri:SpatialReference WKID="4629"/>
                    </esri:Envelope.SpatialReference>
                </esri:Envelope>
            </esri:Map.Extent>


But I read that the map uses the spatialReference of the 1st layer & the layer doesnt have a set method for spatialReference.
Can I tell my ArcGISTiledMapServiceLayer to use a geographic spatialReference?
0 Kudos
DavidLednik
Occasional Contributor II
Tiled layers have a fixed spatialreference. It's defined in the mxd document when you author your data and prepare it fro creating tiled cache. You can have different spatial references for dynamic services but bare in mind that the data is reprojected on the fly and that can have a huge performance impact to your application.

All data that is published on a server have a spatial reference defined. I'm pretty sure you can't publish the data if SR it's missing.
GraphicsLayer is an exception. You create them via code or XAML and you define SR for each graphics that you add to the layer.
If the geometry has different SR as the map control it's going to be reprojected.

The xaml sample code shows how you can define a spatial reference for the envelope. I showed you the same thing in C# code. But if you wan't to do it in XAML this is how you do it. Map control then automatically reprojects the envelope to the spatial reference it uses and so it zooms to your expected location.

Any other question let me know.

Regards,
David
0 Kudos