I was recently tasked to create a custom basemap layer for our apps that combine some of ESRI's published Vector Basemaps and one of their hillshade basemaps. To accomplish, I did something like this:
/**
* Returns a custom ESRI Basemap
*
* @returns {Promise<Object>} ESRI Basemap
*/
export async function createCustomHillshadeBasemap() {
const [Basemap, esriRequest, TileLayer, VectorTileLayer] = await loadModules([
"esri/Basemap",
"esri/request",
"esri/layers/TileLayer",
"esri/layers/VectorTileLayer",
]);
let labelStyle;
let canvasStyle;
// The label style used by the World ESRI Dark Gray Canvas (taken from looking at network request, is this subject to change?):
let labelStyleUrl = "https://www.arcgis.com/sharing/rest/content/items/747cb7a5329c478cbe6981076cc879c5/resources/styles/root.json";
labelStyle = await esriRequest(labelStyleUrl, {
responseType: "json",
});
// The canvas style used by the World ESRI Dark Gray Canvas:
let canvasStyleUrl =
"https://www.arcgis.com/sharing/rest/content/items/5e9b3685f4c24d8781073dd928ebda50/resources/styles/root.json";
canvasStyle = await esriRequest(canvasStyleUrl, {
responseType: "json",
});
let baseLayers = [
new VectorTileLayer({
effect: "opacity(80%) brightness(90%)",
style: canvasStyle.data,
title: "darkCanvas",
url: "https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer",
}),
new VectorTileLayer({
style: labelStyle.data,
title: "labels",
url: "https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer",
}),
];
baseLayers.unshift(
new TileLayer({
title: "hillshade",
url: "https://services.arcgisonline.com/arcgis/rest/services/Elevation/World_Hillshade/MapServer",
})
);
const basemap = new Basemap({
baseLayers: baseLayers,
id: "basemap",
title: "basemap",
});
return basemap;
}
Above works well. But note at line 25 I am using a url to json that I found ESRI uses for its basemap vector styling rules. The only way I encountered this was by inspecting the network requests in my browser when loading this layer. What I'm wondering, is: will this change? Is that style url something we can count on as a constant or will what that entails change without notice (possible concern)? Or is it possible that the url suddenly changes (note that hex string as part of the url) and we're suddenly referencing a dead endpoint (bigger concern)?
I didn't see any documentation on this so wondering if there are any pitfalls I should be aware of. Does ESRI want us to make our own styles and publish them ourselves (I hope not) and/or is there a more recommended way to create a custom basemap layer in ArcGIS JavaScript API that does not require specifying the style url for the basemap if we just want to combine a couple of ESRI's already published sources?