How to reload existing map and view?

430
1
06-12-2020 02:50 PM
ChristianKempis
New Contributor

Hi im currently using the API and react to build a site which houses a map as its primary page.  The map loads fine with all of its layers, however i currently have logic that allows me to "hide" the map div for other elements to show.  I want to be able to reselect my map from the navigation bar I have setup and reload my old map.  

At the moment the map does not display when i try to reshow the div containing the map. 

return ( 

<div>

   ...

   { this.state.showMap === true && ref={this.mapViewReference }

   ...

</div>

The data for the old map still exists with all of its layers etc i just want to be able to reload the map.

Tags (2)
0 Kudos
1 Reply
ChristianKempis
New Contributor

So i was able to come out with a solution however i feel this is a very hacky work around to a feature that arcgis should have by default.

I had to essentially take the object holding my previous map state and copy all of it into a new map with initialization.

const reloadMap (domElementRef) => {

   let oldMap = Object.assign({}, mapObject)

   const map = new Map({

      basemap: oldMap.basemap,

      layers: oldMap.mapView.map.layers

   })

   

   const view = new MapView({

      container: domElementRef,

      map: map

      ....

   })

}

Code similar to above allows the map to completely reload.  Note:  you will have to readd ui elements again as attempting to directely copy ui elements from the old object does not work.  If anyone has a better solution im open to suggestions

0 Kudos