Commit a5f8a21914a62cee97e46cff7855c907fa1b23f5
1 parent
289db173
Exists in
master
Add Zoom feature to emissions equidistant map
Showing
1 changed file
with
43 additions
and
6 deletions
Show diff stats
flaskr/static/js/plots/emissions-equidistant-map.js
... | ... | @@ -22,6 +22,8 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio |
22 | 22 | let center_latitude = 0.0; |
23 | 23 | let center_longitude = 0.0; |
24 | 24 | |
25 | + let projectionScale = 79.4188; | |
26 | + | |
25 | 27 | // Per city |
26 | 28 | let maxAttendeeAmount = 0; |
27 | 29 | let maxFootprint = 0; |
... | ... | @@ -340,7 +342,7 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio |
340 | 342 | |
341 | 343 | const rebuildProjection = () => { |
342 | 344 | mapProjection = d3.geoAzimuthalEquidistant() |
343 | - .scale(79.4188) | |
345 | + .scale(projectionScale) | |
344 | 346 | .rotate([ |
345 | 347 | // Don't ask me why |
346 | 348 | -1 * center_longitude, |
... | ... | @@ -351,17 +353,20 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio |
351 | 353 | }; |
352 | 354 | |
353 | 355 | |
356 | + const redrawProjected = () => { | |
357 | + redrawWorldMap(); | |
358 | + redrawDistanceCircles(); | |
359 | + redrawAttendees(); | |
360 | + redrawCentralCircle(); | |
361 | + }; | |
362 | + | |
354 | 363 | const recenterOnLatLon = (latitude, longitude) => { |
355 | 364 | center_latitude = latitude; |
356 | 365 | center_longitude = longitude; |
357 | 366 | |
358 | 367 | rebuildProjection(); |
359 | 368 | // Draw in order from back to front |
360 | - redrawWorldMap(); | |
361 | - redrawDistanceCircles(); | |
362 | - redrawAttendees(); | |
363 | - redrawCentralCircle(); | |
364 | - | |
369 | + redrawProjected() | |
365 | 370 | //setupLegend(); |
366 | 371 | }; |
367 | 372 | |
... | ... | @@ -449,6 +454,38 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio |
449 | 454 | console.info("[Emissions Equidistant Map] Done.-"); |
450 | 455 | }); |
451 | 456 | |
457 | + // console.log(d3.select(containerSelector)); | |
458 | + let buttonContainer = d3.select(containerSelector) | |
459 | + .append("div") | |
460 | + .style("position", 'absolute') | |
461 | + .style("top", d3.select(containerSelector).property("clientTop") + 12) | |
462 | + .style("left", | |
463 | + d3.select(containerSelector).property("clientLeft") + | |
464 | + svg.attr("width") | |
465 | + - 40); | |
466 | + let zoomOutButton = buttonContainer | |
467 | + .append("input") | |
468 | + .attr("value", "-") | |
469 | + .attr("type", "button") | |
470 | + .style("width", 22); | |
471 | + let zoomInButton = buttonContainer | |
472 | + .append("input") | |
473 | + .attr("value", "+") | |
474 | + .attr("type", "button") | |
475 | + .style("width", 22); | |
476 | + | |
477 | + zoomOutButton.on("click", () => { | |
478 | + projectionScale *= 0.9; | |
479 | + rebuildProjection(); | |
480 | + redrawProjected(); | |
481 | + }); | |
482 | + | |
483 | + zoomInButton.on("click", () => { | |
484 | + projectionScale *= 1.10; | |
485 | + rebuildProjection(); | |
486 | + redrawProjected(); | |
487 | + }); | |
488 | + | |
452 | 489 | d3.select(containerSelector+" svg").on("mousedown", function(event) { |
453 | 490 | const pointerLonLat = mapProjection.invert(d3.pointer(event)); |
454 | 491 | recenterOnLatLon(pointerLonLat[1], pointerLonLat[0]); | ... | ... |