MediaLayer with control points

This sample demonstrates how to add two different static images to a MediaLayer in a 2D MapView by specifying their geographic locations using ControlPointsGeoreference.

A control point is composed of a sourcePoint, representing a point on the element measured in pixels from the top left corner, and a mapPoint, a known geographic location. This allows us to position the images in map space.

The first image is a historic geology map of Telluride Colorado downloaded from the USGS. The geology map is georeferenced with an array of four control points. The latitude and longitude (North American Datum 1927) are labeled on the corners of the map frame, facilitating defining control points.

The second image is a historic fire insurance map of downtown Denver Colorado downloaded from wikimedia.org. The historic Denver map was georeferenced with an array of four control points.

How it works

First, an array of control points is defined.

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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
          // four points representing known map coordinates on the MediaLayer's ImageElement
          const swCornerMapPoint = new Point({ x: -107.875, y: 37.875, spatialReference });
          const nwCornerMapPoint = new Point({ x: -107.875, y: 38, spatialReference });
          const neCornerMapPoint = new Point({ x: -107.75, y: 38, spatialReference });
          const seCornerMapPoint = new Point({ x: -107.75, y: 37.875, spatialReference });

          // create a GraphicsLayer to show the four points on the Map
          const graphicsLayer = new GraphicsLayer({
            graphics: [
              createGraphic(swCornerMapPoint, "green", 0),
              createGraphic(nwCornerMapPoint, "purple", 1),
              createGraphic(neCornerMapPoint, "blue", 2),
              createGraphic(seCornerMapPoint, "red", 3)
            ]
          });

          // create an array of four control points composed of a sourcePoint, a point
          // on the image element in pixels, and a mapPoint which is the location of the
          // sourcePoint in map space
          const swCornerControlPoint = {
            sourcePoint: { x: 89, y: 1918 },
            mapPoint: swCornerMapPoint
          };

          const nwCornerControlPoint = {
            sourcePoint: { x: 83, y: 101 },
            mapPoint: nwCornerMapPoint
          };

          const neCornerControlPoint = {
            sourcePoint: { x: 1508, y: 97 },
            mapPoint: neCornerMapPoint
          };

          const seCornerControlPoint = {
            sourcePoint: { x: 1517, y: 1906 },
            mapPoint: seCornerMapPoint
          };

          const controlPoints = [
            swCornerControlPoint,
            nwCornerControlPoint,
            neCornerControlPoint,
            seCornerControlPoint
          ];

Then, the MediaLayer is initialized with the ImageElement and ControlPointsGeoreference as shown below:

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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
          // georeference for the imageElement using the control points,
          // image width, and image height
          const controlPointsGeoreference = new ControlPointsGeoreference({ controlPoints, width: 1585, height: 2048 });

          const imageElement = new ImageElement({
            image:
              "https://arcgis.github.io/arcgis-samples-javascript/sample-data/media-layer/telluride/TellurideQuad.webp",
            georeference: controlPointsGeoreference
          });

          const mediaLayer = new MediaLayer({
            source: [imageElement],
            title: "Geologic Map of the Telluride Quadrangle, Southwestern Colorado",
            copyright: "Wilbur S Burbank and Robert G. Luedke, 1966",
            spatialReference
          });

Using the SketchViewModel and setting updateOnGraphicClick to true allows the user to move the control points on the map.

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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
          // use the SketchViewModel to allow updating the graphics and control points
          sketch.layer = graphicsLayer;

          sketch.on("update", (event) => {
            if (event.toolEventInfo?.type === "move-start") {
              imageElement.opacity = 0.3;
            }
            if (event.toolEventInfo?.type === "move-stop") {
              imageElement.opacity = 0.9;
            }

            const points = graphicsLayer.graphics
              .toArray()
              .sort((a, b) => a.attributes.index - b.attributes.index)
              .map((graphic) => graphic.geometry);

            controlPointsGeoreference.controlPoints = points.map((mapPoint, index) => ({
              sourcePoint: controlPointsGeoreference.controlPoints[index].sourcePoint,
              mapPoint
            }));
          });

Switching between the locations of the two different MediaLayers is easy using the Bookmarks widget. The sample uses the bookmark-select event listener to add the appropriate MediaLayer to the map after removing the initial MediaLayer.

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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
        // when a bookmark is selected add the appropriate MediaLayer
        bookmarks.on("bookmark-select", (event) => {
          if (event.bookmark.name === "Telluride Geology") {
            map.removeAll();
            addTellurideGeologyMediaLayer();
          }

          if (event.bookmark.name === "Sanborn Fire Insurance Map from Denver (1887)") {
            map.removeAll();
            addDenverInsuranceMediaLayer();
          }
        });

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