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,6 +22,8 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio | ||
22 | let center_latitude = 0.0; | 22 | let center_latitude = 0.0; |
23 | let center_longitude = 0.0; | 23 | let center_longitude = 0.0; |
24 | 24 | ||
25 | + let projectionScale = 79.4188; | ||
26 | + | ||
25 | // Per city | 27 | // Per city |
26 | let maxAttendeeAmount = 0; | 28 | let maxAttendeeAmount = 0; |
27 | let maxFootprint = 0; | 29 | let maxFootprint = 0; |
@@ -340,7 +342,7 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio | @@ -340,7 +342,7 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio | ||
340 | 342 | ||
341 | const rebuildProjection = () => { | 343 | const rebuildProjection = () => { |
342 | mapProjection = d3.geoAzimuthalEquidistant() | 344 | mapProjection = d3.geoAzimuthalEquidistant() |
343 | - .scale(79.4188) | 345 | + .scale(projectionScale) |
344 | .rotate([ | 346 | .rotate([ |
345 | // Don't ask me why | 347 | // Don't ask me why |
346 | -1 * center_longitude, | 348 | -1 * center_longitude, |
@@ -351,17 +353,20 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio | @@ -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 | const recenterOnLatLon = (latitude, longitude) => { | 363 | const recenterOnLatLon = (latitude, longitude) => { |
355 | center_latitude = latitude; | 364 | center_latitude = latitude; |
356 | center_longitude = longitude; | 365 | center_longitude = longitude; |
357 | 366 | ||
358 | rebuildProjection(); | 367 | rebuildProjection(); |
359 | // Draw in order from back to front | 368 | // Draw in order from back to front |
360 | - redrawWorldMap(); | ||
361 | - redrawDistanceCircles(); | ||
362 | - redrawAttendees(); | ||
363 | - redrawCentralCircle(); | ||
364 | - | 369 | + redrawProjected() |
365 | //setupLegend(); | 370 | //setupLegend(); |
366 | }; | 371 | }; |
367 | 372 | ||
@@ -449,6 +454,38 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio | @@ -449,6 +454,38 @@ function draw_emissions_equidistant_map(containerSelector, worldDataUrl, emissio | ||
449 | console.info("[Emissions Equidistant Map] Done.-"); | 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 | d3.select(containerSelector+" svg").on("mousedown", function(event) { | 489 | d3.select(containerSelector+" svg").on("mousedown", function(event) { |
453 | const pointerLonLat = mapProjection.invert(d3.pointer(event)); | 490 | const pointerLonLat = mapProjection.invert(d3.pointer(event)); |
454 | recenterOnLatLon(pointerLonLat[1], pointerLonLat[0]); | 491 | recenterOnLatLon(pointerLonLat[1], pointerLonLat[0]); |