refresh the map when adding new layer

3428
4
11-20-2011 08:17 PM
salimalzahrani
New Contributor
hi everyone,
i am quite newbie on Javascript API, what i am trying to do is:
i added new layers to the map and need to refresh or reload the map so i can see the new layer
i tried many way mentioned here but nothing works
http://forums.esri.com/Thread.asp?c=158&f=2396&t=259812

this is the error i get always.
[08:59:28.833] _547 is undefined @ http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.5compact:48

here is my code for this idea

    map.removeLayer(tiledMapServiceLayer);
    map.removeLayer(dynamicMapServiceLayer);
    var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("url");
    map.addLayer(tiledMapServiceLayer);
    var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("url");
    map.addLayer(dynamicMapServiceLayer);
    map.setExtent(map.extent);
0 Kudos
4 Replies
JeffPace
MVP Alum
hi everyone,
i am quite newbie on Javascript API, what i am trying to do is:
i added new layers to the map and need to refresh or reload the map so i can see the new layer
i tried many way mentioned here but nothing works
http://forums.esri.com/Thread.asp?c=158&f=2396&t=259812

this is the error i get always.
[08:59:28.833] _547 is undefined @ http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.5compact:48

here is my code for this idea

    map.removeLayer(tiledMapServiceLayer);
    map.removeLayer(dynamicMapServiceLayer);
    var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("url");
    map.addLayer(tiledMapServiceLayer);
    var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("url");
    map.addLayer(dynamicMapServiceLayer);
    map.setExtent(map.extent);


both addLayer and setExtent should refresh your map, but you are not creating valid layers. 

var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("url");

you are passing in the String "url", you need to send the actual url.
0 Kudos
salimalzahrani
New Contributor
this is only to shorten the line
0 Kudos
salimalzahrani
New Contributor
i wrote "url" just to shorten the line 🙂

my map is working but i need to be able to change the service layer from one service to another
0 Kudos
JasonSandall
New Contributor
Use the destroy method.

destroy()
Destroys the map instance. After the map is destroyed it is no longer valid however you can re-use the div element of the map to create a new map instance. (As of v2.0)
Return value: none
Code snippets:
map.destroy();
0 Kudos