forked from aitorcalero/SpainCovid19Map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
243 lines (206 loc) · 7.05 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Mapa de Casos de Covid-19 por provincias en España</title>
<style>
html,
body,
#mainViewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#canariasViewDiv {
padding: 0;
margin: 0;
height: 150px;
width: 250px;
background-color: rgba(255, 255, 255, 0.9);
}
.esri-view-width-xlarge .esri-popup__main-container {
width: 400px !important;
}
</style>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.14/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.14/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/widgets/Legend",
"esri/widgets/Expand",
], function(Map, MapView, FeatureLayer, Legend, Expand) {
var layer = new FeatureLayer({
portalItem: {
id: "6a9fa0b2ff3443fea12c6d8963c61562"
},
outFields: ["*"],
title: "Mapa de incidencia de Covid-19 por Provincias"
});
var map = new Map({
layers: [layer]
});
var mainView = new MapView({
container: "mainViewDiv",
map: map,
popup: {
highlightEnabled: false,
dockEnabled: true,
dockOptions: {
breakpoint: false,
position: "top-right"
}
},
extent: {
xmin: -2067672.4238408396,
ymin: 3802581.7988451226,
xmax: 1689360.390431145,
ymax: 5646854.417309365,
spatialReference: {
wkid: 102100
}
},
ui: {
components: ["attribution"]
}
});
var legend = new Legend({
view: mainView
});
var expand = new Expand({
view: mainView,
content: legend
});
mainView.ui.add(expand, "top-left");
var canariasView = new MapView({
container: "canariasViewDiv",
map: map,
extent: {
xmin: -2096603.2272799485,
ymin: 3117560.43839324,
xmax: -1423957.3783704308,
ymax: 3431869.4987018686,
spatialReference: {
wkid: 102100
}
},
ui: {
components: []
}
});
mainView.ui.add("canariasViewDiv", "bottom-left");
mainView
.when(maintainFixedExtent)
.then(disableNavigation)
.then(disablePopupOnClick)
.then(enableHighlightOnPointerMove);
canariasView
.when(disableNavigation)
.then(disablePopupOnClick)
.then(enableHighlightOnPointerMove);
function maintainFixedExtent(view) {
var fixedExtent = view.extent.clone();
// keep a fixed extent in the view
// when the view size changes
view.on("resize", function() {
view.extent = fixedExtent;
});
return view;
};
var highlight = null;
function enableHighlightOnPointerMove(view) {
view.whenLayerView(layer).then(function(layerView) {
view.on("pointer-move", function(event) {
view.hitTest(event).then(function(response) {
const lastHighlight = highlight;
// if a feature is returned, highlight it
// and display its attributes in the popup
// if no features are returned, then close the popup
var id = null;
if (response.results.length) {
var feature = response.results.filter(function(result) {
return result.graphic.layer === layer;
})[0].graphic;
feature.popupTemplate = layer.popupTemplate;
id = feature.attributes.OBJECTID_1;
highlight = layerView.highlight([id]);
var selectionId = mainView.popup.selectedFeature
? mainView.popup.selectedFeature.attributes.OBJECTID
: null;
if (highlight && id !== selectionId) {
mainView.popup.open({
features: [feature]
});
}
} else {
if (mainView.popup.visible) {
mainView.popup.close();
mainView.popup.clear();
}
}
// remove the previous highlight
if (lastHighlight) {
lastHighlight.remove();
lastHighlight = null;
}
});
});
});
}
// disables all navigation in the view
function disableNavigation(view) {
view.popup.dockEnabled = true;
// Removes the zoom action on the popup
view.popup.actions = [];
// stops propagation of default behavior when an event fires
function stopEvtPropagation(event) {
event.stopPropagation();
}
// disable mouse wheel scroll zooming on the view
view.navigation.mouseWheelZoomEnabled = false;
// 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.navigation.browserTouchPanEnabled = false;
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 and rotation with the indicated keys
view.on("key-down", function(event) {
var prohibitedKeys = ["+", "-", "_", "=", "a", "d"];
var keyPressed = event.key.toLowerCase();
if (prohibitedKeys.indexOf(keyPressed) !== -1) {
event.stopPropagation();
}
});
return view;
}
// prevents the user from opening the popup with click
function disablePopupOnClick(view) {
view.on("click", function(event) {
event.stopPropagation();
});
return view;
}
});
</script>
</head>
<body>
<div id="mainViewDiv"></div>
<div id="canariasViewDiv" class="esri-widget"></div>
</body>
</html>