Rendering bug fixes, add 'get' to the ExtraFunctions, filtering in the GRB theme

This commit is contained in:
Pieter Vander Vennet 2021-10-28 03:15:36 +02:00
parent 10d9f18110
commit c74989e88d
9 changed files with 318 additions and 114 deletions

View file

@ -163,12 +163,41 @@ export class ExtraFunction {
}
)
private static readonly GetParsed = new ExtraFunction(
{
name: "get",
doc: "Gets the property of the feature, parses it (as JSON) and returns it. Might return 'undefined' if not defined, null, ...",
args: ["key"]
},
(params, feat) => {
return key => {
const value = feat.properties[key]
if (value === undefined) {
return undefined;
}
try {
const parsed = JSON.parse(value)
if(parsed === null){
return undefined;
}
return parsed;
} catch (e) {
console.warn("Could not parse property " + key + " due to: " + e + ", the value is " + value)
return undefined;
}
}
}
)
private static readonly allFuncs: ExtraFunction[] = [
ExtraFunction.DistanceToFunc,
ExtraFunction.OverlapFunc,
ExtraFunction.ClosestObjectFunc,
ExtraFunction.ClosestNObjectFunc,
ExtraFunction.Memberships
ExtraFunction.Memberships,
ExtraFunction.GetParsed
];
private readonly _name: string;
private readonly _args: string[];
@ -248,11 +277,11 @@ export class ExtraFunction {
console.error("Could not calculate the distance between", feature, "and", otherFeature)
throw "Undefined distance!"
}
if(distance === 0){
console.trace("Got a suspiciously zero distance between", otherFeature, "and self-feature",feature)
if (distance === 0) {
console.trace("Got a suspiciously zero distance between", otherFeature, "and self-feature", feature)
}
if (distance > maxDistance) {
continue
}

View file

@ -12,7 +12,6 @@ import OverpassFeatureSource from "../Actors/OverpassFeatureSource";
import {Changes} from "../Osm/Changes";
import GeoJsonSource from "./Sources/GeoJsonSource";
import Loc from "../../Models/Loc";
import WayHandlingApplyingFeatureSource from "./Sources/RenderingMultiPlexerFeatureSource";
import RegisteringAllFromFeatureSourceActor from "./Actors/RegisteringAllFromFeatureSourceActor";
import TiledFromLocalStorageSource from "./TiledFeatureSource/TiledFromLocalStorageSource";
import SaveTileToLocalStorageActor from "./Actors/SaveTileToLocalStorageActor";
@ -26,6 +25,7 @@ import OsmFeatureSource from "./TiledFeatureSource/OsmFeatureSource";
import {OsmConnection} from "../Osm/OsmConnection";
import {Tiles} from "../../Models/TileRange";
import TileFreshnessCalculator from "./TileFreshnessCalculator";
import {ElementStorage} from "../ElementStorage";
/**
@ -85,7 +85,8 @@ export default class FeaturePipeline {
readonly overpassMaxZoom: UIEventSource<number>;
readonly osmConnection: OsmConnection
readonly currentBounds: UIEventSource<BBox>,
readonly osmApiTileSize: UIEventSource<number>
readonly osmApiTileSize: UIEventSource<number>,
readonly allElements: ElementStorage
}) {
this.state = state;

View file

@ -3,6 +3,8 @@ import FilteredLayer from "../../../Models/FilteredLayer";
import {FeatureSourceForLayer, Tiled} from "../FeatureSource";
import Hash from "../../Web/Hash";
import {BBox} from "../../BBox";
import {ElementStorage} from "../../ElementStorage";
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig";
export default class FilteringFeatureSource implements FeatureSourceForLayer, Tiled {
public features: UIEventSource<{ feature: any; freshness: Date }[]> =
@ -12,12 +14,16 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti
public readonly tileIndex: number
public readonly bbox: BBox
private readonly upstream: FeatureSourceForLayer;
private readonly state: { locationControl: UIEventSource<{ zoom: number }>; selectedElement: UIEventSource<any> };
private readonly state: {
locationControl: UIEventSource<{ zoom: number }>; selectedElement: UIEventSource<any>,
allElements: ElementStorage
};
constructor(
state: {
locationControl: UIEventSource<{ zoom: number }>,
selectedElement: UIEventSource<any>,
allElements: ElementStorage
},
tileIndex,
upstream: FeatureSourceForLayer
@ -30,23 +36,51 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti
this.layer = upstream.layer;
const layer = upstream.layer;
const self = this;
upstream.features.addCallback(() => {
this. update();
self.update();
});
layer.appliedFilters.addCallback(_ => {
this.update()
self.update()
})
this._is_dirty.stabilized(250).addCallbackAndRunD(dirty => {
if (dirty) {
self.update()
}
})
this.update();
}
public update() {
private readonly _alreadyRegistered = new Set<UIEventSource<any>>();
private readonly _is_dirty = new UIEventSource(false)
private registerCallback(feature: any, layer: LayerConfig) {
const src = this.state.allElements.addOrGetElement(feature)
if (this._alreadyRegistered.has(src)) {
return
}
this._alreadyRegistered.add(src)
if (layer.isShown !== undefined) {
const self = this;
src.map(tags => layer.isShown?.GetRenderValue(tags, "yes").txt).addCallbackAndRunD(isShown => {
self._is_dirty.setData(true)
})
}
}
public update() {
const self = this;
const layer = this.upstream.layer;
const features: { feature: any; freshness: Date }[] = this.upstream.features.data;
const newFeatures = features.filter((f) => {
self.registerCallback(f.feature, layer.layerDef)
if (
this.state.selectedElement.data?.id === f.feature.id ||
f.feature.id === Hash.hash.data) {
@ -79,6 +113,7 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti
});
this.features.setData(newFeatures);
this._is_dirty.setData(false)
}
}