Unlisted
Edited
Jul 8, 2024
1 fork
2 stars
Insert cell
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: [-72.8, 43.1], zoom: 10, // Vermont
style: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
scrollZoom: true
});

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

// Set map limits
map.setMinZoom(7);
map.setMaxZoom(15);
let bounds = [
[-73.8, 42.5], // [west, south]
[-71.7, 43.6] // [east, north]
];
map.setMaxBounds(bounds);

map.on('load', () => {
map.addSource('vt', {
"type": "image",
"url": "https://pbogden.github.io/webmap.png",
"coordinates": [
[-72.8699937, 43.1636548], // upper left
[-72.6942517, 43.1636548], // upper right
[-72.6942517, 43.0343442], // bottom right
[-72.8699937, 43.0343442], // bottom left
]
});
map.addLayer({
'id': 'vt',
'type': 'raster',
'source': 'vt',
'minzoom': 0,
'maxzoom': 22,
'paint': {'raster-opacity': .5},
})
})

resolve(map); // See: https://observablehq.com/@mbostock/mapbox-fly-to
invalidation.then(() => map.remove());
}
Insert cell
map.isStyleLoaded() // don't attempt to change things unless layer is actually loaded
? map.setPaintProperty("vt", "raster-opacity", opacity)
: null
Insert cell
maplibregl = require("maplibre-gl")
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