<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>VectorTileLayer - update style | Sample | ArcGIS Maps SDK for JavaScript</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.1/"></script>
<arcgis-map center="22.441, 48.924" zoom="4">
<arcgis-zoom slot="top-left"></arcgis-zoom>
<calcite-button id="capitalButton" slot="top-right" width="full"> Highlight country capitals </calcite-button>
<calcite-button id="waterButton" slot="top-right" width="full"> Change water color </calcite-button>
<calcite-button id="toggleVisibility" slot="top-right" width="full"> Toggle country labels </calcite-button>
<calcite-button id="deleteButton" slot="top-right" width="full"> Delete small cities </calcite-button>
const [Map, VectorTileLayer] = await $arcgis.import([
"@arcgis/core/layers/VectorTileLayer.js",
const layer = new VectorTileLayer({
url: "https://www.arcgis.com/sharing/rest/content/items/4cf7e1fb9f254dcda9c8fbadb15cf0f8/resources/styles/root.json",
const viewElement = document.querySelector("arcgis-map");
viewElement.map = new Map({
const capitalButton = document.getElementById("capitalButton");
const waterButton = document.getElementById("waterButton");
const deleteButton = document.getElementById("deleteButton");
const toggleVisibilityButton = document.getElementById("toggleVisibility");
// Switching between highlighting and unselecting country capital symbol layers
capitalButton.addEventListener("click", () => {
const styleLayer = layer.getStyleLayer("City small scale/x large admin0 capital");
if (styleLayer.paint["text-color"] === "#be1313") {
styleLayer.paint["text-color"] = "#E400E0";
styleLayer.paint["text-halo-color"] = "#E400E0";
styleLayer.layout["icon-size"] = 1.5;
capitalButton.textContent = "Deselect country capitals";
styleLayer.paint["text-color"] = "#be1313";
styleLayer.paint["text-halo-color"] = "";
styleLayer.layout["icon-size"] = 1;
capitalButton.textContent = "Highlight country capitals";
layer.setStyleLayer(styleLayer);
// all water body style layer names
const waterStyleLayers = [
"Marine area/bathymetry depth 1/2",
"Bathymetry/depth 2 (shallow water)/1",
"Water area small scale/1",
// change fill-pattern and fill-color paint properties for water body style layers
waterButton.addEventListener("click", () => {
for (const layerName of waterStyleLayers) {
const paintProperties = layer.getPaintProperties(layerName);
if (paintProperties["fill-pattern"] === "") {
paintProperties["fill-pattern"] = "Marine area";
waterButton.textContent = "Change water color";
paintProperties["fill-pattern"] = "";
paintProperties["fill-color"] = "aqua";
waterButton.textContent = "Change water pattern";
// change the fill-color paint property for the layer.
layer.setPaintProperties(layerName, paintProperties);
// delete all non-capital cities symbol layers from the style
const deleteLayerNames = [
"City small scale/medium other capital",
"City small scale/large other capital",
"City small scale/x large admin1 capital",
"City small scale/medium non capital",
"City small scale/x large non capital",
"City small scale/large non capital",
let deletedStyleLayers = [];
// delete or add small cities style layers
deleteButton.addEventListener("click", () => {
// delete the style layers if they exist in the style
if (deletedStyleLayers.length === 0) {
for (const layerName of deleteLayerNames) {
const styleLayer = layer.getStyleLayer(layerName);
const index = layer.getStyleLayerIndex(layerName);
deletedStyleLayers.push({
layer.deleteStyleLayer(layerName);
deleteButton.textContent = "Add small cities";
// add the layers back to the style at their original index
for (const item of deletedStyleLayers) {
layer.setStyleLayer(item.layer, item.index);
deleteButton.textContent = "Delete small cities";
// toggle visibility country names symbol layer
toggleVisibilityButton.addEventListener("click", () => {
const visibleValue = isVisible ? "none" : "visible";
for (const layerName of toggleLayers) {
layer.setStyleLayerVisibility(layerName, visibleValue);