<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to Create Duplicate Map in JSAPI in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-create-duplicate-map-in-jsapi/m-p/252187#M23350</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adding the layers from one map to another causes issues. You'll want to set it up to create new layers using the same URLs from the existing layers and any options or renderers you may have used and then add the new layers to the second map. You can do checks of what type of layer it is using the &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof"&gt;instanceof&lt;/A&gt; operator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The layers should also have a &lt;EM&gt;declaredClass&lt;/EM&gt; property you can check to see what the type of layer is as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For reference, this is how the OverviewMap does it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Feb 2015 17:19:46 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2015-02-12T17:19:46Z</dc:date>
    <item>
      <title>How to Create Duplicate Map in JSAPI</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-create-duplicate-map-in-jsapi/m-p/252186#M23349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using the JavaScript API, I have a map object, and I'd like to create a second map, which is a copy of the first map. Hopefully somebody knows of a simple way to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After failing to discover a one-liner that copies the map, I thought I could spin through the layers, and add them to the second map. Like this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var secondMap = new Map('secondMapNode');
&lt;SPAN style="line-height: 1.5;"&gt;for(var j = 0; j &amp;lt; firstMap.layerIds.length; j++) {&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var layer = firstMap.getLayer(firstMap.layerIds&lt;J&gt;);&lt;/J&gt;
&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; secondMap.addLayer(layer);&lt;/SPAN&gt;
}
secondMap.setExtent(firstMap.extent);&lt;/PRE&gt;&lt;P&gt;This doesn't work, though. The secondMap acts strange, and the firstMap disappears. I guess that makes sense, because the layer gets confused about which map is belongs to. I'm hoping that I don't have the check the layer type, copy the tileInfo, and everything else.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An alternate approach that I wanted to try was to get the webmap json from the first map, and then create the second map from the json. That would work, but I can't find any code to get webmap json from a map (since the firstMap was created manually, not from webmap json).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:30:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-create-duplicate-map-in-jsapi/m-p/252186#M23349</guid>
      <dc:creator>deleted-user-Jie3eyjOl9XM</dc:creator>
      <dc:date>2021-12-11T12:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create Duplicate Map in JSAPI</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-create-duplicate-map-in-jsapi/m-p/252187#M23350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adding the layers from one map to another causes issues. You'll want to set it up to create new layers using the same URLs from the existing layers and any options or renderers you may have used and then add the new layers to the second map. You can do checks of what type of layer it is using the &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof"&gt;instanceof&lt;/A&gt; operator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The layers should also have a &lt;EM&gt;declaredClass&lt;/EM&gt; property you can check to see what the type of layer is as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For reference, this is how the OverviewMap does it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Feb 2015 17:19:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-create-duplicate-map-in-jsapi/m-p/252187#M23350</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2015-02-12T17:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create Duplicate Map in JSAPI</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-create-duplicate-map-in-jsapi/m-p/252188#M23351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the quick reply. I was actually knee-deep in cloning the DOM node, and you saved me from that mess. The instanceOf operator saved a lot of tedium. This isn't so bad. But, I wish I could find a way to avoid copying each constructor parameter. Here's the general design of the function that I'll use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;_copyMap: function(sourceMap, newDomNode, mapOptions) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var newMap = new Map(newDomNode, mapOptions);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (var j = 0; j &amp;lt; sourceMap.layerIds.length; j++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var layer = sourceMap.getLayer(sourceMap.layerIds&lt;J&gt;);&lt;/J&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (layer instanceof ArcGISDynamicMapServiceLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newMap.addLayer(new ArcGISDynamicMapServiceLayer(layer.url, {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible: layer.visible,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; opacity: layer.opacity,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; imageParameters: layer.imageParameters
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (layer instanceof WebTiledLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newMap.addLayer(new WebTiledLayer(layer.urlTemplate, {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible: layer.visible,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; opacity: layer.opacity,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullExtent: layer.fullExtent,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; initialExtent: layer.initialExtent,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tileInfo: layer.tileInfo,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tileServers: layer.tileServers,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subDomains: layer.subDomains,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; copyrightText: layer.copyrightText
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // DynamicLayer, ImageService, VETiled, etc omitted for brevity&lt;/SPAN&gt;
&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.error("Unsupported Layer Type");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(layer);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return newMap;
},&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:30:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-create-duplicate-map-in-jsapi/m-p/252188#M23351</guid>
      <dc:creator>deleted-user-Jie3eyjOl9XM</dc:creator>
      <dc:date>2021-12-11T12:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create Duplicate Map in JSAPI</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-create-duplicate-map-in-jsapi/m-p/252189#M23352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What may help you out is that in the ArcGIS JavaScript API, with the layers (and other places sometimes), it saves the parameters passed to it in a property called &lt;STRONG&gt;_params&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So &lt;EM&gt;layer._params&lt;/EM&gt; will have the original options that were used to create the layer, minus the url. You could use it to create the new Layer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would use the &lt;STRONG&gt;clone&lt;/STRONG&gt; method of &lt;A href="http://dojotoolkit.org/reference-guide/1.10/dojo/_base/lang.html#clone"&gt;dojo/_base/lang&lt;/A&gt; to prevent any overwriting of the parameters the layer may try and do. Just to be safe.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's one of those &lt;EM&gt;"use at your own risk, underscored property/methods are undocument"&lt;/EM&gt; type things, but it should help out with what you are doing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Feb 2015 18:15:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-create-duplicate-map-in-jsapi/m-p/252189#M23352</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2015-02-12T18:15:49Z</dc:date>
    </item>
  </channel>
</rss>

