Published
Edited
Nov 8, 2021
1 fork
Also listed in…
leaflet
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof rows = Table(geojson.features)
Insert cell
Insert cell
viewof properties = Table(rows.map(d => d.properties))
Insert cell
Insert cell
[...new Set(rows.map(d => d.properties.type))] // Unique "properties.type"s
Insert cell
rows.filter(d => d.properties.type == 'node')
Insert cell
Insert cell
highway_types = [...new Set(highways.map(d => d.highway))]
Insert cell
Insert cell
viewof highways = Table(rows.map(d => d.properties.tags).filter(d => d.highway))
Insert cell
Insert cell
viewof not_highway = Table(rows.map(d => d.properties.tags).filter(d => !(d.highway)))
Insert cell
Insert cell
Insert cell
layer = {
const style = {
"color": "crimson",
"weight": 5,
"opacity": 0.65
};
function onEachFeature(feature, layer) {
if (feature.properties && feature.properties.tags && feature.properties.tags.name) {
layer.bindPopup(feature.properties.tags.name);
} else {
layer.bindPopup(feature.properties.type + " id: " + feature.properties.id)
}
}
const layer = L.geoJSON([geojson], {

style: style,
onEachFeature: onEachFeature,

pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, {
radius: 4,
fillColor: "blue",
stroke: "black",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.5
});
}
}).addTo(map);
map.fitBounds(layer.getBounds(), {padding: [20, 20]});
invalidation.then(() => map.removeLayer(layer));
return layer
}
Insert cell
Insert cell
Insert cell
Insert cell
geojson = queryOverpassGeoJSON(query)
Insert cell
function queryOverpassGeoJSON(query) {
mutable report = md`Please wait...`;
return new Promise((resolve, reject) => {
queryOverpass(query, (error, data) => {
if (error) {
mutable report = error;
reject(error);
} else {
mutable report = md`${data.features.length} features returned.`;
resolve(data);
}
});
});
}
Insert cell
Insert cell
Insert cell
Insert cell
{
viewof query.value = choice ? queries[choice] : null;
viewof query.dispatchEvent(new Event('input'))
return md`This cell links the Radio button and the TextArea submit button.`
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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