Hi All,
We would like to change the webmap assigned to the app created using Web AppBuilder dynamically in a custom widget. And all other widgets such as "Search", "Coordinate", "OverView Map", "SclareBar", "HomeButton", "ZoomSlider" will work with out any impact. So, could anyone please direct me if there is any OOTB utility available in Web AppBuilder framework?
I am following the below procedure to implement this. Please let me know if there is any other best way.
1. Destroying current map (by..... this.map.destroy();)
2. Creating a new map with webmap id of desired webmap, using below code
var mapDeferred = jimuUtils.createWebMap("<url of portal>", "newWebmapID",
mapDivId, {});
3. Publishing "mapChanged" event
topic.publish('mapChanged', newMapObject);
4. Subscribing this event in all the widgets such as mentioned above and writing necessary code to set map object, events, to the code esri dijits
It is working some how. But I am not sure if this is the correct way. So, I would request for any best solutions.
Thanks & Regards,
Vara Prasad.
Solved! Go to Solution.
Vara,
In the MapManager.js there is a onAppConfigChanged method for this.
require "jimu/MapManager" MapManager var chgdAppConfig = this.appConfig; chgdAppConfig .map.itemId = "your new item id"; //if you need to change the portalUrl chgdAppConfig .map.portalUrl = "Your new portal url"; MapManager.getInstance().onAppConfigChanged (chgdAppConfig , "mapChange", {});
Vara,
In the MapManager.js there is a onAppConfigChanged method for this.
require "jimu/MapManager" MapManager var chgdAppConfig = this.appConfig; chgdAppConfig .map.itemId = "your new item id"; //if you need to change the portalUrl chgdAppConfig .map.portalUrl = "Your new portal url"; MapManager.getInstance().onAppConfigChanged (chgdAppConfig , "mapChange", {});
Thanks a lot Robert. It is very nice and very simple and working perfect.
Just one thing that, the custom widget from where this map switching is initiated, is not getting loaded again. I am using, Plateau theme, foldable panel.
Once, the app is reloaded with new WebMap, blank widget panel is kept opened (in which custom widget was opened before map was changed). It did not re load the original widget. Is it expected behavior and need to write any custom code to instantiate the widget again? or is there any other way?
Thanks & Regards,
Vara Prasad.
Vara,
Sorry I don't know the answer to that question. I would think that your widget needs to listen from map changed and then instantiate itself again.
Thanks Robert. I will give a try.
With Regards,
Vara Prasad.