How to create a BasemapGallery using "@arcgis/map-components/components/arcgis-basemap-gallery"?
Solved! Go to Solution.
I suppose there's a couple of ways you can do this.
You can update the source on the BasemapGallery element https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-basemap-gallery/
<arcgis-map item-id="06ca49d0ddb447e7817cfc343ca30df9">
<arcgis-basemap-gallery position="top-right"></arcgis-basemap-gallery>
</arcgis-map>
// in your app somewhere
import LocalBasemapsSource from "@arcgis/core/widgets/BasemapGallery/support/LocalBasemapsSource.js";
const bmgElement = document.querySelector('arcgis-basemap-gallery');
bmgElement.source = new LocalBasemapsSource({
basemaps
});
If you want to do it all via JS
import LocalBasemapsSource from "@arcgis/core/widgets/BasemapGallery/support/LocalBasemapsSource.js";
const bmgElement = document.createElement('arcgis-basemap-gallery');
bmgElement.position = "top-right";
bmgElement.source = new LocalBasemapsSource({
basemaps
});
document.querySelector('arcgis-map').appendChild(bmgElement);
I suppose there's a couple of ways you can do this.
You can update the source on the BasemapGallery element https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-basemap-gallery/
<arcgis-map item-id="06ca49d0ddb447e7817cfc343ca30df9">
<arcgis-basemap-gallery position="top-right"></arcgis-basemap-gallery>
</arcgis-map>
// in your app somewhere
import LocalBasemapsSource from "@arcgis/core/widgets/BasemapGallery/support/LocalBasemapsSource.js";
const bmgElement = document.querySelector('arcgis-basemap-gallery');
bmgElement.source = new LocalBasemapsSource({
basemaps
});
If you want to do it all via JS
import LocalBasemapsSource from "@arcgis/core/widgets/BasemapGallery/support/LocalBasemapsSource.js";
const bmgElement = document.createElement('arcgis-basemap-gallery');
bmgElement.position = "top-right";
bmgElement.source = new LocalBasemapsSource({
basemaps
});
document.querySelector('arcgis-map').appendChild(bmgElement);
Hello @ReneRubalcava,
Thank you for your answer.
Looks like the basemapGallery needs to be on the map:
In my case, it is on different component (in a calcite-panel):
Maybe, I should use BasemapGalleryViewModel? How to use BasemapGalleryViewModel?
BasemapGalleryViewModel provides the logic for the BasemapGallery widget and component. How does it provide?
Forrest
All of the components have a referenceElement property and reference-element attribute so it does not need to be inside a map component.
That can be the id to the arcgis-map component. Here is a blog post that might be useful.
Thank you so much!