Public
Edited
Oct 20, 2023
Insert cell
Insert cell
{
let container = html`<div style='height:800px;' />`
yield container
const map = (container.value = new maplibregl.Map({
boxZoom: true,
pitch: 0,
bearing: 0,
container,
center: [-68.1336229, -16.4955455],
zoom: 15,
style: "https://basemaps.cartocdn.com/gl/positron-nolabels-gl-style/style.json",
scrollZoom: true
}))

map.on("load", function () {
map.addSource("places", places.source)
map.addLayer(places.layer)

map.addSource('labels', labels.source)
map.addLayer(labels.layer)

map.addLayer(placesFake)
})

const mouseenter = function(e) {
map.getCanvas().style.cursor = "pointer";
const poi = e.features[0]
popup.
setHTML(`
<div style="font-weight: bold"; margin: 0px>${poi.properties.name}</div>
<div style="font-size: .8em; opacity: .5; margin: 0px">${poi.properties.category_main}</div>`).
setLngLat(poi.geometry.coordinates).
addTo(map)
}

const mouseleave = function() {
map.getCanvas().style.cursor = "";
popup.remove()
}

const popup = new maplibregl.Popup({
closeButton: false,
closeOnClick: false
})

map.on("mouseenter", "placesfake", mouseenter);
map.on("mouseleave", "placesfake", mouseleave);

map.addControl(new maplibregl.NavigationControl())

map.addControl(
new maplibregl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true
},
showAccuracyCircle: false,
showUserLocation: true
}),
'top-right'
)

}
Insert cell
places = ({
source: {
type: "vector",
url: "pmtiles://https://r2-public.protomaps.com/protomaps-sample-datasets/overture-pois.pmtiles",
attribution: '© <a href="https://overturemaps.org">Overture Maps Foundation</a>'
},
layer: {
id: 'places',
type: 'circle',
source: 'places',
'source-layer': 'pois',
paint: {
'circle-color': '#85bfd4',
'circle-stroke-color': '#85979e',
'circle-opacity': {
base: 1,
stops: [
[8, 0],
[16, .7]
]
},
'circle-radius': [
'interpolate',
['exponential',2],
['zoom'],
0, 1,
18, 9
],
'circle-stroke-width': [
'interpolate',
['exponential',2],
['zoom'],
12, 0,
14, .2
],
}
}
})
Insert cell
placesFake = ({
id: 'placesfake',
type: 'circle',
source: 'places',
'source-layer': 'pois',
paint: {
'circle-color': 'rgba(0,0,0,0)',
'circle-radius': [
'interpolate',
['exponential',2],
['zoom'],
0, 5,
18, 15
],
}
})
Insert cell
labels = ({
source: {
type: 'raster',
tiles: [
'https://a.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png'
],
tileSize: 256
},
layer: {
id: 'labels-layer',
type: 'raster',
source: 'labels',
paint: {
"raster-opacity": .8,
}
}
})
Insert cell
Insert cell
maplibregl = {
const [module, styleURL] = await Promise.all([
require("maplibre-gl@3.1.0"),
require.resolve("maplibre-gl@3.1.0/dist/maplibre-gl.css")
]);
const style = document.head.appendChild(
html`<link rel=stylesheet href=${styleURL}>`
);
invalidation.then(() => style.remove());

let protocol = new pmtiles.Protocol();
module.addProtocol("pmtiles",protocol.tile);
return module;
}
Insert cell
maplibreglcompare = {
const [module, styleURL] = await Promise.all([
require("maplibre-gl@3.1.0"),
require.resolve("maplibre-gl@3.1.0/dist/maplibre-gl.css")
]);
const style = document.head.appendChild(
html`<link rel=stylesheet href=${styleURL}>`
);
invalidation.then(() => style.remove());

let protocol = new pmtiles.Protocol();
module.addProtocol("pmtiles",protocol.tile);
return module;
}
Insert cell
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