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
|
@ -2,6 +2,7 @@ import SimpleMetaTagger from "./SimpleMetaTagger";
|
|||
import {ExtraFuncParams, ExtraFunction} from "./ExtraFunction";
|
||||
import {UIEventSource} from "./UIEventSource";
|
||||
import LayerConfig from "../Models/ThemeConfig/LayerConfig";
|
||||
import State from "../State";
|
||||
|
||||
|
||||
/**
|
||||
|
@ -20,50 +21,68 @@ export default class MetaTagging {
|
|||
* The given features should be part of the given layer
|
||||
*/
|
||||
public static addMetatags(features: { feature: any; freshness: Date }[],
|
||||
params: ExtraFuncParams,
|
||||
layer: LayerConfig,
|
||||
options?: {
|
||||
includeDates?: true | boolean,
|
||||
includeNonDates?: true | boolean
|
||||
}) {
|
||||
params: ExtraFuncParams,
|
||||
layer: LayerConfig,
|
||||
options?: {
|
||||
includeDates?: true | boolean,
|
||||
includeNonDates?: true | boolean
|
||||
}) {
|
||||
|
||||
if (features === undefined || features.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const metatag of SimpleMetaTagger.metatags) {
|
||||
|
||||
try {
|
||||
const metatagsToApply: SimpleMetaTagger [] = []
|
||||
for (const metatag of SimpleMetaTagger.metatags) {
|
||||
if (metatag.includesDates) {
|
||||
if (options.includeDates ?? true) {
|
||||
metatag.addMetaTags(features);
|
||||
metatagsToApply.push(metatag)
|
||||
}
|
||||
} else {
|
||||
if (options.includeNonDates ?? true) {
|
||||
metatag.addMetaTags(features);
|
||||
metatagsToApply.push(metatag)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error("Could not calculate metatag for ", metatag.keys.join(","), ":", e)
|
||||
}
|
||||
}
|
||||
|
||||
// The functions - per layer - which add the new keys
|
||||
// The calculated functions - per layer - which add the new keys
|
||||
const layerFuncs = this.createRetaggingFunc(layer)
|
||||
|
||||
if (layerFuncs !== undefined) {
|
||||
for (const feature of features) {
|
||||
|
||||
try {
|
||||
layerFuncs(params, feature.feature)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
for (let i = 0; i < features.length; i++) {
|
||||
const ff = features[i];
|
||||
const feature = ff.feature
|
||||
const freshness = ff.freshness
|
||||
let somethingChanged = false
|
||||
for (const metatag of metatagsToApply) {
|
||||
try {
|
||||
if(!metatag.keys.some(key => feature.properties[key] === undefined)){
|
||||
// All keys are already defined, we probably already ran this one
|
||||
continue
|
||||
}
|
||||
somethingChanged = somethingChanged || metatag.applyMetaTagsOnFeature(feature, freshness)
|
||||
} catch (e) {
|
||||
console.error("Could not calculate metatag for ", metatag.keys.join(","), ":", e)
|
||||
}
|
||||
}
|
||||
|
||||
if(layerFuncs !== undefined){
|
||||
try {
|
||||
layerFuncs(params, feature)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
somethingChanged = true
|
||||
}
|
||||
|
||||
if(somethingChanged){
|
||||
State.state.allElements.getEventSourceById(feature.properties.id).ping()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static createRetaggingFunc(layer: LayerConfig):
|
||||
((params: ExtraFuncParams, feature: any) => void) {
|
||||
const calculatedTags: [string, string][] = layer.calculatedTags;
|
||||
|
@ -92,11 +111,13 @@ export default class MetaTagging {
|
|||
d = JSON.stringify(d);
|
||||
}
|
||||
feature.properties[key] = d;
|
||||
console.log("Written a delayed calculated tag onto ", feature.properties.id, ": ", key, ":==", d)
|
||||
})
|
||||
result = result.data
|
||||
}
|
||||
|
||||
if (result === undefined || result === "") {
|
||||
console.log("Calculated tag for", key, "gave undefined", feature.properties.id)
|
||||
return;
|
||||
}
|
||||
if (typeof result !== "string") {
|
||||
|
@ -104,6 +125,7 @@ export default class MetaTagging {
|
|||
result = JSON.stringify(result);
|
||||
}
|
||||
feature.properties[key] = result;
|
||||
console.log("Written a calculated tag onto ", feature.properties.id, ": ", key, ":==", result)
|
||||
} catch (e) {
|
||||
if (MetaTagging.errorPrintCount < MetaTagging.stopErrorOutputAt) {
|
||||
console.warn("Could not calculate a calculated tag defined by " + code + " due to " + e + ". This is code defined in the theme. Are you the theme creator? Doublecheck your code. Note that the metatags might not be stable on new features", e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue