Map Extent and GraphicLayers

693
5
11-06-2013 11:24 AM
Labels (1)
BKuiper
Occasional Contributor III
I'm struggling with something that should be basic i guess. I'm trying to add GraphicLayers to my map. GraphicLayers don't have a SpatialReference, so i'm trying to set the Map SpatialReference based on the Geometry items within the GraphicsLayers.

I'm starting with an empty Map without any Extent specified.

If I set the Map.Extent, after the Map Loaded event is called, to the same WKID (102100), my Layer IS NOT shown when added.
If i set the Map.Extent, before the Map Loaded event is called, my Layer IS shown when added.

How can I set the extent after the Map Loaded event is called and make sure my GraphicLayer is shown ?

The Layer is also shown if I first add a Layer that supports SpatialReference (such as a Tiled Layer).

It feels/seems that just setting the Map.Extent is not fully initializing the SpatialReference of the map.

Thanks
0 Kudos
5 Replies
AnttiKajanus1
Occasional Contributor III
So you don't have any basemap layer in the map. As you said, you can set Extent in xaml/code before map gets initialized. Do you know the spatial reference of your graphics or does it change depending on the data?

I think that you have have to define Spatial Reference to map when it is initialized if you don't have any other layers (basemap). So you could create GraphicsLayer with Graphics before initializing the map and use it's full extent. Or you can set your map to some spatial reference and then make sure that your Graphics gets projected into that SR.
0 Kudos
BKuiper
Occasional Contributor III
Thanks for your response, i guess your response confirmed my thoughts on the fact that the Map Extent feature is broken/not working as expected.

I want to be able to dynamically change the spatial reference of the map.

For my use case i want to start with a map without any spatial reference set.
Then i want to be able to set the spatial reference manually when a GraphicsLayer is being added or will let the map auto set the spatialreference when a baselayer (tiled layer) is added.

The problem is that setting the spatial reference manual, after the map is loaded, is not working, because my GraphicsLayer is not shown (although the spatial reference matches).

As a test case I set the Spatial Reference of the map before the map is loaded, and then my Graphics Layer is displayed.

So i guess there is a bug in the Map component, in that it doesn't work correctly when the Extent (Spatial Reference) is manually set after the map is loaded.

I would like to have somebody from Esri confirm this or comment on this, thanks!
0 Kudos
BKuiper
Occasional Contributor III
Another use case/example that is not working for me.

Map is empty, no extent set.

Say I load a basemap (Tiled) with WKID 102100, i then remove this layer and load a basemap (Tiled) with a different WKID, the map is not shown. The layer collection was empty inbetween switching the layers, but the projection of the map is not reset.

If i (re)set the projection manual (Map.Extent = null or Map.Extent = new Extent() { SpatialReference = new SpatialReference(WkidNewTiledMap) }) it is still not shown.

How can i achieve this in 10.1 ?
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

The SpatialReference of the Map cannot be changed once it is set.

I'll follow up on the Map Loaded question.

Cheers

Mike
0 Kudos
BKuiper
Occasional Contributor III
Thanks Mike for clarifying that. Looking forward to your reply regarding the Loading issue.
0 Kudos