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
Solved! Go to Solution.
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} />`
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} />`
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);
Both of these approaches work, and I see why my original approach had it's behavior. Thank you @ReneRubalcava and @Justin_Greco.