I am using the ArcGIS API for JavaScript 3.x and would like to add a vector tile layer that I created to my map as a basemap that appears in the basemap gallery dijit. I am able to load my layer into the map as a VectorTileLayer but when I try to add the layer to the basemaps it just doesn't seem to work.
How can I do this?
I've tried creating a basemap object with the url set to my VectorTileServer, creating a BasemapLayer with a VectorTileLayer type, and use creating a map without a basemap and adding the VectorTileLayer as a layer. The last try got my closest and looks like this:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>Vector Basemap Test</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.31/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.31/esri/css/esri.css">
<style>
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="https://js.arcgis.com/3.15/"></script>
<script>
var map4;
require([
"esri/map",
"esri/basemaps",
"esri/dijit/BasemapLayer",
"esri/layers/VectorTileLayer",
"esri/dijit/Basemap",
"esri/dijit/BasemapGallery",
"dojo/domReady!"
], function(Map, esriBasemaps, BasemapLayer, VectorTileLayer, Basemap, BasemapGallery) {
esriBasemaps.vector1 = {
baseMapLayers: [{ url: "https://tiles.arcgis.com/tiles/bFDgLqS5IyUBQLAd/arcgis/rest/services/Color_Basemap_with_Buildings/VectorTileServer" }],
title: "vector1"
};
map4 = new Map("map4", {
center: [-75.520195, 39.146485],
zoom: 13
});
var vtlayer = new VectorTileLayer("https://tiles.arcgis.com/tiles/bFDgLqS5IyUBQLAd/arcgis/rest/services/Color_Basemap_with_Buildings/VectorTileServer/resources/styles/root.json");
map4.addLayer(vtlayer);
var basemapGallery4 = new BasemapGallery({
showArcGISBasemaps: false,
map: map4
}, "basemapGallery4");
basemapGallery4.startup();
basemapGallery4.on("error", function(msg) {
console.log("basemap gallery error: ", msg);
});
});
</script>
</head>
<body class="claro">
<div style="margin:5px;padding:0;width:300px;height:300px;display:inline-block;">
<div id="map4" style="padding:0;width:100%;height:100%;postition:relative;">
<div style="position:absolute;z-Index:999;width:150px;height:100px;overflow:auto;">
<div id="basemapGallery4"></div>
</div>
</div>
</div>
</body>
</html>
However, the layer doesn't show in my basemap gallery and the other ways of doing it are closer to the few examples I can find online.
You can see my other tries here: https://codepen.io/sirhcybe/pen/abOoqmq