Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

fix(geocode): a region match takes the place itself, not a name starting with it

quanticsoul47727775f6007dcd
diff --git a/src/keylessGeocoder.js b/src/keylessGeocoder.js
index fb82ac84e..5c69a5aa0 100644
--- a/src/keylessGeocoder.js
+++ b/src/keylessGeocoder.js
@@ -294,7 +294,9 @@ export function selectQualifiedFeature(features, query) {
(Array.isArray(features) ? features : []).find((feature) => {
const properties = feature?.properties ?? {};
const name = normalizeToponym(properties.name);
- if (name !== head && !name.startsWith(`${head} `)) return false;
+ // Exactly the place: "Paris Gare de Lyon" is in France too, but it
+ // is not what "Paris, France" asks for.
+ if (name !== head) return false;
const where = ` ${normalizeToponym(
[
properties.city,
diff --git a/src/keylessGeocoder.test.mjs b/src/keylessGeocoder.test.mjs
index bd6b96f59..81e910fe5 100644
--- a/src/keylessGeocoder.test.mjs
+++ b/src/keylessGeocoder.test.mjs
@@ -512,3 +512,51 @@ test('"USA" and "UK" name their countries, and a trailing comma keeps the nearby
assert.equal(Math.round(result.lat), 34, `got ${result.label}`);
assert.equal(fetchImpl.urls.length, 1);
});
+
+test('a region match takes the place itself, not a place whose name starts with it', () => {
+ const station = {
+ geometry: { type: 'Point', coordinates: [4.86, 45.76] },
+ properties: {
+ osm_key: 'railway',
+ name: 'Paris Gare de Lyon',
+ city: 'Lyon',
+ country: 'France',
+ countrycode: 'FR',
+ },
+ };
+ const paris = {
+ geometry: { type: 'Point', coordinates: [2.35, 48.86] },
+ properties: {
+ osm_key: 'place',
+ name: 'Paris',
+ state: 'Île-de-France',
+ country: 'France',
+ countrycode: 'FR',
+ },
+ };
+ assert.equal(selectQualifiedFeature([station, paris], 'Paris, France'), paris);
+ assert.equal(selectQualifiedFeature([station], 'Paris, France'), null);
+});
+
+test('"UK" names the United Kingdom', () => {
+ const london = {
+ geometry: { type: 'Point', coordinates: [-0.13, 51.51] },
+ properties: {
+ osm_key: 'place',
+ name: 'London',
+ country: 'United Kingdom',
+ countrycode: 'GB',
+ },
+ };
+ const ontario = {
+ geometry: { type: 'Point', coordinates: [-81.25, 42.98] },
+ properties: {
+ osm_key: 'place',
+ name: 'London',
+ state: 'Ontario',
+ country: 'Canada',
+ countrycode: 'CA',
+ },
+ };
+ assert.equal(selectQualifiedFeature([ontario, london], 'London, UK'), london);
+});