Select to view content in your preferred language

Map components with feature layers, why must I specify the basemap twice?

302
3
Jump to solution
10-27-2025 07:53 AM
AntonioMedrano
Occasional Contributor

I'm curious why I must specify a basemap twice when using a map component, then creating a map object in the JavaScript? For example, in this codepen, if I remove the basemap declaration either in line 27 or line 46, the map breaks. I purposefully put different basemaps to see which one in the end gets used. It's not a huge deal to define it twice, but it seems like it should only have to be once.

https://codepen.io/antoniomedrano/pen/NPxzozJ?editors=1000 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Esri Frequent Contributor

You don't need to. You can start with just `<arcgis-map>` and skip the `viewOnReady` and just assign the map.

https://codepen.io/odoe/pen/RNrJdVv?editors=1000

This also makes it easier to bind a map in a framework so it could look something like `<arcgis-map map={localMap} />`

View solution in original post

3 Replies
ReneRubalcava
Esri Frequent Contributor

You don't need to. You can start with just `<arcgis-map>` and skip the `viewOnReady` and just assign the map.

https://codepen.io/odoe/pen/RNrJdVv?editors=1000

This also makes it easier to bind a map in a framework so it could look something like `<arcgis-map map={localMap} />`

Justin_Greco
Frequent Contributor

After viewOnReady, the viewElement.map is already defined, you don't need to set it to a new Map object, you just need to add the parks layer to the existing map.

const viewElement = document.querySelector("arcgis-map");
await viewElement.viewOnReady();
viewElement.map.add(parksLayer);

 

AntonioMedrano
Occasional Contributor

Both of these approaches work, and I see why my original approach had it's behavior. Thank you @ReneRubalcava and @Justin_Greco.

0 Kudos