forked from Falke-Design/LeafletSlider
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommented.html
247 lines (220 loc) · 7.56 KB
/
commented.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
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Time Slider Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.6.0/leaflet.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.6.0/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<!-- Include this library for mobile touch support -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
<!-- Include SliderControl.js script -->
<script src="src/SliderControl.js"></script>
<!-- Style map -->
<style>
#myMap {
width: 80%;
height: 600px;
postion: relative;
margin: auto;
}
</style>
</head>
<body>
<!-- Add div to contain #myMap -->
<div id="myMap"></div>
<script>
// Create geoJSON dataset (if linking mulitple markers together to appear/hide at once, all those linked go into one dataset)
var dataset1 = [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-122.3, 47.6]
},
properties: {
title: 'Popup 1',
description: 'Hello World!',
time: '1992/01'
}
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-122.3, 47.58]
},
properties: {
title: 'Popup 2',
description: 'Hello again, World!',
time: '1992/06'
}
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-122.32, 47.59]
},
properties: {
title: 'Popup 3',
description: 'Hello once again, World!',
time: '1992/07'
}
}
]
// If desired, create additional datasets of linked markers
var dataset2 = [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-122.34, 47.62]
},
properties: {
title: 'Popup 4',
description: 'Hello World, once more!',
time: '1993/05'
}
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-122.33, 47.61]
},
properties: {
title: 'Popup 5',
description: 'Hello World, tired yet?!',
time: '1993/08'
}
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-122.33, 47.58]
},
properties: {
title: 'Popup 6',
description: 'Last time: Hello World!',
time: '1993/06'
}
}
]
// Create map inside div with #myMap ID; set view
var map1 = L.map('myMap').setView([47.6,-122.32], 13);
// Add tileLayer to map
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map1);
//Create an empty geoJSON layer
var group1 = L.geoJSON();
/*
// If creating groups of linked markers, remove geoJSON layer above and create an empty layerGroup for each set, below
var group1 = L.layerGroup();
var group2 = L.layerGroup();
*/
// Specify function that will load markers, set icons, bind popups with geoJSON content into the specified layer
function addToGroup1 (feature, layer) {
group1.addLayer(layer);
var content = "<div style='clear: both'></div><div><h4>" + feature.properties.title + "</h4><p>" + feature.properties.time + "</p><p>" + feature.properties.description + "</p></div>";
// Use this section to create custom icons for this group of markers
// layer.setIcon(
// // use this if defined custom icons in dataset
// feature.properties.icon
// // or define one set of icon settings for the entire group here
// );
layer.bindPopup(content, {closeButton: true});
};
/*
// If creating multiple groups to be controlled, repeat code for other groups, until all are covered
function addToGroup2 (feature, layer) {
group2.addLayer(layer);
var content = "<div style='clear: both'></div><div><h4>" + feature.properties.title + "</h4><p>" + feature.properties.time + "</p><p>" + feature.properties.description + "</p></div>";
// Use this section to create custom icons for this group of markers
// layer.setIcon(
// // use this if defined custom icons in dataset
// feature.properties.icon
// // or define one set of icon settings for the entire group here
// );
};
*/
// Create an options object that uses the functions above for each marker in the group
var optionsObject1 = {
// If creating multiple groups, specify an overarching time for all of the items in this group
//time: '1992',
onEachFeature: addToGroup1
};
/*
// If creating multiple groups, repeat above for each group
var optionsObject2 = {
// Specify an overarching time for all of the items in this group
time: '1993',
onEachFeature: addToGroup2
}
*/
// For single group, load dataset, popups, etc. into geoJSON layer
L.geoJSON(dataset1, optionsObject1);
/*
// For multiple groups, remove function above and instead create new variables for each group, using their dataset and function
var fullGroup1 = L.geoJSON(dataset1, optionsObject1);
var fullGroup2 = L.geoJSON(dataset2, optionsObject2);
// For multiple groups, create final layerGroup to hold all of these geoJSON variables in an array
var multipleLayerGroups = L.layerGroup([ fullGroup1, fullGroup2 ]);
*/
// Create Slider
var sliderControl1 = L.control.sliderControl( {
// Set below to EITHER the first originally-empty geoJSON layer, OR the final layerGroup containing the array
layer: group1,
// layer: multipleLayerGroups,
alwaysShowDate: true,
showAllPopups: false
});
// Add the slider to the map
map1.addControl(sliderControl1);
// Initialize the slider
sliderControl1.startSlider();
/*
// To load external JSON and create markers with popups that work with LeafletSlider, use the following instead of the above
// These commands are for a single grouping; for multiple groupings from external JSON(s), this will need to be modified
// Create an empty geoJSON layer
var externalJSON = L.geoJSON();
// Setup markers and popups
function addToExternalJSON (feature, layer) {
externalJSON.addLayer(layer);
var content = "<div style='clear: both'></div><div><h4>" + feature.properties.title + "</h4><p>" + feature.properties.time + "</p><p>" + feature.properties.description + "</p></div>";
// Use this section to create custom icons for this group of markers
// layer.setIcon(
// // use this if defined custom icons in JSON file
// feature.properties.icon
// // or define one set of icon settings for the entire group here
// );
/* layer.bindPopup(content, {closeButton: true});
};
// Create an options object that uses the functions above for each marker in the group
var optionsExternalJSON = {
onEachFeature: addToExternalJSON
};
// Load JSON via $.getJSON
$.getJSON("examples/popups.json", function(json) {
L.geoJSON(json, optionsExternalJSON);
// Create Slider
var externalSlider = L.control.sliderControl( {
// Set layer below to the originally-empty geoJSON layer
layer: externalJSON,
alwaysShowDate: true,
showAllPopups: false
});
// Add the slider to the map
map1.addControl(externalSlider);
// Initialize the slider
externalSlider.startSlider();
});
*/
</script>
</body>
</html>