UNPKG

@visactor/vdataset

Version:

data processing tool

47 lines (41 loc) 2.22 kB
import { geoAlbers, geoAlbersUsa, geoAzimuthalEqualArea, geoAzimuthalEquidistant, geoConicConformal, geoConicEqualArea, geoConicEquidistant, geoEqualEarth, geoEquirectangular, geoGnomonic, geoIdentity, geoMercator, geoNaturalEarth1, geoOrthographic, geoStereographic, geoTransverseMercator, geoPath } from "d3-geo"; const defaultPath = geoPath(); export function getProjectionPath(proj) { return proj && proj.path || defaultPath; } const projections = {}, builtInProjections = { albers: geoAlbers, albersusa: geoAlbersUsa, azimuthalequalarea: geoAzimuthalEqualArea, azimuthalequidistant: geoAzimuthalEquidistant, conicconformal: geoConicConformal, conicequalarea: geoConicEqualArea, conicequidistant: geoConicEquidistant, equalearth: geoEqualEarth, equirectangular: geoEquirectangular, gnomonic: geoGnomonic, identity: geoIdentity, mercator: geoMercator, naturalearth1: geoNaturalEarth1, orthographic: geoOrthographic, stereographic: geoStereographic, transversemercator: geoTransverseMercator }; export const projectionProperties = [ "clipAngle", "clipExtent", "scale", "translate", "center", "rotate", "precision", "reflectX", "reflectY", "parallels", "coefficient", "distance", "fraction", "lobes", "parallel", "radius", "ratio", "spacing", "tilt" ]; function createProjectionInner(type, constructor) { return function projectionGenerator() { const p = constructor(); return p.type = type, p.path = geoPath().projection(p), p.copy = p.copy || function() { const c = projectionGenerator(); return projectionProperties.forEach((prop => { p[prop] && c[prop](p[prop]()); })), c.path.pointRadius(p.path.pointRadius()), c; }, p; }; } export function createProjection(type, proj) { const projectionType = type.toLowerCase(); return arguments.length > 1 ? createProjectionInner(projectionType, proj) : builtInProjections[projectionType] ? (projections[projectionType] || (projections[projectionType] = createProjectionInner(projectionType, builtInProjections[projectionType])), projections[projectionType]) : null; } //# sourceMappingURL=projections.js.map