Fix: improve functionality of GRB-theme (WIP)

This commit is contained in:
Pieter Vander Vennet 2023-05-24 03:26:33 +02:00
parent 66f2999422
commit b86e2910ba
10 changed files with 270 additions and 241 deletions

View file

@ -156,12 +156,14 @@ class IntersectionFunc implements ExtraFunction {
if (otherLayers.length === 0) {
continue
}
for (const otherFeature of otherLayers) {
const intersections = GeoOperations.LineIntersections(feat, <any> otherFeature)
if (intersections.length === 0) {
continue
for (const otherFeatures of otherLayers) {
for (const otherFeature of otherFeatures) {
const intersections = GeoOperations.LineIntersections(feat, <Feature<any, Record<string, string>>>otherFeature)
if (intersections.length === 0) {
continue
}
result.push({feat: otherFeature, intersections})
}
result.push({feat: otherFeature, intersections})
}
}

View file

@ -65,13 +65,13 @@ export default class GeoJsonSource implements FeatureSource {
return
}
this.LoadJSONFrom(url, eventsource, layer)
.then((_) => console.log("Loaded geojson " + url))
.then((fs) => console.log("Loaded",fs.length, "features from", url))
.catch((err) => console.error("Could not load ", url, "due to", err))
return true // data is loaded, we can safely unregister
})
} else {
this.LoadJSONFrom(url, eventsource, layer)
.then((_) => console.log("Loaded geojson " + url))
.then((fs) => console.log("Loaded",fs.length, "features from", url))
.catch((err) => console.error("Could not load ", url, "due to", err))
}
this.features = eventsource

View file

@ -1,17 +1,15 @@
import GeoJsonSource from "./GeoJsonSource"
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
import { FeatureSource } from "../FeatureSource"
import { Or } from "../../Tags/Or"
import {FeatureSource} from "../FeatureSource"
import {Or} from "../../Tags/Or"
import FeatureSwitchState from "../../State/FeatureSwitchState"
import OverpassFeatureSource from "./OverpassFeatureSource"
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
import {Store, UIEventSource} from "../../UIEventSource"
import OsmFeatureSource from "./OsmFeatureSource"
import FeatureSourceMerger from "./FeatureSourceMerger"
import DynamicGeoJsonTileSource from "../TiledFeatureSource/DynamicGeoJsonTileSource"
import { BBox } from "../../BBox"
import {BBox} from "../../BBox"
import LocalStorageFeatureSource from "../TiledFeatureSource/LocalStorageFeatureSource"
import StaticFeatureSource from "./StaticFeatureSource"
import { OsmPreferences } from "../../Osm/OsmPreferences"
/**
* This source will fetch the needed data from various sources for the given layout.
@ -123,6 +121,8 @@ export default class LayoutSource extends FeatureSourceMerger {
bounds,
backend,
isActive,
patchRelations: true
})
}

View file

@ -22,6 +22,7 @@ export default class OsmFeatureSource extends FeatureSourceMerger {
private readonly _downloadedTiles: Set<number> = new Set<number>()
private readonly _downloadedData: Feature[][] = []
private readonly _patchRelations: boolean;
/**
* Downloads data directly from the OSM-api within the given bounds.
* All features which match the TagsFilter 'allowedFeatures' are kept and converted into geojson
@ -33,7 +34,8 @@ export default class OsmFeatureSource extends FeatureSourceMerger {
/**
* If given: this featureSwitch will not update if the store contains 'false'
*/
isActive?: Store<boolean>
isActive?: Store<boolean>,
patchRelations?: true | boolean
}) {
super()
this._bounds = options.bounds
@ -41,6 +43,7 @@ export default class OsmFeatureSource extends FeatureSourceMerger {
this.isActive = options.isActive ?? new ImmutableStore(true)
this._backend = options.backend ?? "https://www.openstreetmap.org"
this._bounds.addCallbackAndRunD((bbox) => this.loadData(bbox))
this._patchRelations = options?.patchRelations ?? true
}
private async loadData(bbox: BBox) {
@ -78,13 +81,13 @@ export default class OsmFeatureSource extends FeatureSourceMerger {
* The requested tile might only contain part of the relation.
*
* This method will download the full relation and return it as geojson if it was incomplete.
* If the feature is already complete (or is not a relation), the feature will be returned
* If the feature is already complete (or is not a relation), the feature will be returned as is
*/
private async patchIncompleteRelations(
feature: { properties: { id: string } },
originalJson: { elements: { type: "node" | "way" | "relation"; id: number }[] }
): Promise<any> {
if (!feature.properties.id.startsWith("relation")) {
if (!feature.properties.id.startsWith("relation") || !this._patchRelations) {
return feature
}
const relationSpec = originalJson.elements.find(

View file

@ -25,6 +25,7 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
if (source.geojsonSource === undefined) {
throw "Invalid layer: geojsonSource expected"
}
console.log("Creating a dynamic geojson source for", layer.source.geojsonSource)
let whitelist = undefined
if (source.geojsonSource.indexOf("{x}_{y}.geojson") > 0) {