MediaLayer with images

This sample demonstrates how to use a MediaLayer in a 2D Map to display static images. The MediaLayer allows you to position images on the map by defining their geographic locations and configuring their extent and rotation.

How it works

A state object is initialized with an empty array to store image elements and a new MediaLayer instance

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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
      const state = {
        imageElements: [],
        mediaLayer: new MediaLayer({
          title: "New Orleans",
        }),
      };

The sample features old topographic maps of New Orleans from the 1890s. Details about each map, such as its name, title, and geographic extent, are stored in an imageInfos array. Image elements are dynamically created and added to the state by iterating over this array and invoking the createImageElement function on each image.

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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
      // A function to create an image element.
      // The function takes the name of the image and its bounding box coordinates as parameters.
      // It returns a new ImageElement instance with the specified image and georeference.
      function createImageElement(name, extent) {
        const imageElement = new ImageElement({
          image: `https://arcgis.github.io/arcgis-samples-javascript/sample-data/media-layer/new-orleans/${name}.png`,
          georeference: new ExtentAndRotationGeoreference({
            extent: new Extent({
              spatialReference: {
                wkid: 102100,
              },
              xmin: extent.xmin,
              ymin: extent.ymin,
              xmax: extent.xmax,
              ymax: extent.ymax,
            }),
          }),
        });
        return imageElement;
      }

A Calcite List is created with a list item for each image element, allowing users to select and adjust the opacity of individual image elements.

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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
      // A function to create a list item for each image.
      // The function takes the image information and index as parameters.
      // It creates a list item with a label and a slider for adjusting the opacity of the image.
      function createListItem(imageInfo, index) {
        const listItem = document.createElement("calcite-list-item");
        listItem.label = imageInfo.title;
        listItem.dataset.imageName = imageInfo.name;
        listItem.selected = true;

        const sliderDiv = document.createElement("div");
        sliderDiv.slot = "content-bottom";

        const sliderLabel = document.createElement("calcite-label");
        sliderLabel.layout = "inline";
        sliderLabel.innerText = "Opacity";

        const slider = document.createElement("calcite-slider");
        slider.value = 100;
        slider.addEventListener("calciteSliderInput", (event) => {
          const value = Number(event.target.value ?? 0);
          state.imageElements[index].opacity = value / 100;
        });

        sliderLabel.appendChild(slider);
        sliderDiv.appendChild(sliderLabel);
        listItem.appendChild(sliderDiv);
        list?.appendChild(listItem);
      }

Users can add or remove image elements from the MediaLayer's source by selecting or deselecting items in the list.

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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
      // A function to update the layer source with the selected images.
      // The function retrieves the selected items from the list and updates the source of the media layer
      // with the corresponding image elements from the imageElements array.
      async function updateLayer() {
        // Create a Set of selected image names for faster lookup
        const selectedImageNames = new Set(
          list.selectedItems.map((item) => item.dataset.imageName),
        );

        const source = state.mediaLayer.source;
        source.elements.removeAll();

        // Filter and add matching image elements to the source
        state.imageElements.forEach((element) => {
          const imageName = element.image?.split("/").pop().replace(".png", "");
          if (selectedImageNames.has(imageName)) {
            source.elements.push(element);
          }
        });
      }

The luminosity blend mode can be applied with a calcite switch at the bottom of the list

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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
      // Change the blend mode of the media layer when the switch is toggled.
      document.querySelector("#luminosity-switch")?.addEventListener("calciteSwitchChange", () => {
        state.mediaLayer.blendMode =
          state.mediaLayer.blendMode === "normal" ? "luminosity" : "normal";
      });

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