-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
323 lines (283 loc) · 10.8 KB
/
index.html
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
<html>
<head>
<meta charset="utf-8"/>
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Then (1950) and Now</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.24/esri/themes/dark/main.css"
/>
<script src="https://js.arcgis.com/4.24/"></script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#overviewDiv {
position: absolute;
top: 0;
right: 0;
width: 240px;
height: 240px;
z-index: 1;
overflow: hidden;
}
#extentDiv {
background-color: rgba(0, 0, 0, 0.5);
position: absolute;
z-index: 2;
}
#aboutDiv {
padding: 12px;
background-color: #303030;;
color: #d1d1d1;
width: 390px;
}
a:visited {
color: #d1d1d1;
}
.esri-bookmarks {
max-height: 300px !important;
}
.button {
height: 5px;
width: 20px;
border-radius: 2px;
border: #d1d1d1a3 solid 1px;
padding: 3px;
font-size: .8em;
}
@media (max-width: 768px) {
#overviewDiv {
display: none;
}
}
</style>
<script>
require([
"esri/Map",
"esri/WebMap",
"esri/Basemap",
"esri/views/MapView",
"esri/widgets/Bookmarks",
"esri/layers/MapImageLayer",
"esri/layers/WebTileLayer",
"esri/layers/VectorTileLayer",
"esri/widgets/LayerList",
"esri/widgets/Swipe",
"esri/widgets/Home",
"esri/Graphic",
"esri/widgets/Expand",
"esri/core/reactiveUtils",
"esri/core/promiseUtils"
], (Map, WebMap, Basemap, MapView, Bookmarks, MapImageLayer, WebTileLayer, VectorTileLayer, LayerList, Swipe, Home, Graphic, Expand, reactiveUtils, promiseUtils) => {
const webmap = new WebMap({
portalItem: {
// autocasts as new PortalItem()
id: "c47b63898ef5458b855a29014c2989e0"
}
});
const view = new MapView({
container: "viewDiv",
map: webmap,
constraints: {
rotationEnabled: false,
maxZoom: 20
},
zoom: 16,
center: [-83.04799999999994, 42.33168000000006], // longitude, latitude
});
// WIDGETS
// add the swipe widget
view.when(function () {
const then = webmap.layers.getItemAt(0);
then.listMode = 'hide-children'
const office = webmap.layers.getItemAt(1);
office.listMode = 'hide'
// create a new Swipe widget
const swipe = new Swipe({
leadingLayers: [then],
position: 75, // set position of widget to 35%
view: view
});
// add the widget to the view
view.ui.add(swipe);
})
const homeBtn = new Home({
view: view
});
//reset the text in the top left to the default when the home button is clicked
homeBtn.on('go', function () {
current_bookmark.innerText = "Detroit - Downtown"
})
// Add the home button to the top left corner of the view
view.ui.add(homeBtn, "bottom-right");
//move the zoom widget to the bottom right
view.ui.move(["zoom"], "bottom-right");
const bookmarks = new Bookmarks({
view: view,
// allows bookmarks to be added, edited, or deleted
editingEnabled: false,
});
let bookmarkExpand = new Expand({
expandIconClass: "esri-icon-bookmark", // see https://developers.arcgis.com/javascript/latest/guide/esri-icon-font/
view: view,
content: bookmarks
});
view.ui.add(bookmarks, "bottom-left");
bookmarks.on("bookmark-select", function (event) {
console.log(event.bookmark.name)
let current_bookmark = document.getElementById('current_bookmark');
current_bookmark.innerText = event.bookmark.name
});
// create a layerlist and expand widget and add to the view
const layerList = new LayerList({
view: view
});
view.ui.add(layerList, "bottom-right");
view.ui.add('aboutDiv', "top-left");
let aboutSection = new Expand({
expandIconClass: "esri-icon-question", // see https://developers.arcgis.com/javascript/latest/guide/esri-icon-font/
expandTooltip: "About", // optional, defaults to "Expand" for English locale
view: view,
expanded: true,
content: document.getElementById('aboutDiv')
});
const insetwebmap = new WebMap({
portalItem: {
// autocasts as new PortalItem()
id: "d922195dc4a142f49ad1de81584aee84"
}
});
const insetView = new MapView({
container: "overviewDiv",
map: insetwebmap,
constraints: {
rotationEnabled: false
}
});
// Remove the default widgets and make sure the user cannot interact with the inset map
insetView.ui.components = [];
insetView.when(disableZooming)
function disableZooming(view) {
// stops propagation of default behavior when an event fires
function stopEvtPropagation(event) {
event.stopPropagation();
}
// exlude the zoom widget from the default UI
// disable mouse wheel scroll zooming on the view
view.on("mouse-wheel", stopEvtPropagation);
// disable zooming via double-click on the view
view.on("double-click", stopEvtPropagation);
// disable zooming out via double-click + Control on the view
view.on("double-click", ["Control"], stopEvtPropagation);
// disables pinch-zoom and panning on the view
view.on("drag", stopEvtPropagation);
// disable the view's zoom box to prevent the Shift + drag
// and Shift + Control + drag zoom gestures.
view.on("drag", ["Shift"], stopEvtPropagation);
view.on("drag", ["Shift", "Control"], stopEvtPropagation);
// prevents zooming with the + and - keys
view.on("key-down", (event) => {
const prohibitedKeys = [
"+",
"-",
"Shift",
"_",
"=",
"ArrowUp",
"ArrowDown",
"ArrowRight",
"ArrowLeft"
];
const keyPressed = event.key;
if (prohibitedKeys.indexOf(keyPressed) !== -1) {
event.stopPropagation();
}
});
return view;
}
insetView.when(() => {
view.when(() => {
setup();// add the extent box to the inset map
});
});
const extentDebouncer = promiseUtils.debounce(() => {
insetView.goTo({
center: view.center,
scale:
view.scale *
3 *
Math.max(
view.width / insetView.width,
view.height / insetView.height
)
});
});
function setup() {
const extent3Dgraphic = new Graphic({
geometry: null,
symbol: {
type: "simple-fill",
color: [0, 0, 0, 0.5],
outline: null
}
});
insetView.graphics.add(extent3Dgraphic);
reactiveUtils.watch(
() => view.extent,
(extent) => {
// Sync the overview map location
// whenever the 3d view is stationary
extentDebouncer().then(() => {
extent3Dgraphic.geometry = extent;
});
},
{
initial: true
}
);
}
// check screen size to adjust widgets to fit better
let all_components = view.ui.components
view.watch("width", () => {
if (view.width <= 768) {
// it's a small screen
view.ui.components = ['attribution']
view.ui.add(layerList, "top-right");
view.ui.add(bookmarks, "bottom-left");
view.ui.remove('aboutDiv', "top-left");
view.ui.remove(bookmarks, "bottom-left");
view.ui.add(aboutSection, "top-left");
view.ui.add(bookmarkExpand, "bottom-left");
} else {
//it's a big screen
view.ui.components = all_components
view.ui.move(["zoom"], "bottom-right");
view.ui.move(layerList, "bottom-right");
}
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="overviewDiv">
<div id="extentDiv"></div>
</div>
<div id="aboutDiv" class="esri-widget">
<img src="logo.svg" alt="logo" style="height: 15px">
<a style='float: right; color: #d1d1d1a3;' href="javascript:window.location.reload(true)"><span class="esri-widget button">Reset</span></a>
<h2 style="text-align: center">Then and Now</h2>
<p style="font-size: .95em">Get lost in 1950 and see what a few places around Southeast Michigan looked like Then and Now.</p>
<h3 style="text-align: center" id="current_bookmark">Detroit - Downtown</h3>
</div>
</body>
</html>