<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>
<link rel="stylesheet" href="https://js.arcgis.com/5.0/esri/themes/light/main.css" />
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>
const [Map, MapView, VectorTileLayer] = await $arcgis.import([
"@arcgis/core/views/MapView.js",
"@arcgis/core/layers/VectorTileLayer.js",
// Make map view and bind it to the map
const view = new MapView({
center: [22.441, 48.924],
const layer = new VectorTileLayer({
url: "http://www.arcgis.com/sharing/rest/content/items/4cf7e1fb9f254dcda9c8fbadb15cf0f8/resources/styles/root.json",
view.ui.add("topbar", "top-right");
// Get the screen point from the view's click event
view.on("click", (event) => {
// Search for graphics at the clicked location. View events can be used
// as screen locations as they expose an x,y coordinate that conforms
// to the ScreenPoint definition.
view.hitTest(event).then((response) => {
if (response.results.length) {
// do something with the result graphic
layer.getStyleLayer(response.results[0].graphic.attributes.layerName),
response.results[0].graphic.attributes,
// Switching between highlighting and unselecting country capital symbol layers
document.getElementById("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";
// Scales the original size of the icon by the provided factor.
// The new pixel size of the image will be
// the original pixel size multiplied by icon-size.
// 1 is the original size; 3 triples the size of the image.
styleLayer.layout["icon-size"] = 1.5;
document.getElementById("capitalButton").textContent = "Deselect country capitals";
styleLayer.paint["text-color"] = "#be1313";
styleLayer.paint["text-halo-color"] = "";
styleLayer.layout["icon-size"] = 1;
document.getElementById("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
document.getElementById("waterButton").addEventListener("click", () => {
waterStyleLayers.forEach((layerName) => {
const paintProperties = layer.getPaintProperties(layerName);
if (paintProperties["fill-pattern"] === "") {
paintProperties["fill-pattern"] = "Marine area";
document.getElementById("waterButton").textContent = "Change water color";
// set the fill-color and remove the fill-pattern
paintProperties["fill-pattern"] = "";
paintProperties["fill-color"] = "aqua";
document.getElementById("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
"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
document.getElementById("deleteButton").addEventListener("click", () => {
// delete the style layers if they exist in the style
if (deletedStyleLayers.length === 0) {
deleteLayerNames.forEach((layerName) => {
const styleLayer = layer.getStyleLayer(layerName);
const index = layer.getStyleLayerIndex(layerName);
deletedStyleLayers.push({
layer.deleteStyleLayer(layerName);
document.getElementById("deleteButton").textContent = "Add small cities";
// add the layers back to the style at their original index
deletedStyleLayers.forEach((item) => {
layer.setStyleLayer(item.layer, item.index);
document.getElementById("deleteButton").textContent = "Delete small cities";
let visibleValue = "visible";
// toggle visibility country names symbol layer
document.getElementById("toggleVisibility").addEventListener("click", () => {
visibleValue = isVisible ? "none" : "visible";
toggleLayers.forEach((layerName) => {
layer.setStyleLayerVisibility(layerName, visibleValue);
<div id="topbar" class="esri-widget">
<button class="esri-button style-button" id="capitalButton" type="button">
Highlight country capitals
<button class="esri-button style-button" id="waterButton" type="button">
<button class="esri-button style-button" id="toggleVisibility" type="button">
<button class="esri-button style-button" id="deleteButton" type="button">