-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialization.js
291 lines (240 loc) · 8.41 KB
/
initialization.js
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
//here we setup the data-loading and tag select menu
setup_select("load data list", time_option_list);
setup_select("tag1", tag_list);
/////////////////////////////////////////////////
//here we setup the first data set menu
data_1 = document.getElementById("data 1");
data_1.addEventListener("change", function() {
});
/////////////////////////////////////////////////
//here is the second data set menu
//It is a lot longer becasue I want to plot different output values
//when data2 is not "None", so I need to update the colour slider here.
data_2 = document.getElementById("data 2");
data_2.addEventListener("change", function() {
if (get_selected_options("data 2")[0] !== "None") {
try {
//if there is a output value type change, destroy the old slider
window.parameter1_colour_slider.noUiSlider.destroy();
window.parameter1_colour_slider = [];
} catch (error) {}
if (typeof(window.parameter1_change_colour_slider) === "undefined" || typeof(window.parameter1_change_colour_slider.noUiSlider) === "undefined") {
//create the proper slider with proper parameters
window.parameter1_change_colour_slider = document.getElementById("colour slider");
noUiSlider.create(window.parameter1_change_colour_slider, {
start: default_change_colour_range,
connect: true,
range: {
"min": change_colour_range[0],
"max": change_colour_range[1]
},
format: wNumb({
decimals: 3,
suffix: "%",
})
});
window.colour_value = document.getElementById("colour value");
//make the small text below the slider, showing the value range
parameter1_change_colour_slider.noUiSlider.on("update", function(values) {
window.colour_value.innerHTML = values.join(" to ");
});
}
} else {
//same as above, just the oppsite situation
try {
window.parameter1_change_colour_slider.noUiSlider.destroy();
window.parameter1_change_colour_slider = [];
} catch (err) {}
if (typeof(window.parameter1_colour_slider) === "undefined" || typeof(window.parameter1_colour_slider.noUiSlider) === "undefined") {
window.parameter1_colour_slider = document.getElementById("colour slider");
noUiSlider.create(parameter1_colour_slider, {
start: default_slider1_range,
connect: true,
range: {
"min": default_slider1_range[0],
"max": default_slider1_range[1]
},
format: wNumb({
decimals: 0,
})
});
window.colour_value = document.getElementById("colour value");
parameter1_colour_slider.noUiSlider.on("update", function(values) {
window.colour_value.innerHTML = values.join(" to ");
});
}
}
});
/////////////////////////////////////////////////
//These two (update_slider and update_slider_range) are functions
//to help us control the noUiSlider
let update_slider = function(slider, handle, value) {
if (handle === "low") {
if (value < slider.noUiSlider.options.range.min) {
slider.noUiSlider.updateOptions({
start: [value, slider.noUiSlider.get()[1]],
range: {
"min": value,
"max": slider.noUiSlider.options.range.max
}
});
} else {
slider.noUiSlider.set([value, null]);
}
}
if (handle === "high") {
if (value > slider.noUiSlider.options.range.max) {
slider.noUiSlider.updateOptions({
start: [slider.noUiSlider.get()[0], value],
range: {
"min": slider.noUiSlider.options.range.min,
"max": value
}
});
} else {
slider.noUiSlider.set([null, value]);
}
}
};
let update_slider_range = function(slider, handle, value) {
if (handle === "low") {
if (value < slider.noUiSlider.options.range.min) {
slider.noUiSlider.updateOptions({
range: {
"min": value,
"max": slider.noUiSlider.options.range.max
}
});
}
}
if (handle === "high") {
if (value > slider.noUiSlider.options.range.max) {
slider.noUiSlider.updateOptions({
range: {
"min": slider.noUiSlider.options.range.min,
"max": value
}
});
}
}
};
/////////////////////////////////////////////////
//the setup for the first filter. In the origal Ymap, this will be the assessment value
const parameter1_slider = document.getElementById("parameter1 slider");
//setup it is a noUiSlider
noUiSlider.create(parameter1_slider, {
start: default_slider1_range,
connect: true,
range: {
"min": default_slider1_range[0],
"max": default_slider1_range[1]
},
});
//get the text boxs in the html
parameter1_lower_bound = document.getElementById("parameter1 lower bound");
parameter1_upper_bound = document.getElementById("parameter1 upper bound");
//listen to changes
parameter1_lower_bound.addEventListener("change", function() {
update_slider_range(parameter1_colour_slider, "low", this.value - 0);
update_slider(parameter1_slider, "low", this.value - 0);
});
parameter1_upper_bound.addEventListener("change", function() {
update_slider_range(parameter1_colour_slider, "high", this.value - 0);
update_slider(parameter1_slider, "high", this.value - 0);
});
//listen to changes on the slider
parameter1_slider.noUiSlider.on("update", function(values, handle) {
let value = values[parseInt(handle,10)];
if (!handle) {
parameter1_lower_bound.value = value;
} else {
parameter1_upper_bound.value = (value);
}
//since the text boxs are controlled by materializeCSS
//we need to reload them
let elems = document.querySelectorAll("select");
let instances = M.FormSelect.init(elems, materialize_options);
});
/////////////////////////////////////////////////
// this will be the second slider, which is the lot size, originally
// same details as parameter1
const parameter2_slider = document.getElementById("parameter2 slider");
noUiSlider.create(parameter2_slider, {
start: default_slider2_range,
connect: true,
range: {
"min": default_slider2_range[0],
"max": default_slider2_range[1]
}
});
parameter2_lower_bound = document.getElementById("parameter2 lower bound");
parameter2_upper_bound = document.getElementById("parameter2 upper bound");
parameter2_lower_bound.addEventListener("change", function() {
update_slider(parameter2_slider, "low", this.value - 0);
});
parameter2_upper_bound.addEventListener("change", function() {
update_slider(parameter2_slider, "high", this.value - 0);
});
parameter2_slider.noUiSlider.on("update", function(values, handle) {
let value = values[parseInt(handle,10)];
if (!handle) {
parameter2_lower_bound.value = value;
} else {
parameter2_upper_bound.value = (value);
}
let elems = document.querySelectorAll("select");
let instances = M.FormSelect.init(elems, materialize_options);
});
/////////////////////////////////////////////////
//create the colour slider fo the first time
parameter1_colour_slider = document.getElementById("colour slider");
noUiSlider.create(parameter1_colour_slider, {
start: default_slider1_range,
connect: true,
range: {
"min": default_slider1_range[0],
"max": default_slider1_range[1]
},
format: wNumb({
decimals: 0,
})
});
window.colour_value = document.getElementById("colour value");
parameter1_colour_slider.noUiSlider.on("update", function(values) {
window.colour_value.innerHTML = values.join(" to ");
});
///////////////////////////////////////////////// sliders finished
//map initialiating
// set up the map use leaflet
let mymap = L.map("mapid", {
renderer: L.canvas(),
markerZoomAnimation: false,
zoomAnimation: false,
});
mymap.setView(map_start_center, 12);
// add map tile from OpenStreetMap France. Thanks!
L.tileLayer("http://a.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png", {
maxZoom: 18,
attribution: '<a href="https://rayliu.ca">Ray Liu</a>, ' +
'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'<a href="https://www.openstreetmap.fr/fonds-de-carte/">OpenStreetMap Fr</a>',
id: "OpenStreetMap.Mapnik"
}).addTo(mymap);
// set a layer group so the points can be easily removed
data_points = L.layerGroup().addTo(mymap);
// setup the legend layer
let legend = L.control({
position: "bottomright"
});
let popup = L.popup(); // set the pop up layer
/////////////////////////////////////////////////
/////Colour functions setup
RGB_gradient_function = [];
RGB_steps = RGB_gradient.length - 1;
for (let i = 0; i < RGB_steps; i++) {
RGB_gradient_function[parseInt(i,10)] = [];
for (let j = 0; j < 3; j++) {
RGB_gradient_function[parseInt(i,10)].push([(RGB_gradient[parseInt(i + 1,10)][parseInt(j,10)] - RGB_gradient[parseInt(i,10)][parseInt(j,10)]) * RGB_steps, RGB_gradient[parseInt(i,10)][parseInt(j,10)]]);
}
}