Fix various bugs

This commit is contained in:
Pieter Vander Vennet 2022-02-22 14:13:41 +01:00
parent 30f4be183e
commit 5284f198d8
26 changed files with 339 additions and 119 deletions

View file

@ -207,27 +207,36 @@ export abstract class OsmObject {
return objects;
}
/**
* Uses the list of polygon features to determine if the given tags are a polygon or not.
* */
protected static isPolygon(tags: any): boolean {
for (const tagsKey in tags) {
if (!tags.hasOwnProperty(tagsKey)) {
continue
}
const polyGuide = OsmObject.polygonFeatures.get(tagsKey)
const polyGuide : { values: Set<string>; blacklist: boolean } = OsmObject.polygonFeatures.get(tagsKey)
if (polyGuide === undefined) {
continue
}
if ((polyGuide.values === null)) {
// We match all
// .values is null, thus merely _having_ this key is enough to be a polygon (or if blacklist, being a line)
return !polyGuide.blacklist
}
// is the key contained?
return polyGuide.values.has(tags[tagsKey])
// is the key contained? Then we have a match if the value is contained
const doesMatch = polyGuide.values.has(tags[tagsKey])
if(polyGuide.blacklist){
return !doesMatch
}
return doesMatch
}
return false;
}
private static constructPolygonFeatures(): Map<string, { values: Set<string>, blacklist: boolean }> {
const result = new Map<string, { values: Set<string>, blacklist: boolean }>();
for (const polygonFeature of polygon_features) {
for (const polygonFeature of (polygon_features["default"] ?? polygon_features)) {
const key = polygonFeature.key;
if (polygonFeature.polygon === "all") {
@ -381,7 +390,7 @@ export class OsmWay extends OsmObject {
}
if (element.nodes === undefined) {
console.log("PANIC")
console.error("PANIC: no nodes!")
}
for (const nodeId of element.nodes) {
@ -417,7 +426,9 @@ export class OsmWay extends OsmObject {
}
private isPolygon(): boolean {
if (this.coordinates[0] !== this.coordinates[this.coordinates.length - 1]) {
// Compare lat and lon seperately, as the coordinate array might not be a reference to the same object
if (this.coordinates[0][0] !== this.coordinates[this.coordinates.length - 1][0] ||
this.coordinates[0][1] !== this.coordinates[this.coordinates.length - 1][1] ) {
return false; // Not closed
}
return OsmObject.isPolygon(this.tags)