mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
keep bent streets, enclosed landmarks and same-name outlines honest
A street ribbon that holds neither its ring mean nor the anchor is centred on the street's nearest point when the street runs within 100 m. Nominatim outline selection ranks an exact name, then one holding every asked word, then an overlap, and refuses an overlap whose name lacks the ask's last word unless that word is in the result's address or type, so "Central Park Zoo" is no longer Central Park. The server caches every accepted outline and answers each ask with the one holding its resolved anchor (sent as alat/alon), read across the antimeridian. A duplicate mark that fails to clean up no longer tears down the new outline it duplicates.
This commit is contained in:
1 parent
d9a460658d
commit
a38a065c5c
16 files changed
+516
-133
No files matched your search
@@ -1128,8 +1128,13 @@ export function createAnnotationEngine({
|
||||
if ((other.footprintKind || null) !== (anno.footprintKind || null))
|
||||
continue;
|
||||
if (!outlinesEqual(other, anno)) continue;
|
||||
removeRendered(other);
|
||||
annotations.delete(other.id);
|
||||
try {
|
||||
removeRendered(other);
|
||||
annotations.delete(other.id);
|
||||
} catch {
|
||||
// The duplicate's failure is its own: leave it addressable for
|
||||
// later cleanup and keep this mark's installed outline.
|
||||
}
|
||||
}
|
||||
}
|
||||
renderer.sync(annotations);
|
||||
|
||||
@@ -120,3 +120,45 @@ test('the engine resolves a bare street highlight with its footprint', async (t)
|
||||
assert.equal(seen[0].footprint, true);
|
||||
assert.equal(seen[0].entityKind, 'street');
|
||||
});
|
||||
|
||||
test('a duplicate that fails to clean up never costs the new outline', async (t) => {
|
||||
installAnimationFrameStubs(t);
|
||||
const polygons = [[outer]];
|
||||
const outline = { ring: outer, polygons, footprintKind: 'area' };
|
||||
const point = { lon: 0.005, lat: 0.005, height: 0, source: 'fake' };
|
||||
// "Old" draws at once; "New" resolves the same polygon later.
|
||||
const resolveTarget = async ({ target }) =>
|
||||
target === 'old'
|
||||
? { ...point, label: target, ...outline }
|
||||
: {
|
||||
...point,
|
||||
label: target,
|
||||
resolveOutline: async () => ({ ...point, ...outline }),
|
||||
};
|
||||
const stuck = new Set();
|
||||
const outcomes = [];
|
||||
const engine = createAnnotationEngine({
|
||||
viewer: {},
|
||||
renderer: {
|
||||
...renderer,
|
||||
add(anno) {
|
||||
if (anno.label === 'Old') stuck.add(anno);
|
||||
},
|
||||
remove(anno) {
|
||||
if (stuck.has(anno)) throw new Error('renderer refused');
|
||||
},
|
||||
},
|
||||
resolveTarget,
|
||||
});
|
||||
engine.onOutlineEvent((event) => outcomes.push(event));
|
||||
await engine.annotate({ type: 'area', target: 'old', label: 'Old' });
|
||||
await engine.annotate({ type: 'area', target: 'new', label: 'New' });
|
||||
for (let i = 0; i < 10; i++) await new Promise((r) => setTimeout(r, 0));
|
||||
const fresh = engine.list().find((mark) => mark.label === 'New');
|
||||
assert.equal(fresh?.footprintKind, 'area', 'the new mark keeps its outline');
|
||||
assert.notEqual(fresh.outlineUnavailable, true);
|
||||
assert.deepEqual(
|
||||
outcomes.filter((event) => event.label === 'New').map((e) => e.status),
|
||||
['resolved'],
|
||||
);
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
ringCentroid,
|
||||
} from '../sources/featureGeometry.js';
|
||||
import { isUnavailableCapability } from '../sources/capability.js';
|
||||
import { polygonsContain } from '../data/adminBoundaries.js';
|
||||
import { containsAnchor } from '../data/adminBoundaries.js';
|
||||
import { lonLatToTile } from '../data/tomtomTiles.js';
|
||||
import {
|
||||
BUILDING_MAX_DISTANCE_M,
|
||||
@@ -19,6 +19,8 @@ import {
|
||||
} from '../sources/openFreeMapOutlines.js';
|
||||
import { createNominatimOutlineClient } from '../sources/nominatimOutlines.js';
|
||||
|
||||
export { containsAnchor };
|
||||
|
||||
/**
|
||||
* Outline rungs that need no Overpass, around the resolver's existing ladder:
|
||||
*
|
||||
@@ -82,46 +84,6 @@ export function nominatimKindFor({ scope, groundsLike, pointLike, around }) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether polygons contain a point. A part whose outer ring crosses the
|
||||
* antimeridian ([179.99, …], [-179.99, …]) is read contiguously in its own
|
||||
* longitude frame, with the point moved into that frame; every other part,
|
||||
* including one genuinely wider than 180°, is tested as stored. Crossing is
|
||||
* read from an edge jumping more than 180°, which assumes densely noded rings
|
||||
* (OSM, Nominatim, tiles); a ring that is both wider than 180° and crossing, or
|
||||
* a non-crossing ring with a single edge over 180°, is not supported.
|
||||
*/
|
||||
export function containsAnchor(polygons, lat, lon) {
|
||||
if (!Number.isFinite(lon)) return false;
|
||||
for (const part of polygons || []) {
|
||||
const outer = part?.[0];
|
||||
if (!Array.isArray(outer) || !outer.length) continue;
|
||||
const reference = outer[0][0];
|
||||
const shift = (x) => x - 360 * Math.round((x - reference) / 360);
|
||||
const span = (ring, f) => {
|
||||
let west = Infinity;
|
||||
let east = -Infinity;
|
||||
for (const [x] of ring) {
|
||||
west = Math.min(west, f(x));
|
||||
east = Math.max(east, f(x));
|
||||
}
|
||||
return east - west;
|
||||
};
|
||||
// An edge jumping more than 180° wraps the line; a polar ring whose
|
||||
// edges run along ±180 collapses when reframed and is read as stored.
|
||||
const jumps = outer.some(
|
||||
([x], i) => i > 0 && Math.abs(x - outer[i - 1][0]) > 180,
|
||||
);
|
||||
const framedSpan = jumps ? span(outer, shift) : 0;
|
||||
const crosses = framedSpan > 0 && framedSpan < 180;
|
||||
const framed = crosses
|
||||
? part.map((ring) => ring.map(([x, y]) => [shift(x), y]))
|
||||
: part;
|
||||
if (polygonsContain([framed], lat, crosses ? shift(lon) : lon)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parts with the one holding the anchor outside its holes first. A boundary
|
||||
* can be largest at sea (Tokyo's island municipalities), so size alone does
|
||||
@@ -275,7 +237,14 @@ export function createOutlineRungs({
|
||||
if (!isNamedAsk(query)) return null;
|
||||
const bias = ctx.view || { lat: ctx.lat, lon: ctx.lon };
|
||||
const outline = await nominatim.lookup(
|
||||
{ query, kind, lat: bias.lat, lon: bias.lon },
|
||||
{
|
||||
query,
|
||||
kind,
|
||||
lat: bias.lat,
|
||||
lon: bias.lon,
|
||||
anchorLat: ctx.lat,
|
||||
anchorLon: ctx.lon,
|
||||
},
|
||||
{ signal: ctx.signal },
|
||||
);
|
||||
if (!outline?.polygons?.length) return outline; // null | undefined | unavailable | rateLimited
|
||||
|
||||
@@ -420,6 +420,8 @@ test('a city with no configured Overpass is outlined by Nominatim', async () =>
|
||||
kind: 'city',
|
||||
lat: CAPITOL.lat,
|
||||
lon: CAPITOL.lon,
|
||||
anchorLat: 43.6,
|
||||
anchorLon: 1.44,
|
||||
});
|
||||
assert.deepEqual(
|
||||
run.calls.finished,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { readFileSync } from 'node:fs';
|
||||
import { FEATURE_SOURCE_METHODS } from '../sources/featureSource.js';
|
||||
import { createAnnotationResolver } from './resolver.js';
|
||||
import { polygonsContain } from '../data/adminBoundaries.js';
|
||||
import { streetFootprint } from './outlineRungs.js';
|
||||
|
||||
function viewerAt(lat, lon, height = 20_000) {
|
||||
return {
|
||||
@@ -338,6 +339,54 @@ test('a courtyard outline with no filled candidate anchor remains a point', asyn
|
||||
}
|
||||
});
|
||||
|
||||
test('a bent street keeps its outline when the anchor sits beside the centreline', async () => {
|
||||
// 500 m east then 500 m north: the ring mean lands off the 22 m ribbon.
|
||||
const lat0 = 30.27;
|
||||
const lon0 = -97.74;
|
||||
const dLon = 500 / (111320 * Math.cos((lat0 * Math.PI) / 180));
|
||||
const dLat = 500 / 111320;
|
||||
const line = [
|
||||
[lon0, lat0],
|
||||
[lon0 + dLon / 2, lat0],
|
||||
[lon0 + dLon, lat0],
|
||||
[lon0 + dLon, lat0 + dLat / 2],
|
||||
[lon0 + dLon, lat0 + dLat],
|
||||
];
|
||||
const footprint = streetFootprint({ lines: [line] });
|
||||
// A geocoded point 15 m north of the first leg, outside the ribbon.
|
||||
const lat = lat0 + 15 / 111320;
|
||||
const lon = lon0 + dLon / 2;
|
||||
assert.equal(polygonsContain(footprint.polygons, lat, lon), false);
|
||||
const { resolve } = harness(
|
||||
{ lat, lng: lon, name: 'Bent Street', label: 'Bent St', types: ['route'] },
|
||||
{ outlineRungs: rungsAnswering(footprint) },
|
||||
);
|
||||
const pending = await resolve('Bent Street', viewerAt(lat, lon, 3000), {
|
||||
entityKind: 'street',
|
||||
});
|
||||
const outline = await pending.resolveOutline();
|
||||
assert.equal(outline?.ring, footprint.ring, 'the street is still drawn');
|
||||
assert.ok(polygonsContain(outline.polygons, outline.lat, outline.lon));
|
||||
assert.ok(Math.abs(outline.lat - lat0) < 1e-7, 'centred on the street');
|
||||
assert.ok(Math.abs(outline.lon - lon) < 1e-7);
|
||||
// A same-name street that never comes near the anchor is not that street.
|
||||
const far = lat0 + 300 / 111320;
|
||||
const away = harness(
|
||||
{
|
||||
lat: far,
|
||||
lng: lon,
|
||||
name: 'Bent Street',
|
||||
label: 'Bent St',
|
||||
types: ['route'],
|
||||
},
|
||||
{ outlineRungs: rungsAnswering(footprint) },
|
||||
);
|
||||
const distant = await away.resolve('Bent Street', viewerAt(far, lon, 3000), {
|
||||
entityKind: 'street',
|
||||
});
|
||||
assert.equal((await distant.resolveOutline())?.ring ?? null, null);
|
||||
});
|
||||
|
||||
test('local dateline outlines share a frame for area, centering and filled anchors', async () => {
|
||||
const ring = [
|
||||
[179.9995, -0.0005],
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
approximateAreaM2,
|
||||
approximateDistanceM,
|
||||
pointInPolygon,
|
||||
nearestPointOnLines,
|
||||
} from '../sources/featureGeometry.js';
|
||||
import { defaultGeospatial } from '../search/defaults.js';
|
||||
import * as Cesium from 'cesium';
|
||||
@@ -79,6 +80,9 @@ function localOutlineFrame(fp) {
|
||||
/** Ms the analyst region lookup waits on geocode + admin boundary. */
|
||||
const REGION_FALLBACK_BUDGET_MS = 3_000;
|
||||
|
||||
/** How far a street may run from its anchor when the ribbon holds neither. */
|
||||
const STREET_SNAP_MAX_M = 100;
|
||||
|
||||
/**
|
||||
* Names that end like a landmark rather than a district: "Central Park",
|
||||
* "Lake Merritt"-style suffixes are checked on the last word only, so "Park
|
||||
@@ -830,8 +834,18 @@ export function createAnnotationResolver({
|
||||
frame.reference === null
|
||||
? lon
|
||||
: lon - 360 * Math.round((lon - frame.reference) / 360);
|
||||
if (!polygonsContainPoint(frame.polygons, lat, anchorLon)) return null;
|
||||
centroid = { lat, lon };
|
||||
if (polygonsContainPoint(frame.polygons, lat, anchorLon)) {
|
||||
centroid = { lat, lon };
|
||||
} else if (Array.isArray(fp.lines)) {
|
||||
// A bent street's ribbon rarely holds its ring mean, and a geocoded
|
||||
// anchor can sit beside the centreline: centre on the street itself,
|
||||
// only when it runs beside the anchor.
|
||||
const onStreet = nearestPointOnLines(fp.lines, lat, lon);
|
||||
if (!onStreet || onStreet.distanceM > STREET_SNAP_MAX_M) return null;
|
||||
centroid = { lat: onStreet.lat, lon: onStreet.lon };
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (
|
||||
frame.reference !== null &&
|
||||
|
||||
Reference in new issue
Block a user