Public
Edited
Feb 6, 2024
2 stars
Also listed in…
Geospatial
Insert cell
Insert cell
Insert cell
Insert cell
BufferQuery = {
return srid === "3857"
? `SELECT ST_Transform(ST_Buffer(ST_Transform(MakePoint(${bufferCenter[0]}, ${bufferCenter[1]},4326),3857), ${bufferWidth}, ${quadSegments}), 4326);`
: `SELECT ST_Buffer(MakePoint(${bufferCenter[0]}, ${bufferCenter[1]},4326), ${bufferWidthDegrees}, ${quadSegments});`;
}
Insert cell
buffer = await db.exec(BufferQuery).get.first
Insert cell
{
if (mapReady) {
map.getSource("buffer").setData(buffer);
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
map.on("load", async () => {
// buffer circle
map.addSource("buffer", {
type: "geojson",
data: { type: "FeatureCollection", features: [] }
});

map.addLayer({
id: "buffer",
type: "line",
source: "buffer",
paint: {
"line-color": "#ff0000",
"line-width": 3
}
});
mutable mapReady = true;
})
Insert cell
marker = new mapboxgl.Marker({ draggable: true })
.setLngLat([5.7245, 45.1885])
.addTo(map)
Insert cell
mutable bufferCenter = [5.7245, 45.1885]
Insert cell
marker.on(
"drag",
(d) =>
(mutable bufferCenter = [
Math.round(marker.getLngLat().lng * 1000000) / 1000000,
Math.round(marker.getLngLat().lat * 1000000) / 1000000
])
)
Insert cell
Insert cell
Insert cell
Insert cell
dbsrc = FileAttachment("lights@1.sqlite").arrayBuffer()
Insert cell
projsrc = FileAttachment("proj.db").arrayBuffer()
Insert cell
Insert cell
db = spl
.mount("proj", [{ name: "proj.db", data: projsrc }])
.db(dbsrc)
.exec("select initspatialmetadata(1)")
Insert cell
Insert cell
spl = SPL.default()
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