[JS API 4.x] SPA with multiple map configurations

756
2
Jump to solution
05-17-2018 01:19 AM
SebastianKvist
New Contributor II

Hi,

We are currently developing a GIS-SPA, in which the user should be able to choose between several map configurations, lets call them "map modes". These map modes will present different map layers from different sources, render different tools available etc.

The user should be able to go back and forth between these map modes, keeping the state of some mapView-properties like extent, scale etc.

Our initial idea was to always work with a single instance of the MapView, while having several instances of the Map-class. When the user would switch to a different map mode, we simple replace the instance of the Map with the one corresponding to the current map mode, informing out MapView of this new Map it should be viewing.

We also have a single instance of LayerList, connected to our one MapView-instance. 

Switching "map mode" was working just fine in 4.6, the MapView loaded the new map config and the LayerList was automatically updated. After updating to 4.7, the MapView seems to be loading the new map config correctly, but the LayerList produces a DOM-exception: 'Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.

Now, after reading "A Map object should be created prior to a view so it can be passed into the map property of that view..." in the API Reference, it got me thinking that maybe we are going about this map mode handling the wrong way.

Would we perhaps be better off creating a sort of bundle for the Map and MapView, keeping a one-to-one relation for these entities, for each of our map modes? Would this in turn also call for having multiple instances of the LayerList?

Thanks in advance,

Sebastian

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Sebastian,

  It sounds like a bug needs to be reported about the LayerList widgets error. Switching the map is a valid workflow and esri even has a sample for this. So I would say your workflow is fine and there is just a bug you have to work around. You may need to destroy and recreate the LayerList widget each map switch until the bug is fixed.

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Sebastian,

  It sounds like a bug needs to be reported about the LayerList widgets error. Switching the map is a valid workflow and esri even has a sample for this. So I would say your workflow is fine and there is just a bug you have to work around. You may need to destroy and recreate the LayerList widget each map switch until the bug is fixed.

0 Kudos
SebastianKvist
New Contributor II

Thank you for your answer. Yes, I imagined the possibility of it being a bug - however I noticed we actually recreate some widgets when the map changed, which in fact seem to have triggered this error. The error mentioned above would present itself when I recreated the Print widget, rather than the LayerList widget.

Anyways, the key question here was regarding the ability to reuse the MapView instance and then in turn reuse widget instances depending on the same MapView. I feel I have gotten the answer to that.

Regards, 

Sebastian

0 Kudos