Various fixes

This commit is contained in:
Pieter Vander Vennet 2021-12-07 17:46:57 +01:00
parent 18044ff22b
commit 07fd8f404a
14 changed files with 154 additions and 60 deletions

View file

@ -10,6 +10,10 @@ export class BBox {
readonly minLat: number;
readonly minLon: number;
/***
* Coordinates should be [[lon, lat],[lon, lat]]
* @param coordinates
*/
constructor(coordinates) {
this.maxLat = -90;
this.maxLon = -180;
@ -44,6 +48,21 @@ export class BBox {
}
return feature.bbox;
}
static bboxAroundAll(bboxes: BBox[]): BBox{
let maxLat: number = -90;
let maxLon: number= -180;
let minLat: number= 80;
let minLon: number= 180;
for (const bbox of bboxes) {
maxLat = Math.max(maxLat, bbox.maxLat)
maxLon = Math.max(maxLon, bbox.maxLon)
minLat = Math.min(minLat, bbox.minLat)
minLon = Math.min(minLon, bbox.minLon)
}
return new BBox([[maxLon, maxLat],[minLon,minLat]])
}
static fromTile(z: number, x: number, y: number): BBox {
return new BBox(Tiles.tile_bounds_lon_lat(z, x, y))

View file

@ -14,6 +14,7 @@ export interface ExtraFuncParams {
*/
getFeaturesWithin: (layerId: string, bbox: BBox) => any[][],
memberships: RelationsTracker
getFeatureById: (id:string) => any
}
/**
@ -79,20 +80,19 @@ class DistanceToFunc implements ExtraFunction {
}
if (typeof arg0 === "number") {
// Feature._lon and ._lat is conveniently place by one of the other metatags
return GeoOperations.distanceBetween([arg0, lat], [feature._lon, feature._lat]);
return GeoOperations.distanceBetween([arg0, lat], GeoOperations.centerpointCoordinates(feature));
}
if (typeof arg0 === "string") {
// This is an identifier
// TODO FIXME
const feature = undefined // State.state.allElements.ContainingFeatures.get(arg0);
const feature = featuresPerLayer.getFeatureById(arg0)
if (feature === undefined) {
return undefined;
}
arg0 = feature;
}
// arg0 is probably a feature
return GeoOperations.distanceBetween(GeoOperations.centerpointCoordinates(arg0), [feature._lon, feature._lat])
// arg0 is probably a geojsonfeature
return GeoOperations.distanceBetween(GeoOperations.centerpointCoordinates(arg0), GeoOperations.centerpointCoordinates(feature))
}
}

View file

@ -448,11 +448,12 @@ export default class FeaturePipeline {
window.setTimeout(
() => {
const layerDef = src.layer.layerDef;
const somethingChanged = MetaTagging.addMetatags(
MetaTagging.addMetatags(
src.features.data,
{
memberships: this.relationTracker,
getFeaturesWithin: (layerId, bbox: BBox) => self.GetFeaturesWithin(layerId, bbox)
getFeaturesWithin: (layerId, bbox: BBox) => self.GetFeaturesWithin(layerId, bbox),
getFeatureById: (id:string) => self.state.allElements.ContainingFeatures.get(id)
},
layerDef,
{

View file

@ -178,8 +178,6 @@ export default class MetaTagging {
try {
const functions = MetaTagging.createFunctionsForFeature(layer.id, calculatedTags)
ExtraFunctions.FullPatchFeature(params, feature);
for (const f of functions) {
f(feature);

View file

@ -8,6 +8,7 @@ import {UIEventSource} from "../UIEventSource";
import MapState from "./MapState";
import SelectedFeatureHandler from "../Actors/SelectedFeatureHandler";
import Hash from "../Web/Hash";
import {BBox} from "../BBox";
export default class FeaturePipelineState extends MapState {
@ -29,6 +30,8 @@ export default class FeaturePipelineState extends MapState {
clusterCounter.addTile(source)
const sourceBBox = source.features.map(allFeatures => BBox.bboxAroundAll(allFeatures.map(f => BBox.get(f.feature))))
// Do show features indicates if the 'showDataLayer' should be shown
const doShowFeatures = source.features.map(
f => {
@ -44,7 +47,7 @@ export default class FeaturePipelineState extends MapState {
return false;
}
if (!source.bbox.overlapsWith(bounds)) {
if (!sourceBBox.data.overlapsWith(bounds)) {
// Not within range -> features are hidden
return false
}
@ -81,7 +84,7 @@ export default class FeaturePipelineState extends MapState {
return true
}, [this.currentBounds, source.layer.isDisplayed]
}, [this.currentBounds, source.layer.isDisplayed, sourceBBox]
)
new ShowDataLayer(