Skip to main content
100%

Interactive Map

✓ Published0🌍 Public
AArnaudBru
Last edited Feb 2, 2018
Created on Feb 2, 2018

This interactive map displays world countries on an equirectangular projection, with hover highlighting and rollover labels showing country names. Users can zoom and pan the map, with limits ensuring the map never leaves the viewport. The visualization uses D3.js v4’s `d3.zoom`, `d3.geoPath`, and `d3.geoEquirectangular` for rendering, while JQuery handles container sizing. Country labels are positioned using `Path.Centroid`, and the map resizes responsively with the window, recalculating zoom and translate extents. Data comes from a geographic GeoJSON source embedded in the SVG rendering.

AI-generated description

D3.js Map with zoom/pan and rollover labels:

  • Uses D3.js(v4) and JQuery
  • Displayed within "map-holder" div to allow easier placement on page.
  • Initial zoom is to show the map as small as possible without leaving whitespace at edges (i.e matching height of div or width of div, whichever is greater zoom)
  • Initial translation is to show centre of map in centre of div
  • ScaleExtent used to ensure map can't be zoomed out to smaller than initial value
  • TranslateExtent used to ensure map can't be moved beyond inside of div
  • Country name labels placed using Path.Centroid (some strange results for countries with remote colonies, e.g France)
  • On resize of window the map SVG is resized, the zoom scaleExtent and translateExtent recalculated and the map zoomed and panned to new initial settings.

forked from <a href='http://bl.ocks.org/andybarefoot/'>andybarefoot</a>'s block: <a href='http://bl.ocks.org/andybarefoot/765c937c8599ef540e1e0b394ca89dc5'>Responsive interactive D3.js map</a>

gpl-3.0 Licensed

Similar vizzes