Introduction to visualization

You can style basemap layers, which are composed of vector tile data, and feature layers, which are composed of features, to help visualize the data in your application.

Basemap styles

A basemap style is a set of visual properties such as fill colors, viewing levels, and fonts that define how the visual elements in a vector tile basemap layer are displayed. There are two types of basemap styles: default and custom.

  • Default styles: Styles provided by Esri such as ArcGIS:Streets, ArcGIS:Topographic, and ArcGIS:Nova.
  • Custom styles: Styles you create and save as items using the ArcGIS Vector Tile Style Editor.

How to display a custom basemap style

  1. Create a style with the ArcGIS Vector Tile Style Editor.
  2. Go to the new basemap layer's item page and copy its item ID.
  3. Reference the OpenLayers CSS, JS, and ol-mapbox-style libraries.
  4. Set the item ID as the basemap style enumeration.
  5. Set the style URL.
  6. Load and apply the basemap style to a map using olms.

Example

Display a custom basemap layer

This example illustrates how you can set the item ID of a custom vector basemap layer in place of a default basemap layer style.

Use dark colors for code blocksCopy
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
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v10.1.0/ol.css" type="text/css" />
    <script src="https://cdn.jsdelivr.net/npm/ol@v10.1.0/dist/ol.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/ol-mapbox-style@12.3.5/dist/olms.js"></script>

    <script>

      const accessToken = "YOUR_ACCESS_TOKEN";

      const basemapId = "6976148c11bd497d8624206f9ee03e30"; // Custom vector tile style

      const basemapURL = `https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/items/${basemapId}?token=${accessToken}`;

      olms.apply(map, basemapURL).then(() => {

        // Add Esri attribution
        // Learn more in https://esriurl.com/attribution
        const source = map.getLayers().item(0).getSource();
        source.setAttributions(["Powered by <a href='https://www.esri.com/en-us/home' target='_blank'>Esri</a> | ", source.getAttributions()]);

      });

    </script>

Feature styles

You can style points, lines, and polygons for visualization in a map by defining symbols for features. To style features in a feature layer, you define symbols and apply them with a renderer. For data-driven visualization, the symbol is always determined based on a data (attribute) value returned from a field in the data layer.

To style features in OpenLayers, you use the Style class. A Style object allows you to define symbols using properties such as fill, stroke, text, and image. Once you create a style definition, reference it in your Vector layer to apply it to the features in the feature layer.

How to style a feature layer

  1. Import your data from a CSV, XLS, GeoJSON, or Shapefile file to create a hosted feature layer.
  2. Get the URL for the feature layer.
  3. Reference the OpenLayers CSS, JS, and ol-mapbox-style libraries.
  4. Instantiate a Style class and define symbols for the features you want to visualize.
  5. Reference the Style object and feature layer URL in a Vector layer.

Example

Style a feature layer (points)

This example customizes a map of trailhead locations so that they display as hiker symbols.

Use dark colors for code blocksCopy
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v10.1.0/ol.css" type="text/css" />
    <script src="https://cdn.jsdelivr.net/npm/ol@v10.1.0/dist/ol.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/ol-mapbox-style@12.3.5/dist/olms.js" type="text/javascript"></script>

    <script>

      olms.apply(map, basemapURL).then(function (map) {

        const trailheadStyle = function (feature) {
          return new ol.style.Style({
            image: new ol.style.Icon({
              src: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",
              scale: 0.25
            }),

          });
        };

        const trailheadsLayer = new ol.layer.Vector({
          source: new ol.source.Vector({
            format: new ol.format.GeoJSON(),
            url: trailheadsLayerURL,

            // Attribution text retrieved from https://arcgis.com/home/item.html?id=883cedb8c9fe4524b64d47666ed234a7
            attributions: ['| Los Angeles GeoHub']

          }),

          style: trailheadStyle,
          declutter: true
        });

        map.addLayer(trailheadsLayer);

        // Add Esri attribution
        // Learn more in https://esriurl.com/attribution
        const source = map.getLayers().item(0).getSource();
        source.setAttributions("Powered by <a href='https://www.esri.com/en-us/home' target='_blank'>Esri</a> | ")
      });
    </script>

Tutorials

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.