Unlisted
Edited
Jan 12
Fork of DEM contours
Insert cell
Insert cell
viewof map = {
const container = html`<div style="height:600px;">`;
let resolve;
container.value = new Promise(_ => resolve = _);
yield container; // Give the container dimensions.
const map = new maplibregl.Map({
// interactive: false,
boxZoom: true, // use shift+drag to create bounding box, "zoom to" follows
pitch: 0,
bearing: 0,
maplibreLogo: true,
container,
center: [-70.2568, 43.6591], zoom: 13, // Portland, ME
style: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
scrollZoom: true
});

map.addControl(new maplibregl.NavigationControl());

// Set map limits
map.setMinZoom(10);
map.setMaxZoom(15);

map.on('load', () => {
map.addSource("contour-source", {
type: "vector",
tiles: [
demSource.contourProtocolUrl({
// convert meters to feet, default=1 for meters
multiplier: 3.28084,
thresholds: {
10: 5,
11: 5,
12: 5,
13: 5,
14: 5,
15: 5,
// zoom: [minor, major]
// 9: [200, 1000],
// 10: [200, 1000],
// 11: [200, 1000],
// 12: [100, 500],
// 14: [50, 200],
// 15: [20, 100],
},
// optional, override vector tile parameters:
contourLayer: "contours",
elevationKey: "ele",
levelKey: "level",
extent: 4096,
buffer: 1,
}),
],
maxzoom: 15,
});
map.addLayer({
id: "contour-lines",
type: "line",
source: "contour-source",
"source-layer": "contours",
paint: {
"line-color": "rgba(0,0,0, 50%)",
// level = highest index in thresholds array the elevation is a multiple of
"line-width": ["match", ["get", "level"], 1, 1, 0.5],
},
});
})

resolve(map); // See: https://observablehq.com/@mbostock/mapbox-fly-to
invalidation.then(() => map.remove());
}
Insert cell
maplibregl = require("maplibre-gl")
Insert cell
mlcontour = require("maplibre-contour")
Insert cell
demSource = {
const demSource = new mlcontour.DemSource({
// url: "https://elevation-tiles-prod.s3.amazonaws.com/terrarium/{z}/{x}/{y}.png", encoding: "terrarium", // THIS WORKS
url: "https://pbogden.github.io/geo/xyz/{z}/{x}/{y}.png", encoding: "mapbox", // DOES NOT WORK
maxzoom: 15,
});

demSource.setupMaplibre(maplibregl);

return demSource
}
Insert cell
<link href="https://unpkg.com/maplibre-gl/dist/maplibre-gl.css" rel="stylesheet" />
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