Skip to content

armgit / Aleph

Public Imported from GitHub
0

Give satellite imagery, terrain data, buildings, streetview photos to your LLM

Cleanup changes

Belluxx38aa50015fe3
diff --git a/src/assets/app.js b/src/assets/app.js
index f837706..b2e3436 100644
--- a/src/assets/app.js
+++ b/src/assets/app.js
@@ -460,13 +460,13 @@ async function selectCapture(identity, fit = true) {
if (fit && run.terrain) fitCapture(false);
if (!updating || newTerrain || fit) applyTerrain(fit && run.terrain);
if (fit && !run.terrain) fitCapture();
- const work = [];
if (run.osm && !map.getSource("osm")) loadOSM(run);
if (run.layers.streetview && (!map.getSource("photos")
- || state.photoCount < run.layers.streetview.done)) work.push(loadPhotos(run, ticket));
- const results = await Promise.allSettled(work);
+ || state.photoCount < run.layers.streetview.done)) {
+ try { await loadPhotos(run, ticket); }
+ catch (error) { if (ticket === state.selection) notice(error.message); }
+ }
if (ticket !== state.selection) return;
- for (const result of results) if (result.status === "rejected") notice(result.reason.message);
applyLayers();
} finally {
if (ticket === state.selection) {
@@ -481,17 +481,11 @@ async function selectCapture(identity, fit = true) {
function loadOSM(run) {
state.map.addSource("osm", {type: "geojson", data: runURL(run.id, "/osm.geojson"),
attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap contributors</a>'});
- const polygon = ["==", ["geometry-type"], "Polygon"];
- const building = ["all", polygon, ["has", "building"], ["!=", ["get", "building"], "no"]];
- const land = ["all", polygon,
- ["any", ["has", "landuse"], ["in", ["get", "natural"], ["literal", ["wood", "grassland", "scrub", "heath"]]]],
- ["!", ["has", "building"]]];
- const water = ["all", polygon, ["any", ["==", ["get", "natural"], "water"], ["has", "water"], ["==", ["get", "landuse"], "reservoir"]]];
- const road = ["all", ["==", ["geometry-type"], "LineString"], ["has", "highway"]];
+ const building = ["has", "building"], road = ["has", "road"];
const layers = [
- {id: "land", type: "fill", filter: land, paint: {"fill-color": "--map-land", "fill-opacity": 0.27}},
- {id: "water", type: "fill", filter: water, paint: {"fill-color": "--map-capture-water", "fill-opacity": 0.6}},
- {id: "water-lines", type: "line", filter: ["all", ["==", ["geometry-type"], "LineString"], ["has", "waterway"]], paint: {"line-color": "--map-capture-waterway", "line-width": 2}},
+ {id: "land", type: "fill", filter: ["has", "land"], paint: {"fill-color": "--map-land", "fill-opacity": 0.27}},
+ {id: "water", type: "fill", filter: ["has", "water"], paint: {"fill-color": "--map-capture-water", "fill-opacity": 0.6}},
+ {id: "water-lines", type: "line", filter: ["has", "waterway"], paint: {"line-color": "--map-capture-waterway", "line-width": 2}},
{id: "road-casing", type: "line", filter: road, paint: {"line-color": "--map-capture-road-casing", "line-opacity": 0.8, "line-width": ["interpolate", ["linear"], ["zoom"], 12, 1.5, 19, 8]}},
{id: "roads", type: "line", filter: road, paint: {"line-color": "--map-capture-road", "line-width": ["interpolate", ["linear"], ["zoom"], 12, 0.7, 19, 5]}},
{id: "buildings", type: "fill", filter: building, paint: {"fill-color": "--map-capture-building", "fill-opacity": 0.5}},
@@ -499,7 +493,7 @@ function loadOSM(run) {
{id: "buildings-3d", type: "fill-extrusion", filter: building, layout: {visibility: "none"}, paint: {"fill-extrusion-color": "--map-capture-building", "fill-extrusion-height": ["get", "_height"], "fill-extrusion-base": ["get", "_base"], "fill-extrusion-opacity": 0.88}},
];
for (const layer of layers) addLayer({...layer, source: "osm"});
- // Keep photo dots above polygons regardless of which request finished first.
+ // OSM can become available after photo dots during a live capture.
if (state.map.getLayer("stops")) state.map.moveLayer("stops", "selection-fill");
}
diff --git a/src/dashboard_osm.py b/src/dashboard_osm.py
index 5564afc..5c2a803 100644
--- a/src/dashboard_osm.py
+++ b/src/dashboard_osm.py
@@ -3,9 +3,10 @@
import math
import re
from collections import defaultdict
+from itertools import pairwise
from xml.etree import ElementTree as ET
-from .geo import collection, feature
+from .geo import feature
DISPLAY_TAGS = {"building", "landuse", "natural", "water", "highway", "waterway"}
TAGS = DISPLAY_TAGS | {"name", "height", "building:levels", "min_height", "type"}
@@ -50,17 +51,15 @@ def meters(value, fallback):
def properties(tags, polygon):
if not polygon:
- return {key: tags[key] for key in ("highway", "waterway") if key in tags}
- building = "building" in tags and tags["building"] != "no"
+ return {layer: True for key, layer in (("highway", "road"), ("waterway", "waterway")) if key in tags}
+ building = tags.get("building", "no") != "no"
land = "building" not in tags and ("landuse" in tags or tags.get("natural") in
("wood", "grassland", "scrub", "heath"))
water = tags.get("natural") == "water" or "water" in tags or tags.get("landuse") == "reservoir"
- if not (building or land or water):
- return {}
- result = {key: tags[key] for key in ("building", "landuse", "natural", "water") if key in tags}
+ result = {layer: True for layer, visible in (("land", land), ("water", water)) if visible}
if building:
height = meters(tags.get("height"), meters(tags.get("building:levels"), 3) * 3)
- result.update(_height=height, _base=min(height, meters(tags.get("min_height"), 0)),
+ result.update(building=tags["building"], _height=height, _base=min(height, meters(tags.get("min_height"), 0)),
_estimated=not tags.get("height") and not tags.get("building:levels"))
if "name" in tags:
result["name"] = tags["name"]
@@ -121,13 +120,13 @@ def rings(identities, ways, nodes):
def signed_area(ring):
- return sum(a[0] * b[1] - b[0] * a[1] for a, b in zip(ring, ring[1:])) / 2
+ return sum(a[0] * b[1] - b[0] * a[1] for a, b in pairwise(ring)) / 2
def contains(ring, point):
x, y = point
inside = False
- for (ax, ay), (bx, by) in zip(ring, ring[1:]):
+ for (ax, ay), (bx, by) in pairwise(ring):
if (ay > y) != (by > y) and x < (bx - ax) * (y - ay) / (by - ay) + ax:
inside = not inside
return inside
@@ -182,4 +181,4 @@ def display_osm(path):
coordinates.reverse()
features.append(feature("Polygon" if polygon else "LineString",
[coordinates] if polygon else coordinates, props))
- return collection(features)
+ return dict(type="FeatureCollection", features=features)
diff --git a/src/dashboard_tiles.py b/src/dashboard_tiles.py
index 5d6fd74..062844d 100644
--- a/src/dashboard_tiles.py
+++ b/src/dashboard_tiles.py
@@ -131,12 +131,9 @@ class Tiles:
if path.is_file():
with Image.open(path) as patch:
return patch.convert("RGBA")
- image = Image.new(mode, (size, size))
- if version and z == grid["zoom"]:
- if elevation:
- image.close()
- image = terrain_tile(contained(folder, "terrain.tif"), grid, x, y)
- elif version:
+ image = (terrain_tile(contained(folder, "terrain.tif"), grid, x, y)
+ if elevation and version and z == grid["zoom"] else Image.new(mode, (size, size)))
+ if version and z < grid["zoom"]:
for dy in range(2):
for dx in range(2):
with (
diff --git a/tests/test_dashboard_osm.py b/tests/test_dashboard_osm.py
index faf8d8f..46ea99c 100644
--- a/tests/test_dashboard_osm.py
+++ b/tests/test_dashboard_osm.py
@@ -60,11 +60,11 @@ class DashboardOSMTests(unittest.TestCase):
self.assertEqual(building["geometry"]["type"], "Polygon")
self.assertEqual(building["properties"], dict(building="yes", name="Library", _height=9.144,
_base=9.144, _estimated=False))
- self.assertEqual(forest["properties"], {"landuse": "forest"})
- self.assertEqual(pond["properties"], {"natural": "water", "water": "pond"})
+ self.assertEqual(forest["properties"], {"land": True})
+ self.assertEqual(pond["properties"], {"water": True})
self.assertEqual(road["geometry"]["type"], "LineString")
- self.assertEqual(road["properties"], {"highway": "residential"})
- self.assertEqual(stream["properties"], {"waterway": "stream"})
+ self.assertEqual(road["properties"], {"road": True})
+ self.assertEqual(stream["properties"], {"waterway": True})
self.assertEqual(house["properties"]["_height"], 6)
self.assertFalse(house["properties"]["_estimated"])
self.assertEqual(shed["properties"]["_height"], 9)
@@ -83,7 +83,7 @@ class DashboardOSMTests(unittest.TestCase):
self.save()
features = display_osm(self.path)["features"]
self.assertEqual(len(features), 1)
- self.assertEqual(features[0]["properties"], {"natural": "water"})
+ self.assertEqual(features[0]["properties"], {"water": True})
geometry = features[0]["geometry"]
self.assertEqual(geometry["type"], "MultiPolygon")
polygons = geometry["coordinates"]
@@ -100,7 +100,7 @@ class DashboardOSMTests(unittest.TestCase):
self.relation(1, [(1, "outer"), (2, "inner")], type="multipolygon")
self.save()
features = display_osm(self.path)["features"]
- self.assertEqual([f["properties"] for f in features], [{"landuse": "forest"}, {"natural": "water"}])
+ self.assertEqual([f["properties"] for f in features], [{"land": True}, {"water": True}])
self.assertEqual(len(features[0]["geometry"]["coordinates"][0]), 2)
def test_endpoint_reconverts_without_cache_and_reports_invalid_xml(self):