Public
Edited
Oct 26, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
location
Insert cell
Insert cell
feature = features
? features.find((f) => f.properties.you)
: { type: "Feature", properties: {} }
Insert cell
Insert cell
Insert cell
location = {
if (prompt) {
try {
return await getLocation();
} catch (error) {
console.error(error);
return null;
}
} else {
return null;
}
}
Insert cell
function getLocation() {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
({ coords: { longitude, latitude } }) => resolve([longitude, latitude]),
reject
);
});
}
Insert cell
async function findPolygon(rect) {
const source = geojson.deserialize(url, rect);
const features = [];
// intentionally not caring about multiple matches, which makes sense for these datasets but may not always
for await (const feature of source) {
if (d3.geoContains(feature, [rect.minX, rect.minY])) {
feature.properties.you = true;
}

features.push(feature);
}

return features;
}
Insert cell
geojson = import("https://esm.sh/flatgeobuf@3.23.1/lib/mjs/geojson.js?bundle")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more