Location-aware preset matching

This commit is contained in:
Bryan Housel
2021-03-23 12:39:14 -04:00
parent 55d9da9480
commit ec787f81ad

View File

@@ -197,17 +197,23 @@ export function presetIndex() {
if (geometry === 'vertex' && entity.isOnAddressLine(resolver)) {
geometry = 'point';
}
return _this.matchTags(entity.tags, geometry);
const entityExtent = entity.extent(resolver);
return _this.matchTags(entity.tags, geometry, entityExtent.center());
});
};
_this.matchTags = (tags, geometry) => {
_this.matchTags = (tags, geometry, loc) => {
const geometryMatches = _geometryIndex[geometry];
let address;
let best = -1;
let match;
let validLocations;
if (Array.isArray(loc)) {
validLocations = locationManager.locationsAt(loc);
}
for (let k in tags) {
// If any part of an address is present, allow fallback to "Address" preset - #4353
if (/^addr:/.test(k) && geometryMatches['addr:*']) {
@@ -218,10 +224,17 @@ export function presetIndex() {
if (!keyMatches) continue;
for (let i = 0; i < keyMatches.length; i++) {
const score = keyMatches[i].matchScore(tags);
const candidate = keyMatches[i];
// discard candidate preset if location is not valid at `loc`
if (validLocations && candidate.locationSetID) {
if (!validLocations[candidate.locationSetID]) continue;
}
const score = candidate.matchScore(tags);
if (score > best) {
best = score;
match = keyMatches[i];
match = candidate;
}
}
}