A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.arcgis.com/javascript/latest/tutorials/display-a-custom-basemap-style/ below:

Display a custom basemap style | Overview | ArcGIS Maps SDK for JavaScript 4.33

Learn how to access and display a styled vector basemap layer in a map.

A styled basemap layer is a set of styles that you define to override one of the default basemap styles service vector tile layer styles. These are used to create and display a map or scene with your own custom styles, labels, and colors. To create a styled basemap layer, you can use the ArcGIS Vector Tile Style Editor. The editor stores your styles in ArcGIS as a layer item with an item ID.

In this tutorial, you will use an item ID to access and display a styled vector tile layer (Forest and Parks Canvas) in a map. You also add an image tile layer (World Hillshade) to enhance the visualization. Both layers are hosted in ArcGIS Online.

Note

To learn how to style your own basemap, visit Basemap layers and Styles and data visualization in the Mapping APIs and location services guide. To learn more about services, visit basemap styles service.

Prerequisites ArcGIS Accounts:

You need an ArcGIS Location Platform or ArcGIS Online account.

Steps Create a new pen
  1. To get started, either complete the Display a map tutorial or .
Get an access token

You need an access token with the correct privileges to access the location services used in this tutorial.

  1. Go to the Create an API key tutorial and create an API key with the following privilege(s):
  2. In CodePen, set esriConfig.apiKey to your access token.

    Use dark colors for code blocks

    1
    2
    3
    4
    5
    6
    7
    8
    9
      var esriConfig = {
        apiKey: "YOUR_ACCESS_TOKEN",
      };
    

To learn about other ways to get an access token, go to Types of authentication.

Add modules
  1. In a new <script> at the bottom of the <body>, add the Basemap, VectorTileLayer, and TileLayer modules.

    The ArcGIS Maps SDK for JavaScript is available via CDN and npm, but this tutorial is based on CDN. The $arcgis.import global function accepts a module path or array of module paths, and returns a promise that resolves with the requested modules. This function can only be used when working with the CDN; otherwise, use the standard import syntax. To learn more about the SDK's different modules, visit the References page.

    Expand

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
        <script type="module">
    
          const [Basemap, TileLayer, VectorTileLayer] = await $arcgis.import([
            "@arcgis/core/Basemap.js",
            "@arcgis/core/layers/TileLayer.js",
            "@arcgis/core/layers/VectorTileLayer.js",
          ]);
    
        </script>
    
Create a vector tile layer

You can access a basemap layer by referencing its item ID. You can find a layer's item ID by accessing it with ArcGIS Online or the ArcGIS Vector Tile Style Editor.

  1. Go to the Forest and Parks Canvas vector tile layer in ArcGIS Online and find its item ID. The ID is at the end of the URL.

  2. In CodePen, create a new VectorTileLayer object and set its portalItem id property to d2ff12395aeb45998c1b154e25d680e5 and the opacity property to 0.75.

    Learn more about loading a layer by its item ID in the API reference.

    Expand

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
          const vectorTileLayer = new VectorTileLayer({
            portalItem: {
              id: "6976148c11bd497d8624206f9ee03e30", // Forest and Parks Canvas
            },
            opacity: 0.75,
          });
    
    
Create an image tile layer

Use ArcGIS Online to find the item ID for the World Hillshade image tile layer and then use it to access the layer. The image tile layer will be used to visually enhance the styles with terrain.

  1. Go to the World Hillshade image tile layer in ArcGIS and find its item ID. The ID is at the end of the URL.

  2. In CodePen, create a new TileLayer and set its portalItem id property to 1b243539f4514b6ba35e7d995890db1d.

    Learn more about loading a layer by its item ID in the API reference.

Expand

Use dark colors for code blocks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
      const vectorTileLayer = new VectorTileLayer({
        portalItem: {
          id: "6976148c11bd497d8624206f9ee03e30", // Forest and Parks Canvas
        },
        opacity: 0.75,
      });

      const hillshadeTileLayer = new TileLayer({
        portalItem: {
          id: "1b243539f4514b6ba35e7d995890db1d", // World Hillshade
        },
      });

Add the basemap layers

Basemaps can contain multiple baseLayers. Use the Basemap class to add the vectorTileLayerand hillshadeTileLayer created above. These layers will create the underlying style for the map. The vector tile layer provides the base colors and the image tile layer provides the hillshade or topographic effect.

  1. In the main function, create a Basemap object and add vectorTileLayer and the hillshadeTileLayer to the baseLayers array.

    Expand

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
          const vectorTileLayer = new VectorTileLayer({
            portalItem: {
              id: "6976148c11bd497d8624206f9ee03e30", // Forest and Parks Canvas
            },
            opacity: 0.75,
          });
    
          const hillshadeTileLayer = new TileLayer({
            portalItem: {
              id: "1b243539f4514b6ba35e7d995890db1d", // World Hillshade
            },
          });
    
          const basemap = new Basemap({ baseLayers: [hillshadeTileLayer, vectorTileLayer] });
    
    
  2. Update the map's basemap property to use the basemap object created earlier.

    Expand

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
          const vectorTileLayer = new VectorTileLayer({
            portalItem: {
              id: "6976148c11bd497d8624206f9ee03e30", // Forest and Parks Canvas
            },
            opacity: 0.75,
          });
    
          const hillshadeTileLayer = new TileLayer({
            portalItem: {
              id: "1b243539f4514b6ba35e7d995890db1d", // World Hillshade
            },
          });
    
          const basemap = new Basemap({ baseLayers: [hillshadeTileLayer, vectorTileLayer] });
    
          const viewElement = document.querySelector("arcgis-map");
          viewElement.basemap = basemap;
    
    
Update the map position
  1. Update the center and zoom properties to zoom the display to North America.

    Expand

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
          const viewElement = document.querySelector("arcgis-map");
          viewElement.basemap = basemap;
    
          viewElement.center = [-100, 40];
          viewElement.zoom = 3;
    
Run the app

In CodePen, run your code to display the map.

The map should display the Forest and Parks Canvas vector tile layer on top of the World Hillshade image tile layer. The styled vector tile layer is displayed on top of the hillshade terrain.

What's next?

Learn how to use additional API features and ArcGIS services in these tutorials:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4