mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
Location-aware preset matching
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user