|
265 | 265 | title.update = function(lat, log, val, canton) {
|
266 | 266 | console.log(lat);
|
267 | 267 | this._div.innerHTML = `<div class="leaflet-control-layers leaflet-control-layers-expanded" style="width:145px;height:90px;background:gray">
|
268 |
| - <span>canton: ` + canton.toString() + `</span> |
| 268 | + <span>Canton: ` + canton.toString() + `</span> |
269 | 269 | <span>Longtitude: ` + log.toString().substr(0,5) + `</span>
|
270 | 270 | <span>Latitude: ` + lat.toString().substr(0,5) + `<br /></span>
|
271 | 271 | <span>Value: ` + val.toString().substr(0,5) + ` </span>
|
272 | 272 | </div>`;
|
273 | 273 | };
|
274 | 274 | title.addTo(map);
|
275 | 275 |
|
| 276 | + var legend = L.control({position: 'topright'}); |
| 277 | + legend.onAdd = function(map) { |
| 278 | + this._div = L.DomUtil.create('div'); |
| 279 | + this.update() |
| 280 | + return this._div; |
| 281 | + }; |
| 282 | + legend.update = function() { |
| 283 | + this._div.innerHTML = '<div class="leaflet-control-layers leaflet-control-layers-expanded2" id="legendBox" style="width:250px;height:80px;background:white"></div>'; |
| 284 | + }; |
| 285 | + legend.addTo(map); |
| 286 | + var legendSVG = d3.select('#legendBox') |
| 287 | + .append('svg') |
| 288 | + .attr('transform', 'translate(0,' + 0 + ')') |
| 289 | + .attr('width', 250) |
| 290 | + .attr('height', 80); |
| 291 | + |
276 | 292 | showBlock = true;
|
277 | 293 | function toggleBlock(num) {
|
278 | 294 | console.log('Toggle the block')
|
279 | 295 | if(showBlock === true && num == 1){
|
280 | 296 | /* use jquery to select your DOM elements that has the class 'legend' */
|
281 | 297 | $('.leaflet-control-layers').hide();
|
282 |
| - showBlock= false; |
| 298 | + showBlock= false; |
283 | 299 | }
|
284 | 300 | else if (showBlock === false && num == 0){
|
285 | 301 | $('.leaflet-control-layers').show();
|
286 |
| - showBlock = true; |
| 302 | + showBlock = true; |
287 | 303 | }
|
288 | 304 | }
|
289 | 305 |
|
290 |
| - |
291 |
| - // Use the custom grouped layer control, not "L.control.layers" |
292 |
| - L.control.layers(basemaps, null).addTo(map); |
293 |
| - |
294 | 306 | // Remove the stupid leaflet copyright from bottom right
|
295 | 307 |
|
296 | 308 | let stupid_element = document.querySelector('.leaflet-control-attribution.leaflet-control');
|
|
320 | 332 | const svg_y = - height_total - margin.top - margin.bottom - panel_guide_height;
|
321 | 333 | const color = 'steelblue';
|
322 | 334 |
|
| 335 | + createD3LegendBox(legendSVG, 0); |
| 336 | + |
323 | 337 | // Build statistics svg
|
324 | 338 | stat_svg = d3.select('#stat_elements_div')
|
325 | 339 | .append('svg')
|
|
335 | 349 | .attr('opacity', 0.6);
|
336 | 350 |
|
337 | 351 |
|
338 |
| - createD3LegendBox(stat_svg, 0); |
339 |
| - |
340 |
| - |
341 | 352 | // Add canton border to the map
|
342 | 353 | let svg = d3.select(map.getPanes().overlayPane).append('svg').attr('id', 'svg');
|
343 | 354 | let g = svg.append('g').attr('class', 'leaflet-zoom-hide');
|
|
365 | 376 | let typicals_rcp45_2040_25 = d3.json('./data/csv_quickflow/rcp45_2040_25pct/typical_provs.json');
|
366 | 377 | let typicals_rcp45_2040_25_allag = d3.json('./data/csv_quickflow/rcp45_2040_25pct_allag/typical_provs.json');
|
367 | 378 | let typicals_rcp85_2020_75 = d3.json('./data/csv_quickflow/rcp85_2020_75pct/typical_provs.json');
|
368 |
| - let typicals_rcp85_2040_75 = d3.json('./data/csv_quickflow/rcp85_2040_75pct/typical_provs.json'); |
| 379 | + let typicals_rcp85_2040_75 = d3.json('./data/csv_quickflow/rcp85_2040_75pct/typical_provs.json'); |
369 | 380 |
|
370 | 381 | // Get summary data
|
371 | 382 | let summary_bf_history = d3.json('./data/B_historical_change/typical_summary.json')
|
|
375 | 386 | let summary_rcp45_2040_25 = d3.json('./data/csv_quickflow/rcp45_2040_25pct/typical_summary.json');
|
376 | 387 | let summary_rcp45_2040_25_allag = d3.json('./data/csv_quickflow/rcp45_2040_25pct_allag/typical_summary.json');
|
377 | 388 | let summary_rcp85_2020_75 = d3.json('./data/csv_quickflow/rcp85_2020_75pct/typical_summary.json');
|
378 |
| - let summary_rcp85_2040_75 = d3.json('./data/csv_quickflow/rcp85_2040_75pct/typical_summary.json'); |
| 389 | + let summary_rcp85_2040_75 = d3.json('./data/csv_quickflow/rcp85_2040_75pct/typical_summary.json'); |
379 | 390 | // Get national baseflow data
|
380 | 391 | let national_data = d3.json('./data/national_data.json');
|
381 | 392 |
|
|
524 | 535 | for(var i = 0; i < radioButtons.length; i++) {
|
525 | 536 | radioButtons[i].addEventListener('change', function() {
|
526 | 537 | if(this.value !== "null") {
|
| 538 | + legend.addTo(map); |
| 539 | + legendSVG = d3.select('#legendBox') |
| 540 | + .append('svg') |
| 541 | + .attr('transform', 'translate(0,' + 0 + ')') |
| 542 | + .attr('width', 380) |
| 543 | + .attr('height', 100); |
527 | 544 | prev = this;
|
528 | 545 | getCorrectLayerAndAddToMap(this.value);
|
529 | 546 |
|
530 |
| - if(this.value === 0) { |
531 |
| - // Hide timeline |
532 |
| - } |
533 |
| - |
534 |
| - createD3LegendBox(stat_svg, parseInt(this.value, 10)); |
| 547 | + createD3LegendBox(legendSVG, parseInt(this.value, 10)); |
535 | 548 | }
|
536 | 549 |
|
537 | 550 | if(this.value === "null") {
|
|
543 | 556 | if(baseflowLayer !== undefined) {
|
544 | 557 | map.removeLayer(baseflowLayer);
|
545 | 558 | }
|
| 559 | + legend.remove(); |
546 | 560 | removeAllLegend();
|
547 | 561 | }
|
548 | 562 | });
|
|
0 commit comments