The only thing missing is I cannot find the 'well known string ids' from the basemaps in the basemap gallery for which I can use to reference later, i.e. streets, streets-vector, topo dark-gray
, etc etc.
I am getting the objects responses with the below on any change of selection to the basemap gallery, I am seemingly getting EVERYTHING back but the 'well known string ids' in which I can save and use later to render that basemap. I am getting the title
and property ID but the ids to change the map, i.e. topo
are no where to be found within the object responses.
basemapGallery.watch('activeBasemap', function(newBasemap, property, object) console.log('new active basemap', {newBasemap, property, object});.......... // also have tried pulling in the basemap obj here as well
i.e. I can programmatically, manually, change the basemap in my application or in the dev console with the below.
myapp.widgets.basemapManager.basemapGallery.activeBasemap = "streets"
The docs lead me to believe I can use portal item id to reference the basemaps but this did not work. I have tried to reference it every which way in accordance to the above line.
Below is a screenshot of my watch function
after a selection has been made to the basemap gallery. No named string ids to change the map found, i.e. 'dark-grey' 'topo' 'streets' etc.
Solved! Go to Solution.
Cam,
There is no good way to get those well know ids. But you can use the portal item id.
basemapGallery.activeBasemap = {portalItem: {id: "588f0e0acc514c11bc7c898fed9fc651"}};
This sets the basemap to "topo".
Cam,
There is no good way to get those well know ids. But you can use the portal item id.
basemapGallery.activeBasemap = {portalItem: {id: "588f0e0acc514c11bc7c898fed9fc651"}};
This sets the basemap to "topo".
Hello,
i have the same problem, only that I use
self-defined basemaps.
myBasemap = new Basemap({
baseLayers: [new TileLayer({title: 'Basiskarte', url: arcgisServerUrl + "Basiskarte/Basiskarte2c/ MapServer",visible: true}),
id: "Basiskarte",
title: "Basiskarte",
thumbnailUrl: "img/Basemap/Basiskarte.jpg"
});
....
How do I set the basemap active :
basemapGallery.activeBasemap = {id: "Basiskarte"}; ???
Ulrich,
In your case it would be:
basemapGallery.activeBasemap = myBasemap;
Use the actual basemap object.
Thanks Robert,
This is mostly working for all maps in my basemap gallery.
However, sadly... there are 4 maps that do not have a portalItem object. Alas their portal item ids are returning null. Any options for me here?
Are they maps that would normally have a well known id?
I do not think so. I'm thinking I may to manually create an associative array of some sorts for these 4. So close, yet so far away....
Edit, Update:
So the above did not work, I tried grabbing the maps that weren't returning a portal item and assigning one to them. However it didn't work, any options to capture these and re-render?
I tried every which way just setting a portal item id within the below format for my failing maps.
Hi all,
I am running into the same issue. Have there been any updates to the API that make it easier to get the well known string ids for a basemap that is selected from the basemap gallery? That seems silly to have to work with the portal ID, and deal with it not always being there.
Use toJSON and fromJSON.
To save the current basemap to localstorage, for example:
let basemapGallery = new BasemapGallery({ view: view });
basemapGallery.watch("activeBasemap", (evt) => {
localStorage.opsBaseMap = JSON.stringify(evt.toJSON());
});
To load the basemap into a new Map:
require(["esri/views/MapView", "esri/Map", "esri/Basemap"], (MapView, Map, Basemap) => {
let tmap = Basemap.fromJSON(JSON.parse(localStorage.opsBaseMap));
map = new Map({
basemap: tmap
});
});