Construct a mapping app with web components

Learn how to construct a UI for a mapping application with web components using Calcite Components and ArcGIS Maps SDK for JavaScript's Map components.

You will use Calcite Components to enhance the user experience and drive interaction in your mapping application. This tutorial focuses on the user interface and Map components to streamline app creation, and does not require prior knowledge of the ArcGIS Maps SDK for JavaScript. If you are new to the ArcGIS Maps SDK for JavaScript, you can also explore this great tutorial that covers similar mapping concepts used in this application.

Prerequisites

ArcGIS developer account
You need a free ArcGIS developer account or an account associated with an ArcGIS Online organization to access the services used in this tutorial.

Steps

Create a new pen

  1. Navigate to CodePen to create a new pen for your mapping application.

Add HTML

  1. In CodePen > HTML, add HTML and CSS to create a page with an arcgis-map component, which will display the map.

  2. Add an id to the arcgis-map component to reference throughout app development, add CSS to set it's width and height to the browser's window, and Flexbox to supplement further app styling.

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
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>Calcite Components: Construct a mapping app with web components</title>
  </head>
  <style>
    html,
    body,
    #mapEl {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
      display: flex;
    }
  </style>
  <body>
    <arcgis-map id="mapEl"></arcgis-map>
  </body>
  <script>
  </script>
</html>
  1. In the <head> element, add references to Calcite Components and ArcGIS Maps SDK for JavaScript.
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
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

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
  <title>Calcite Components: Create a mapping app with web components</title>

  <script src="https://js.arcgis.com/calcite-components/2.13.0/calcite.esm.js" type="module"></script>
  <link rel="stylesheet" href="https://js.arcgis.com/calcite-components/2.13.0/calcite.css" />
  <script src="https://js.arcgis.com/4.30/"></script>
  <link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" />

</head>
Expand
  1. Next, add the reference to the ArcGIS Maps SDK for JavaScript Map components.
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
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

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
  <title>Calcite Components: Create a mapping app with web components</title>

  <script src="https://js.arcgis.com/calcite-components/2.13.0/calcite.esm.js" type="module"></script>
  <link rel="stylesheet" href="https://js.arcgis.com/calcite-components/2.13.0/calcite.css" />
  <script src="https://js.arcgis.com/4.30/"></script>
  <link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" />

  <script type="module" src="https://js.arcgis.com/map-components/4.30/arcgis-map-components.esm.js"></script>

</head>
Expand

Use an API key

An API key is required to access ArcGIS services if you are using a developer account. You can skip this step if you have an account associated with an ArcGIS Online organization.

  1. Go to your developer dashboard to get an API key.
  2. Back in CodePen > <script>, import the esriConfig class.
  3. Set the apiKey property.
Use dark colors for code blocks
1
2
3
4
5
6
<script>
  require(["esri/config"],
    function (esriConfig) {
      esriConfig.apiKey = "YOUR_API_KEY";
  });
</script>

Display a map

The map is the central focus of this application. You added CSS above which makes the map the full width and height of the window. You will also add ArcGIS Maps SDK for JavaScript Map components that interact with the map.

  1. In the <body>, you will initialize the arcgis-map component using the item-id attribute, which specifies the webmap's item ID.
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
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
    <arcgis-map id="mapEl" item-id="03d584a7c9874b44821c6a766c3bbc11">

    </arcgis-map>
Expand
  1. Next, add an arcgis-zoom component and set its position with respect to the arcgis-map component.
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
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
    <arcgis-map id="mapEl" item-id="03d584a7c9874b44821c6a766c3bbc11">

      <arcgis-zoom position="top-left"></arcgis-zoom>

    </arcgis-map>
Expand

At this point the application will display a map. Next, you'll use Calcite Components to build the app's user interface.

Create the layout

To create the layout you will use calcite-shell, which organizes other components on the page using slots. Slots are a web component concept and there is a brief section in Core concepts. A list of Calcite Components slots, if it has any, can be found on its reference page. For example, here are shell's slots.

  1. Add the calcite-shell component, and set the content-behind attribute so users can interact with the map behind the shell.
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
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
  <calcite-shell content-behind>

    <arcgis-map id="mapEl" item-id="03d584a7c9874b44821c6a766c3bbc11">

      <arcgis-zoom position="top-left"></arcgis-zoom>

    </arcgis-map>

  </calcite-shell>

Expand
  1. Next, add the calcite-shell-panel component, placing it in shell's "panel-end" slot.

  2. Then, set the shell panel's displayMode attribute to "float" so it's content appears to hover over the map.

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
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
  <calcite-shell content-behind>

    <calcite-shell-panel id="shell-panel-nav" slot="panel-end" display-mode="float" height-scale="l">

    </calcite-shell-panel>

    <arcgis-map id="mapEl" item-id="03d584a7c9874b44821c6a766c3bbc11">

      <arcgis-zoom position="top-left"></arcgis-zoom>

    </arcgis-map>

  </calcite-shell>

Expand
  1. Add a calcite-panel component. Supply an id to dynamically populate the heading with the title of the web map, and add the hidden attribute to hide the component on initialization.

  2. Then, slot a calcite-icon into panel's "header-actions-start" slot.

  3. Next, slot calcite-action-bar into panel's "action-bar" slot, where you can add calcite-actions to display Map components.

  4. For each action, add a unique data-action-id value.

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
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
    <calcite-shell-panel id="shell-panel-nav" slot="panel-end" display-mode="float" height-scale="l">

      <calcite-panel id="app-heading" hidden>
        <calcite-icon id="logo-icon" slot="header-actions-start" icon="explore" text-label="explore"></calcite-icon>
        <calcite-action-bar id="map-actions" slot="action-bar" layout="horizontal" expand-disabled>
          <calcite-action icon="layers" text="Layers" data-action-id="layers"></calcite-action>
          <calcite-action icon="basemap" text="Basemaps" data-action-id="basemaps"></calcite-action>
          <calcite-action icon="legend" text="Legend" data-action-id="legend"></calcite-action>
          <calcite-action icon="bookmark" text="Bookmarks" data-action-id="bookmarks"></calcite-action>
          <calcite-action icon="print" text="Print" data-action-id="print"></calcite-action>
          <calcite-action icon="information" text="About" data-action-id="information"></calcite-action>
        </calcite-action-bar>
      </calcite-panel>

    </calcite-shell-panel>
Expand

Add Map components

To build on your layout, you will add Map components that display when a user interacts with a calcite-action.

  1. First, add a calcite-block component.

    • Add the open attribute to display its contents
    • Supply a unique heading
    • Provide the value from the corresponding data-action-id to the block's data-block-id attribute
    • Add the hidden attribute so the component and its contents are not displayed when the app is initialized
  2. In the calcite-block, slot the arcgis-layer-list Map component.

    • Set the reference-element to the map component's id
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
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
    <calcite-shell-panel id="shell-panel-nav" slot="panel-end" display-mode="float" height-scale="l">

      <calcite-panel id="app-heading" hidden>
        <calcite-icon id="logo-icon" slot="header-actions-start" icon="explore" text-label="explore"></calcite-icon>
        <calcite-action-bar id="map-actions" slot="action-bar" layout="horizontal" expand-disabled>
          <calcite-action icon="layers" text="Layers" data-action-id="layers"></calcite-action>
          <calcite-action icon="basemap" text="Basemaps" data-action-id="basemaps"></calcite-action>
          <calcite-action icon="legend" text="Legend" data-action-id="legend"></calcite-action>
          <calcite-action icon="bookmark" text="Bookmarks" data-action-id="bookmarks"></calcite-action>
          <calcite-action icon="print" text="Print" data-action-id="print"></calcite-action>
          <calcite-action icon="information" text="About" data-action-id="information"></calcite-action>
        </calcite-action-bar>
      </calcite-panel>

      <!-- Map-specific blocks containing ArcGIS Maps SDK for JavaScript components -->
      <calcite-block open heading="Layers" data-block-id="layers" hidden>
        <arcgis-layer-list drag-enabled reference-element="mapEl" visibility-appearance="checkbox"></arcgis-layer-list>
      </calcite-block>

    </calcite-shell-panel>
Expand
  1. Repeat steps 1 and 2 to add calcite-block components to contain the arcgis-basemap-gallery, arcgis-legend, arcgis-bookmarks, and arcgis-print components.
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
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
      <!-- Map-specific blocks containing ArcGIS Maps SDK for JavaScript components -->
      <calcite-block open heading="Layers" data-block-id="layers" hidden>
        <arcgis-layer-list drag-enabled reference-element="mapEl" visibility-appearance="checkbox"></arcgis-layer-list>
      </calcite-block>

      <calcite-block open heading="Basemaps" data-block-id="basemaps" hidden>
        <arcgis-basemap-gallery reference-element="mapEl"></arcgis-basemap-gallery>
      </calcite-block>
      <calcite-block open heading="Legend" data-block-id="legend" hidden>
        <arcgis-legend legend-style="classic" reference-element="mapEl"></arcgis-legend>
      </calcite-block>
      <calcite-block open heading="Bookmarks" data-block-id="bookmarks" hidden>
        <arcgis-bookmarks editing-enabled="false" reference-element="mapEl"></arcgis-bookmarks>
      </calcite-block>
      <calcite-block open heading="Print" data-block-id="print" hidden>
        <arcgis-print allowed-formats="all" allowed-layouts="all" include-default-templates="false"
          reference-element="mapEl"></arcgis-print>
      </calcite-block>
Expand

Create an information card

An information card can provide users with information about the app's data. You will use calcite-card to display the webmap's information, where the card will dynamically populate and organize the title, thumbnail image, description, last modified date, and tags.

  1. Similar to the other Map components, add a calcite-block component.

    • Add the open attribute to display its contents
    • Supply a unique heading
    • Provide the value from the corresponding data-action-id to the block's data-block-id attribute
    • Add the closed attribute so the component and its contents are not displayed when the app is initialized
  2. Add the calcite-card component.

  3. Add the following child elements to the card, with unique id's:

    • Define an img in the card's "thumbnail" slot
    • Add three div elements, one in the "heading" slot, another in the "description" slot, and finally one in the "footer-end" slot
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
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
      <!-- Info block (populates with info from the web map) -->
      <calcite-block open heading="About the data" data-block-id="information" hidden>
        <calcite-card id="card-content">
          <img id="card-thumbnail" alt="Webmap thumbnail" slot="thumbnail" />
          <div id="card-heading" slot="heading">
            <!-- Dynamically populated -->
          </div>
          <div id="card-description" slot="description">
            <!-- Dynamically populated -->
          </div>
          <div id="card-tags" slot="footer-end">
            <!-- Dynamically populated -->
          </div>
        </calcite-card>
      </calcite-block>
Expand

Populate the content

You finished adding components to your application! Now populate the panel's heading and information card with content from the web map.

  1. Declare the arcgis-map component in the <script> tag.
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
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
<script>

  const mapEl = document.getElementById("mapEl");

</script>
Expand
  1. On the map's arcgisViewReadyChange event, declare constants for the following portalItem's to populate contents from the web map: title, thumbnailUrl, snippet, modified, and tags.

  2. Next, add the values to the UI, where:

    • title will supply the panel's heading and card's "heading" slot
    • thumbnailUrl adds the card's img's src property to the "thumbnail" slot
    • snippet and modified supplement card's "description" slot
    • tags will iterate through each tag to create individual calcite-chip components in card's "footer-end" slot
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
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
  mapEl.addEventListener("arcgisViewReadyChange", () => {
    const { title, thumbnailUrl, snippet, modified, tags } = mapEl.map.portalItem;
    document.getElementById("app-heading").heading = `${title} Explorer`;
    document.getElementById("card-heading").innerHTML = title;
    document.getElementById("card-thumbnail").src = thumbnailUrl;
    document.getElementById("card-description").innerHTML = `<p>${snippet}</p><p>Last modified on ${modified}.</p>`;
    tags.forEach(tag => {
      document.getElementById("card-tags").innerHTML += `<calcite-chip>${tag}</calcite-chip>`;
    });

  });
Expand

Make components interactive

The next step is to display the calcite-block components, which contain the Map components, when clicking on the corresponding calcite-action components.

  1. Create a function that will execute when each calcite-action is clicked. The function will hide the active calcite-block and display the block corresponding to the clicked action. If the user clicks on the active action, the corresponding block will close and there will not be any open blocks.
  1. Create a click event listener on the calcite-action-bar using the function above as the callback.
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
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
  let activeWidget;
  const handleActionBarClick = ({ target }) => {
    if (target.tagName !== "CALCITE-ACTION") {
      return;
    }
    if (activeWidget) {
      document.querySelector(`[data-action-id=${activeWidget}]`).active = false;
      document.querySelector(`[data-block-id=${activeWidget}]`).hidden = true;
    }
    const nextWidget = target.dataset.actionId;
    if (nextWidget !== activeWidget) {
      document.querySelector(`[data-action-id=${nextWidget}]`).active = true;
      document.querySelector(`[data-block-id=${nextWidget}]`).hidden = false;
      activeWidget = nextWidget;
    } else {
      activeWidget = null;
    }
  };
  document.querySelector("calcite-action-bar").addEventListener("click", handleActionBarClick);
Expand

Add a loader component

Now everything is interactive in your application! You can open and close Map components using Calcite Components. However, the application takes a second to load, which should be communicated to the user.

  1. In the <body> element after the shell's closing tag, add a calcite-loader to display the component.
Use dark colors for code blocks
1
2
</calcite-shell>
<calcite-loader></calcite-loader>
  1. Inside of the arcgisViewReadyChange event, below the rest of the JavaScript code, hide the calcite-loader component with the hidden property set to true and display the calcite-panel. When the map and its properties have loaded into the app, the loader will be hidden and the panel will display in the UI.
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
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
  mapEl.addEventListener("arcgisViewReadyChange", () => {
    const { title, thumbnailUrl, snippet, modified, tags } = mapEl.map.portalItem;
    document.getElementById("app-heading").heading = `${title} Explorer`;
    document.getElementById("card-heading").innerHTML = title;
    document.getElementById("card-thumbnail").src = thumbnailUrl;
    document.getElementById("card-description").innerHTML = `<p>${snippet}</p><p>Last modified on ${modified}.</p>`;
    tags.forEach(tag => {
      document.getElementById("card-tags").innerHTML += `<calcite-chip>${tag}</calcite-chip>`;
    });

    document.querySelector("calcite-loader").hidden = true;
    document.getElementById("app-heading").removeAttribute("hidden");

  });
Expand

Add styling

In the <style> element, add some additional CSS to enhance the user interface for your heading calcite-panel and information calcite-card.

  1. Add Flexbox variables to the calcite-icon slotted into the panel's "header-actions-start" to align the component.

  2. Next, add styles for the panel to set the width and heights for:

    • calcite-shell-panel via the --calcite-shell-panel-min-width style
    • A media query for calcite-shell-panel to support smaller devices, such as mobile phones
    • calcite-block components containing a data-block-id attribute with max-height
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
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
  #logo-icon {
    align-self: center;
    height: auto;
    margin-inline-start: 0.5rem;
  }

  #shell-panel-nav {
    --calcite-shell-panel-min-width: 18rem;
  }

  @media (max-width: 400px) {
    #shell-panel-nav {
      --calcite-shell-panel-min-width: 80vw;
    }
  }

  calcite-block[data-block-id] {
    max-height: 50vh;
    overflow-y: auto;
  }

Expand
  1. Finally, add styles to calcite-card by adding padding to the component, updating the font-size using CSS variables, and wrapping the tags with flex-wrap.
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
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
  #card-heading {
    font-size: var(--calcite-font-size-md);
  }

  #card-description {
    font-size: var(--calcite-font-size);
  }

  #card-tags {
    flex-wrap: wrap;
  }

Expand

Run the app

In CodePen, run your code to display the application.

The map will display once the application finishes loading, along with the web map's title and a calcite-action-bar. Clicking on the calcite-action components will open and close the calcite-block components, which contain the ArcGIS Maps SDK for JavaScript Map components.

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