forked from MapComplete/MapComplete
Add initial clustering per tile, very broken
This commit is contained in:
parent
2b78c4b53f
commit
c5e9448720
88 changed files with 1080 additions and 651 deletions
|
@ -31,7 +31,7 @@ export default class SimpleMetaTagger {
|
|||
"_version_number"],
|
||||
doc: "Information about the last edit of this object."
|
||||
},
|
||||
(feature) => {/*Note: also handled by 'UpdateTagsFromOsmAPI'*/
|
||||
(feature) => {/*Note: also called by 'UpdateTagsFromOsmAPI'*/
|
||||
|
||||
const tgs = feature.properties;
|
||||
|
||||
|
@ -48,6 +48,7 @@ export default class SimpleMetaTagger {
|
|||
move("changeset", "_last_edit:changeset")
|
||||
move("timestamp", "_last_edit:timestamp")
|
||||
move("version", "_version_number")
|
||||
return true;
|
||||
}
|
||||
)
|
||||
private static latlon = new SimpleMetaTagger({
|
||||
|
@ -62,6 +63,7 @@ export default class SimpleMetaTagger {
|
|||
feature.properties["_lon"] = "" + lon;
|
||||
feature._lon = lon; // This is dirty, I know
|
||||
feature._lat = lat;
|
||||
return true;
|
||||
})
|
||||
);
|
||||
private static surfaceArea = new SimpleMetaTagger(
|
||||
|
@ -74,6 +76,7 @@ export default class SimpleMetaTagger {
|
|||
feature.properties["_surface"] = "" + sqMeters;
|
||||
feature.properties["_surface:ha"] = "" + Math.floor(sqMeters / 1000) / 10;
|
||||
feature.area = sqMeters;
|
||||
return true;
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -118,9 +121,7 @@ export default class SimpleMetaTagger {
|
|||
}
|
||||
|
||||
}
|
||||
if (rewritten) {
|
||||
State.state.allElements.getEventSourceById(feature.id).ping();
|
||||
}
|
||||
return rewritten
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -135,6 +136,7 @@ export default class SimpleMetaTagger {
|
|||
const km = Math.floor(l / 1000)
|
||||
const kmRest = Math.round((l - km * 1000) / 100)
|
||||
feature.properties["_length:km"] = "" + km + "." + kmRest
|
||||
return true;
|
||||
})
|
||||
)
|
||||
private static country = new SimpleMetaTagger(
|
||||
|
@ -144,7 +146,6 @@ export default class SimpleMetaTagger {
|
|||
},
|
||||
feature => {
|
||||
|
||||
|
||||
let centerPoint: any = GeoOperations.centerpoint(feature);
|
||||
const lat = centerPoint.geometry.coordinates[1];
|
||||
const lon = centerPoint.geometry.coordinates[0];
|
||||
|
@ -157,11 +158,11 @@ export default class SimpleMetaTagger {
|
|||
const tagsSource = State.state.allElements.getEventSourceById(feature.properties.id);
|
||||
tagsSource.ping();
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.warn(e)
|
||||
}
|
||||
})
|
||||
return false;
|
||||
}
|
||||
)
|
||||
private static isOpen = new SimpleMetaTagger(
|
||||
|
@ -174,7 +175,7 @@ export default class SimpleMetaTagger {
|
|||
if (Utils.runningFromConsole) {
|
||||
// We are running from console, thus probably creating a cache
|
||||
// isOpen is irrelevant
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
const tagsSource = State.state.allElements.getEventSourceById(feature.properties.id);
|
||||
|
@ -199,7 +200,7 @@ export default class SimpleMetaTagger {
|
|||
if (oldNextChange > (new Date()).getTime() &&
|
||||
tags["_isOpen:oldvalue"] === tags["opening_hours"]) {
|
||||
// Already calculated and should not yet be triggered
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
tags["_isOpen"] = oh.getState() ? "yes" : "no";
|
||||
|
@ -227,6 +228,7 @@ export default class SimpleMetaTagger {
|
|||
}
|
||||
}
|
||||
updateTags();
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.warn("Error while parsing opening hours of ", tags.id, e);
|
||||
tags["_isOpen"] = "parse_error";
|
||||
|
@ -244,11 +246,11 @@ export default class SimpleMetaTagger {
|
|||
const tags = feature.properties;
|
||||
const direction = tags["camera:direction"] ?? tags["direction"];
|
||||
if (direction === undefined) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
const n = cardinalDirections[direction] ?? Number(direction);
|
||||
if (isNaN(n)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// The % operator has range (-360, 360). We apply a trick to get [0, 360).
|
||||
|
@ -256,7 +258,7 @@ export default class SimpleMetaTagger {
|
|||
|
||||
tags["_direction:numerical"] = normalized;
|
||||
tags["_direction:leftright"] = normalized <= 180 ? "right" : "left";
|
||||
|
||||
return true;
|
||||
})
|
||||
)
|
||||
private static carriageWayWidth = new SimpleMetaTagger(
|
||||
|
@ -268,7 +270,7 @@ export default class SimpleMetaTagger {
|
|||
|
||||
const properties = feature.properties;
|
||||
if (properties["width:carriageway"] === undefined) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const carWidth = 2;
|
||||
|
@ -366,7 +368,7 @@ export default class SimpleMetaTagger {
|
|||
|
||||
properties["_width:difference"] = Utils.Round(targetWidth - width);
|
||||
properties["_width:difference:no_pedestrians"] = Utils.Round(targetWidthIgnoringPedestrians - width);
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
private static currentTime = new SimpleMetaTagger(
|
||||
|
@ -375,7 +377,7 @@ export default class SimpleMetaTagger {
|
|||
doc: "Adds the time that the data got loaded - pretty much the time of downloading from overpass. The format is YYYY-MM-DD hh:mm, aka 'sortable' aka ISO-8601-but-not-entirely",
|
||||
includesDates: true
|
||||
},
|
||||
(feature, _, freshness) => {
|
||||
(feature, freshness) => {
|
||||
const now = new Date();
|
||||
|
||||
if (typeof freshness === "string") {
|
||||
|
@ -394,7 +396,7 @@ export default class SimpleMetaTagger {
|
|||
feature.properties["_now:datetime"] = datetime(now);
|
||||
feature.properties["_loaded:date"] = date(freshness);
|
||||
feature.properties["_loaded:datetime"] = datetime(freshness);
|
||||
|
||||
return true;
|
||||
}
|
||||
)
|
||||
public static metatags = [
|
||||
|
@ -413,12 +415,18 @@ export default class SimpleMetaTagger {
|
|||
public readonly keys: string[];
|
||||
public readonly doc: string;
|
||||
public readonly includesDates: boolean
|
||||
private readonly _f: (feature: any, index: number, freshness: Date) => void;
|
||||
public readonly applyMetaTagsOnFeature: (feature: any, freshness: Date) => boolean;
|
||||
|
||||
constructor(docs: { keys: string[], doc: string, includesDates?: boolean }, f: ((feature: any, index: number, freshness: Date) => void)) {
|
||||
/***
|
||||
* A function that adds some extra data to a feature
|
||||
* @param docs: what does this extra data do?
|
||||
* @param f: apply the changes. Returns true if something changed
|
||||
*/
|
||||
constructor(docs: { keys: string[], doc: string, includesDates?: boolean },
|
||||
f: ((feature: any, freshness: Date) => boolean)) {
|
||||
this.keys = docs.keys;
|
||||
this.doc = docs.doc;
|
||||
this._f = f;
|
||||
this.applyMetaTagsOnFeature = f;
|
||||
this.includesDates = docs.includesDates ?? false;
|
||||
for (const key of docs.keys) {
|
||||
if (!key.startsWith('_') && key.toLowerCase().indexOf("theme") < 0) {
|
||||
|
@ -450,12 +458,4 @@ export default class SimpleMetaTagger {
|
|||
return new Combine(subElements).SetClass("flex-col")
|
||||
}
|
||||
|
||||
public addMetaTags(features: { feature: any, freshness: Date }[]) {
|
||||
for (let i = 0; i < features.length; i++) {
|
||||
let feature = features[i];
|
||||
this._f(feature.feature, i, feature.freshness);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue