refresh button

1662
4
10-02-2012 11:17 AM
BillShockley
Occasional Contributor
I am working with the toolbar sample:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/toolbar_naviga...

all of them work great, but I would like to add a refresh button to the toolbar.  Can anyone assist me with this or point me in the right direction?

Thanks
0 Kudos
4 Replies
by Anonymous User
Not applicable
Hi Bill :),
What are you trying to 'refresh,' the application..the map?  You could add a refresh button that refreshes the map and sets it to its default extent and removes any additional operational layers that were added.  Is this the kind of functionality you are referring to?
0 Kudos
BillShockley
Occasional Contributor
Hi Bill :),
What are you trying to 'refresh,' the application..the map?  You could add a refresh button that refreshes the map and sets it to its default extent and removes any additional operational layers that were added.  Is this the kind of functionality you are referring to?


Yes that would be a start and see how it works.  I'm new to the javascripting but I'm trying.  Any help is much appreciated.
0 Kudos
BetsySchenck-Gardner
Occasional Contributor
Well to start with, if you want to return to your original default extent, create a global variable called spatialExtent and initialize it with the starting extent of your map.  For instance, add the following statement in your init function.
      startExtent = new esri.geometry.Extent(-27471128,-11652400,4072293,15507815, new esri.SpatialReference({wkid:3857}));
Now create a button called Reset which when you click on it, calls the function resetMap.  All you have to have in the function resetMap is the following:
      map.setExtent(startExtent);
That will reload your map to its original location. 

As far as getting back the original layers you had drawn on your map, as long as you declare them globally and define them in your init function, you can recall them in the resetMap function.   For instance, if there is a particular basemap you originally had displayed, you would have to do the following statement in your init function:
  basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer");
Then in the resetMap function you need to add the following:
  map.removeAllLayers();
  map.addLayer(basemap);  

The map.removeAllLayers() clears the map of whatever you have displayed on it.  The map.addLayer(basemap) adds the basemap back.  You can do the same with any additional layers as long as you define them globally so they can be seen by the function.  Hope this makes sense.  I'm assuming you know a little bit of javascript.
0 Kudos
BillShockley
Occasional Contributor
Well to start with, if you want to return to your original default extent, create a global variable called spatialExtent and initialize it with the starting extent of your map.  For instance, add the following statement in your init function.
      startExtent = new esri.geometry.Extent(-27471128,-11652400,4072293,15507815, new esri.SpatialReference({wkid:3857}));
Now create a button called Reset which when you click on it, calls the function resetMap.  All you have to have in the function resetMap is the following:
      map.setExtent(startExtent);
That will reload your map to its original location. 

As far as getting back the original layers you had drawn on your map, as long as you declare them globally and define them in your init function, you can recall them in the resetMap function.   For instance, if there is a particular basemap you originally had displayed, you would have to do the following statement in your init function:
  basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer");
Then in the resetMap function you need to add the following:
  map.removeAllLayers();
  map.addLayer(basemap);  

The map.removeAllLayers() clears the map of whatever you have displayed on it.  The map.addLayer(basemap) adds the basemap back.  You can do the same with any additional layers as long as you define them globally so they can be seen by the function.  Hope this makes sense.  I'm assuming you know a little bit of javascript.


I already have a full extent button as the example shows.  I have a webpage that has a javascript like the example from my previous post and I have a live 'Dynamic Map Service Layer' in the map that shows where trucks are located.  Instead of having to refresh the entire web page, I would like a button that refreshes just the map.  I'm not that great with javascript, but I'm willing to learn.  Any help is much appreciated.
0 Kudos