Public
Edited
May 14, 2023
1 fork
51 stars
Contour Labels (canvas)Coordinated mapsgeoformatSmall circle testKruskal MazeAll the geoshapesReprojecting Vector TilesCloud ContoursHello h3-jsClipping AlbersTranslucent EarthThe truth about the Mercator projectionUsing d3-inertia with observableMercator projection of a Mercator globeD3 Vector Tiles (WIP)Finding intersections between the graticule and the clip sphere of the stereographic projection, method 2Plate tectonicsAnother hex mapEquateur & tropiquesTissot's indicatrixDistance to shoreMultiPolygon clippingSouth Africa’s medial axisSpherical intersectionVolcano Semis (points circulaires)Pencil Airocean45° mapNetCDFBlue noise sphereRubber DymaxionSpherical quasi-random (R2) distributionAutomated label placement (countries)Automated label placement (France)Automated label placement (cities)d3.geoIntersectArcDelaunay.findTriangled3-geo-voronoi and gridded dataElevation vtk.jsMapfillKrigingSpherical HeatmapReproject elevation tiles — detailReproject elevation tiles — worldFisheye Conformal MapSpherical KDE InterpolationSpherical kernel interpolation with nearest neighborsShepard’s methodModified Shepard’s methodSpherical contoursGeo Voronoi interpolationBlurry contoursHow much warmer? (BBC)H3 hexagons & geoContoursHillshading & supersamplingH3 odditiesManhattan VoronoiManhattan Voronoi IIGeoJSON feature editorColorized Manhattan Spanning Treelegra mapslegra country mapsThe complex logarithm projectionCountries small multipleThe 2D approximate Newton-Raphson methodOceanAttitudeCount visible objectsThe Gray-Fuller spatial gridGray-Fuller grid metricsGray-Fuller grid odditiesSpherical smallest-circle problemBounding CirclesCountries Enclosing CirclesFullscreen Seamless Zoomable Map TilesMap Pan & ZoomSpherical Ellipses
Synchronized projections
The closest countryTriangular tiling of icosahedronHello, polygon-clippingCorées / KoreasHello, procedural-glHello, placekeyZoom World ChoroplethClipping spherical polygonsSpherical phyllotaxisFour-color world map with ClingoHello, jsgeoda!The Sun’s analemmaWorld of squaresWorld of squares (spherical)A map of AfricaTagged bordersClipped geoVoronoiBlue noise sphere IISpherical Perlin NoiseSpherical Delaunay triangulationDynamic simplificationRewindPlot: Voronoi labelsAoC 12: shortest path under constraintsHello, pixi.jsFlight PathsRay out of a convex hullDistance to a segment
Also listed in…
Projections
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// this is a very classic function to draw a globe, not much to see there except the call to "zoom"
globe = function(
projection,
title,
{ invalidation, visibility, width = 300, height = 300 } = {}
) {
const context = context2d(width, height),
path = d3
.geoPath()
.projection(
projection
.precision(0.1)
.fitSize([width - 4, height - 4], { type: "Sphere" })
)
.context(context);

projection.translate(projection.translate().map(d => d + 2));

function drawText(text) {
context.save();
context.translate(4, 14);
context.font = "bold 9pt sans-serif";
context.shadowBlur = 3;
context.strokeStyle = context.shadowColor = "white";
context.shadowOffs = 0;
context.strokeText(text, 0, 0);
context.fillText(text, 0, 0);
context.restore();
}

function draw() {
const r = projection.rotate();
context.clearRect(0, 0, width, height);
context.beginPath();
path(d3.geoGraticule10());
context.lineWidth = 0.25;
context.stroke();
context.beginPath();
path(land);
context.fill();
context.beginPath();
path({ type: "Sphere" });
context.lineWidth = 1.5;
context.stroke();

drawText(title);
}

return d3
.select(context.canvas)
.classed("globe", true)
.call(
zoom(projection, draw, {
target: context.canvas,
invalidation,
visibility
})
)
.on("pointerenter pointerdown pointerup", event => {
d3.select(event.currentTarget).style(
"cursor",
event.type === "pointerdown" ? "grabbing" : "grab"
);
})
.node();
}
Insert cell
// this is where the magic happens:
// we take the versor-zooming component (renamed vzoom),
// and wrap it with the synchronization logic
zoom = {
// a communication channel between the globes
const dispatch = d3.dispatch("zoom");

return function(projection, draw, { target, invalidation, visibility }) {
invalidation && invalidation.then(() => dispatch.on("zoom." + id, null));

const id = Math.random(),
s0 = projection.scale();
let willdraw = 0;
dispatch.on("zoom." + id, async function(r, z) {
projection.rotate(r).scale((d3.zoomTransform(target).k = z * s0));

// priority given to the map under the mouse
if (this == target) draw();
// debounce the other maps
else if (!willdraw++) {
if (visibility) await visibility();
await new Promise(r => setTimeout(r, 5)); // change from 5 to 200ms to see what happens
willdraw = 0;
draw();
}
});

const zoom = vzoom(projection).on("zoom.render", function() {
dispatch.call("zoom", this, projection.rotate(), projection.scale() / s0);
});

// do first draw *after* zoom is applied
Promise.resolve().then(() =>
dispatch.call("zoom", this, projection.rotate(), 1)
);

return Object.assign(zoom, { dispatch });
};
}
Insert cell
html`<style>canvas.globe { margin: 3px; }</style>`
Insert cell
d3 = require("d3@7", "d3-geo-polygon@1.8")
Insert cell
import { zoom as vzoom } from "@d3/versor-zooming"
Insert cell
land = {
const topo = await d3.json(
"https://unpkg.com/visionscarto-world-atlas@0.0.6/world/110m.json"
),
simpler = topojson.simplify(topojson.presimplify(topo), 0.5); // try 0 for slower maps
return topojson.feature(simpler, simpler.objects.land);
}
Insert cell
topojson = require("topojson@3")
Insert cell
Insert cell
// outside of Observable, replace by or import from
// https://github.com/observablehq/stdlib/blob/master/src/dom/context2d.js
context2d = DOM.context2d
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more