Multiple maps on a single page
I don't think this is possible, but want to ask just in case I am overlooking something: Is it possible to have multiple maps/viewers on a single page (without using IFrames)?
-
Hi Berend,
Last time I checked, this isn't currently possible. The ArcGIS JavaScript API takes an element ID in the constructor and hosts the map in the element with that ID. A common pattern for APIs that host UI inside of consumer-specified DOM elements is to take either an ID or an actual DOM element.
IDs must be unique per document, so any time an element with an ID exists, it must be the only one on the page. We try to avoid this in our own components, but sometimes we run into situations where an ID is explicitly needed. Moving forward, we're going to generate random IDs and data-bind to them (e.g. something like <div class="map" data-binding='{@random-id: mapId}' />), which will allow us to create reusable components out of existing components not quite designed for multiple instances per page.
If you try embedding multiple instances in the same page, be aware that it may work in one browser but not in another. I believe it's entirely up to the browser how to deal with conflicting IDs, and they may outright delete or replace conflicting elements in the DOM tree.
You could try modifing the ID of the map div after the MapView is created in order to prevent the next viewer from having a conflict.
Unfortunately, iFrames are probably the easiest choice here. Tip : preserve the two "meta" tags in Index.html by adding them to the page hosting the iFrame. The "viewport" tag is important for mobile/touch devices.
-Jason
0 -
Thanks Jason!
0
Please sign in to leave a comment.
Comments
2 comments