操作方法

操作方法:使用 ArcGIS API for JavaScript 更改矢量底图的样式

Last Published: April 25, 2020

摘要

使用矢量底图的优点之一是底图的样式(如颜色)可使用 ArcGIS API for JavaScript 进行自定义。

过程

可以通过获取样式 URL 并将其应用于代码来更改矢量底图的样式。

  1. 获取样式 URL。 要使用 ArcGIS Online 帐户中现有矢量底图的样式,请按以下说明进行操作:
    1. 登录 ArcGIS Online 帐户,打开所需矢量底图的“项目详细信息”页面。
    2. 查看样式选项中查看矢量底图的样式 URL。
User-added image
  1. 复制样式 URL。 以下是样式 URL 的示例:
User-added image
  1. 在 ArcGIS API for JavaScript 中通过以下脚本应用样式 URL。
    require(["esri/map",
    "esri/layers/FeatureLayer",
    "esri/layers/VectorTileLayer",
    "dojo/domReady!"
    ], function (Map, FeatureLayer, VectorTileLayer) {
    
    //Initializing the map constructor
    var map = new Map("map", {
    center: [-118, 34.5],
    zoom: 8,
    //basemap: "topo"
    });
    
    //自定义矢量底图时,将 URL 更改为自定义 URL。
    var darkGrayStyleURL = "https://www.arcgis.com/sharing/rest/content/items/57436c01bc754dbb87dfb636b6484022/resources/styles/root.json";
    var lightGrayStyleURL = "https://www.arcgis.com/sharing/rest/content/items/1e47168d181248e491541ffd5a91c0de/resources/styles/root.json"
    
    let vectormap = new VectorTileLayer("https://basemaps.arcgis.com/v1/arcgis/rest/services/World_Basemap/VectorTileServer");
    vectormap.setStyle(lightGrayStyleURL);
    vectormap.on("load", () => {
    map.addLayer(vectormap);
    });
    
    
    
    });

文章 ID:000016718

接收通知并查找新问题或常见问题的解决方案

从我们全新的 AI 聊天机器人中获得简明答案和视频解决方案。

下载 Esri 支持应用程序

相关信息

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项