Is there any OOTB designed utility to change the webmap dynamically in app designed in Web AppBuilder?

2057
4
Jump to solution
04-20-2016 11:12 PM
Vara_PrasadM_S
Occasional Contributor II

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.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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", {});

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

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_PrasadM_S
Occasional Contributor II

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.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
Vara_PrasadM_S
Occasional Contributor II

Thanks Robert. I will give a try.

With Regards,

Vara Prasad.

0 Kudos