Select to view content in your preferred language

Where did I go wrong

948
6
12-24-2012 05:02 PM
DidarBultanov
Emerging Contributor
not displayed
private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            MyMap.Layers.Clear();
            ArcGISTiledMapServiceLayer arcgisLayer = new ArcGISTiledMapServiceLayer();
            Envelope env = new Envelope();
            switch (((RadioButton)e.OriginalSource).Name)
            {
                case "Layer1":
                    arcgisLayer.InitializationFailed += Layer_InitializationFailed;
                    arcgisLayer.Url = "http://myserver/arcgis/rest/services/kz28/MapServer";
                    arcgisLayer.Initialize();
                    env = new Envelope(-1176967.4359368654, 4452540.931675468, 1966840.1233924914, 6252256.853320533);
                    env.SpatialReference = new SpatialReference(32642);
                    MyMap.Extent = env;
                    MyMap.Layers.Add(arcgisLayer);
                break;
                case "OpenStreesMap":
                    OpenStreetMapLayer osmLayer =new OpenStreetMapLayer();
                    osmLayer.InitializationFailed += Layer_InitializationFailed;
                    string layerTypeTag = ((RadioButton)e.OriginalSource).Tag as string;
                    osmLayer.Style = OpenStreetMapLayer.MapStyle.Mapnik ;
                    osmLayer.Initialize();

                break;
                case "Layer3":
                    arcgisLayer.Url ="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer";
                    arcgisLayer.InitializationFailed += Layer_InitializationFailed;
                    env = new Envelope(-20037507.2295943, -19971868.8804086, 20037507.2295943, 19971868.8804086);
                    env.SpatialReference = new SpatialReference(102100);
                    MyMap.Extent = env;
                    MyMap.Layers.Add(arcgisLayer);
                break;
            }  
           
        } 
Thanks
0 Kudos
6 Replies
ChristopherHill
Deactivated User
What exactly are you having a problem with? From what I can see of what you have pasted is that you never added open street map to the map control.

MyMap.Layers.Add(osmLayer); <-- missing
0 Kudos
DidarBultanov
Emerging Contributor
What exactly are you having a problem with? From what I can see of what you have pasted is that you never added open street map to the map control.

MyMap.Layers.Add(osmLayer); <-- missing

different spatial reference
is an error in the approximation is not visible layers World_Imagery
0 Kudos
DominiqueBroux
Esri Frequent Contributor
different spatial reference


To change the Spatialreference of a map, you have first to clear all the layers and to set the map extent to null before adding your new layers.
I also recommend you to instantiate a new layer each time you change the URL instead of reusing the same one.
0 Kudos
DidarBultanov
Emerging Contributor
To change the Spatialreference of a map, you have first to clear all the layers and to set the map extent to null before adding your new layers.
I also recommend you to instantiate a new layer each time you change the URL instead of reusing the same one.

I have all of your recommendations already made
MyMap.Layers.Clear();
ArcGISTiledMapServiceLayer arcgisLayer = new ArcGISTiledMapServiceLayer();
Envelope env = new Envelope();
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Envelope env = new Envelope();

You have to set the map extent to null by code like: MyMap.Extent = null;
0 Kudos
DidarBultanov
Emerging Contributor
You have to set the map extent to null by code like: MyMap.Extent = null;

does not help, swears at different spatial reference
           
MyMap.Layers.Clear();
            MyMap.Extent = null;
            ArcGISTiledMapServiceLayer arcgisLayer = new ArcGISTiledMapServiceLayer();
            Envelope env = new Envelope();

I realized the error was due to window OverviewMap
Thanks
0 Kudos