UNPKG

@fxi/d3-geo-zoom

Version:

Zoom and Pan D3 Geo projections (Ported from vasturiano/d3-geo-zoom)

17 lines (15 loc) 510 B
import * as d3 from "d3"; // Projection interpolation function (from Observable example by Herman Sontrop) // https://observablehq.com/d/0fadbba834367bb5 export function interpolateProjection(raw0, raw1) { const mutate = d3.geoProjectionMutator(t => (x, y) => { const [x0, y0] = raw0(x, y), [x1, y1] = raw1(x, y); return [x0 + t * (x1 - x0), y0 + t * (y1 - y0)]; }); let t = 0; return Object.assign(mutate(t), { alpha(_) { return arguments.length ? mutate(t = +_) : t; } }); }