forked from MapComplete/MapComplete
		
	refactoring: more state splitting, basic layoutFeatureSource
This commit is contained in:
		
							parent
							
								
									8e2f04c0d0
								
							
						
					
					
						commit
						b94a8f5745
					
				
					 54 changed files with 1067 additions and 1969 deletions
				
			
		|  | @ -1,15 +1,15 @@ | ||||||
| import { ElementStorage } from "../ElementStorage" |  | ||||||
| import { Changes } from "../Osm/Changes" | import { Changes } from "../Osm/Changes" | ||||||
|  | import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"; | ||||||
| 
 | 
 | ||||||
| export default class ChangeToElementsActor { | export default class ChangeToElementsActor { | ||||||
|     constructor(changes: Changes, allElements: ElementStorage) { |     constructor(changes: Changes, allElements: FeaturePropertiesStore) { | ||||||
|         changes.pendingChanges.addCallbackAndRun((changes) => { |         changes.pendingChanges.addCallbackAndRun((changes) => { | ||||||
|             for (const change of changes) { |             for (const change of changes) { | ||||||
|                 const id = change.type + "/" + change.id |                 const id = change.type + "/" + change.id | ||||||
|                 if (!allElements.has(id)) { |                 if (!allElements.has(id)) { | ||||||
|                     continue // Ignored as the geometryFixer will introduce this
 |                     continue // Ignored as the geometryFixer will introduce this
 | ||||||
|                 } |                 } | ||||||
|                 const src = allElements.getEventSourceById(id) |                 const src = allElements.getStore(id) | ||||||
| 
 | 
 | ||||||
|                 let changed = false |                 let changed = false | ||||||
|                 for (const kv of change.tags ?? []) { |                 for (const kv of change.tags ?? []) { | ||||||
|  |  | ||||||
|  | @ -1,23 +1,19 @@ | ||||||
| import { Store, UIEventSource } from "../UIEventSource" | import { ImmutableStore, Store, UIEventSource } from "../UIEventSource" | ||||||
| import { Or } from "../Tags/Or" | import { Or } from "../Tags/Or" | ||||||
| import { Overpass } from "../Osm/Overpass" | import { Overpass } from "../Osm/Overpass" | ||||||
| import FeatureSource from "../FeatureSource/FeatureSource" | import FeatureSource from "../FeatureSource/FeatureSource" | ||||||
| import { Utils } from "../../Utils" | import { Utils } from "../../Utils" | ||||||
| import { TagsFilter } from "../Tags/TagsFilter" | import { TagsFilter } from "../Tags/TagsFilter" | ||||||
| import SimpleMetaTagger from "../SimpleMetaTagger" |  | ||||||
| import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" | import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" | ||||||
| import RelationsTracker from "../Osm/RelationsTracker" |  | ||||||
| import { BBox } from "../BBox" | import { BBox } from "../BBox" | ||||||
| import Loc from "../../Models/Loc" |  | ||||||
| import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | ||||||
| import Constants from "../../Models/Constants" |  | ||||||
| import TileFreshnessCalculator from "../FeatureSource/TileFreshnessCalculator" |  | ||||||
| import { Tiles } from "../../Models/TileRange" |  | ||||||
| import { Feature } from "geojson" | import { Feature } from "geojson" | ||||||
| 
 | 
 | ||||||
|  | /** | ||||||
|  |  * A wrapper around the 'Overpass'-object. | ||||||
|  |  * It has more logic and will automatically fetch the data for the right bbox and the active layers | ||||||
|  |  */ | ||||||
| export default class OverpassFeatureSource implements FeatureSource { | export default class OverpassFeatureSource implements FeatureSource { | ||||||
|     public readonly name = "OverpassFeatureSource" |  | ||||||
| 
 |  | ||||||
|     /** |     /** | ||||||
|      * The last loaded features, as geojson |      * The last loaded features, as geojson | ||||||
|      */ |      */ | ||||||
|  | @ -26,106 +22,67 @@ export default class OverpassFeatureSource implements FeatureSource { | ||||||
|     public readonly runningQuery: UIEventSource<boolean> = new UIEventSource<boolean>(false) |     public readonly runningQuery: UIEventSource<boolean> = new UIEventSource<boolean>(false) | ||||||
|     public readonly timeout: UIEventSource<number> = new UIEventSource<number>(0) |     public readonly timeout: UIEventSource<number> = new UIEventSource<number>(0) | ||||||
| 
 | 
 | ||||||
|     public readonly relationsTracker: RelationsTracker |  | ||||||
| 
 |  | ||||||
|     private readonly retries: UIEventSource<number> = new UIEventSource<number>(0) |     private readonly retries: UIEventSource<number> = new UIEventSource<number>(0) | ||||||
| 
 | 
 | ||||||
|     private readonly state: { |     private readonly state: { | ||||||
|         readonly locationControl: Store<Loc> |         readonly zoom: Store<number> | ||||||
|         readonly layoutToUse: LayoutConfig |         readonly layoutToUse: LayoutConfig | ||||||
|         readonly overpassUrl: Store<string[]> |         readonly overpassUrl: Store<string[]> | ||||||
|         readonly overpassTimeout: Store<number> |         readonly overpassTimeout: Store<number> | ||||||
|         readonly currentBounds: Store<BBox> |         readonly bounds: Store<BBox> | ||||||
|     } |     } | ||||||
|     private readonly _isActive: Store<boolean> |     private readonly _isActive: Store<boolean> | ||||||
|     /** |     private readonly padToZoomLevel?: Store<number> | ||||||
|      * Callback to handle all the data |     private _lastQueryBBox: BBox | ||||||
|      */ |  | ||||||
|     private readonly onBboxLoaded: ( |  | ||||||
|         bbox: BBox, |  | ||||||
|         date: Date, |  | ||||||
|         layers: LayerConfig[], |  | ||||||
|         zoomlevel: number |  | ||||||
|     ) => void |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * Keeps track of how fresh the data is |  | ||||||
|      * @private |  | ||||||
|      */ |  | ||||||
|     private readonly freshnesses: Map<string, TileFreshnessCalculator> |  | ||||||
| 
 | 
 | ||||||
|     constructor( |     constructor( | ||||||
|         state: { |         state: { | ||||||
|             readonly locationControl: Store<Loc> |  | ||||||
|             readonly layoutToUse: LayoutConfig |             readonly layoutToUse: LayoutConfig | ||||||
|  |             readonly zoom: Store<number> | ||||||
|             readonly overpassUrl: Store<string[]> |             readonly overpassUrl: Store<string[]> | ||||||
|             readonly overpassTimeout: Store<number> |             readonly overpassTimeout: Store<number> | ||||||
|             readonly overpassMaxZoom: Store<number> |             readonly overpassMaxZoom: Store<number> | ||||||
|             readonly currentBounds: Store<BBox> |             readonly bounds: Store<BBox> | ||||||
|         }, |         }, | ||||||
|         options: { |         options?: { | ||||||
|             padToTiles: Store<number> |             padToTiles?: Store<number> | ||||||
|             isActive?: Store<boolean> |             isActive?: Store<boolean> | ||||||
|             relationTracker: RelationsTracker |  | ||||||
|             onBboxLoaded?: ( |  | ||||||
|                 bbox: BBox, |  | ||||||
|                 date: Date, |  | ||||||
|                 layers: LayerConfig[], |  | ||||||
|                 zoomlevel: number |  | ||||||
|             ) => void |  | ||||||
|             freshnesses?: Map<string, TileFreshnessCalculator> |  | ||||||
|         } |         } | ||||||
|     ) { |     ) { | ||||||
|         this.state = state |         this.state = state | ||||||
|         this._isActive = options.isActive |         this._isActive = options?.isActive ?? new ImmutableStore(true) | ||||||
|         this.onBboxLoaded = options.onBboxLoaded |         this.padToZoomLevel = options?.padToTiles | ||||||
|         this.relationsTracker = options.relationTracker |  | ||||||
|         this.freshnesses = options.freshnesses |  | ||||||
|         const self = this |         const self = this | ||||||
|         state.currentBounds.addCallback((_) => { |         state.bounds.addCallbackD((_) => { | ||||||
|             self.update(options.padToTiles.data) |             self.updateAsyncIfNeeded() | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Creates the 'Overpass'-object for the given layers | ||||||
|  |      * @param interpreterUrl | ||||||
|  |      * @param layersToDownload | ||||||
|  |      * @constructor | ||||||
|  |      * @private | ||||||
|  |      */ | ||||||
|     private GetFilter(interpreterUrl: string, layersToDownload: LayerConfig[]): Overpass { |     private GetFilter(interpreterUrl: string, layersToDownload: LayerConfig[]): Overpass { | ||||||
|         let filters: TagsFilter[] = [] |         let filters: TagsFilter[] = layersToDownload.map((layer) => layer.source.osmTags) | ||||||
|         let extraScripts: string[] = [] |  | ||||||
|         for (const layer of layersToDownload) { |  | ||||||
|             if (layer.source.overpassScript !== undefined) { |  | ||||||
|                 extraScripts.push(layer.source.overpassScript) |  | ||||||
|             } else { |  | ||||||
|                 filters.push(layer.source.osmTags) |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         filters = Utils.NoNull(filters) |         filters = Utils.NoNull(filters) | ||||||
|         extraScripts = Utils.NoNull(extraScripts) |         if (filters.length === 0) { | ||||||
|         if (filters.length + extraScripts.length === 0) { |  | ||||||
|             return undefined |             return undefined | ||||||
|         } |         } | ||||||
|         return new Overpass( |         return new Overpass(new Or(filters), [], interpreterUrl, this.state.overpassTimeout) | ||||||
|             new Or(filters), |  | ||||||
|             extraScripts, |  | ||||||
|             interpreterUrl, |  | ||||||
|             this.state.overpassTimeout, |  | ||||||
|             this.relationsTracker |  | ||||||
|         ) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private update(paddedZoomLevel: number) { |     /** | ||||||
|         if (!this._isActive.data) { |      * | ||||||
|  |      * @private | ||||||
|  |      */ | ||||||
|  |     private async updateAsyncIfNeeded(): Promise<void> { | ||||||
|  |         if (!this._isActive?.data) { | ||||||
|  |             console.log("OverpassFeatureSource: not triggering as not active") | ||||||
|             return |             return | ||||||
|         } |         } | ||||||
|         const self = this |  | ||||||
|         this.updateAsync(paddedZoomLevel).then((bboxDate) => { |  | ||||||
|             if (bboxDate === undefined || self.onBboxLoaded === undefined) { |  | ||||||
|                 return |  | ||||||
|             } |  | ||||||
|             const [bbox, date, layers] = bboxDate |  | ||||||
|             self.onBboxLoaded(bbox, date, layers, paddedZoomLevel) |  | ||||||
|         }) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private async updateAsync(padToZoomLevel: number): Promise<[BBox, Date, LayerConfig[]]> { |  | ||||||
|         if (this.runningQuery.data) { |         if (this.runningQuery.data) { | ||||||
|             console.log("Still running a query, not updating") |             console.log("Still running a query, not updating") | ||||||
|             return undefined |             return undefined | ||||||
|  | @ -135,15 +92,27 @@ export default class OverpassFeatureSource implements FeatureSource { | ||||||
|             console.log("Still in timeout - not updating") |             console.log("Still in timeout - not updating") | ||||||
|             return undefined |             return undefined | ||||||
|         } |         } | ||||||
|  |         const requestedBounds = this.state.bounds.data | ||||||
|  |         if ( | ||||||
|  |             this._lastQueryBBox !== undefined && | ||||||
|  |             requestedBounds.isContainedIn(this._lastQueryBBox) | ||||||
|  |         ) { | ||||||
|  |             return undefined | ||||||
|  |         } | ||||||
|  |         const [bounds, date, updatedLayers] = await this.updateAsync() | ||||||
|  |         this._lastQueryBBox = bounds | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Download the relevant data from overpass. Attempt to use a different server; only downloads the relevant layers | ||||||
|  |      * @private | ||||||
|  |      */ | ||||||
|  |     private async updateAsync(): Promise<[BBox, Date, LayerConfig[]]> { | ||||||
|         let data: any = undefined |         let data: any = undefined | ||||||
|         let date: Date = undefined |         let date: Date = undefined | ||||||
|         let lastUsed = 0 |         let lastUsed = 0 | ||||||
| 
 | 
 | ||||||
|         const layersToDownload = [] |         const layersToDownload = [] | ||||||
|         const neededTiles = this.state.currentBounds.data |  | ||||||
|             .expandToTileBounds(padToZoomLevel) |  | ||||||
|             .containingTileRange(padToZoomLevel) |  | ||||||
|         for (const layer of this.state.layoutToUse.layers) { |         for (const layer of this.state.layoutToUse.layers) { | ||||||
|             if (typeof layer === "string") { |             if (typeof layer === "string") { | ||||||
|                 throw "A layer was not expanded!" |                 throw "A layer was not expanded!" | ||||||
|  | @ -151,7 +120,7 @@ export default class OverpassFeatureSource implements FeatureSource { | ||||||
|             if (layer.source === undefined) { |             if (layer.source === undefined) { | ||||||
|                 continue |                 continue | ||||||
|             } |             } | ||||||
|             if (this.state.locationControl.data.zoom < layer.minzoom) { |             if (this.state.zoom.data < layer.minzoom) { | ||||||
|                 continue |                 continue | ||||||
|             } |             } | ||||||
|             if (layer.doNotDownload) { |             if (layer.doNotDownload) { | ||||||
|  | @ -161,31 +130,10 @@ export default class OverpassFeatureSource implements FeatureSource { | ||||||
|                 // Not our responsibility to download this layer!
 |                 // Not our responsibility to download this layer!
 | ||||||
|                 continue |                 continue | ||||||
|             } |             } | ||||||
|             const freshness = this.freshnesses?.get(layer.id) |  | ||||||
|             if (freshness !== undefined) { |  | ||||||
|                 const oldestDataDate = |  | ||||||
|                     Math.min( |  | ||||||
|                         ...Tiles.MapRange(neededTiles, (x, y) => { |  | ||||||
|                             const date = freshness.freshnessFor(padToZoomLevel, x, y) |  | ||||||
|                             if (date === undefined) { |  | ||||||
|                                 return 0 |  | ||||||
|                             } |  | ||||||
|                             return date.getTime() |  | ||||||
|                         }) |  | ||||||
|                     ) / 1000 |  | ||||||
|                 const now = new Date().getTime() |  | ||||||
|                 const minRequiredAge = now / 1000 - layer.maxAgeOfCache |  | ||||||
|                 if (oldestDataDate >= minRequiredAge) { |  | ||||||
|                     // still fresh enough - not updating
 |  | ||||||
|                     continue |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             layersToDownload.push(layer) |             layersToDownload.push(layer) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (layersToDownload.length == 0) { |         if (layersToDownload.length == 0) { | ||||||
|             console.debug("Not updating - no layers needed") |  | ||||||
|             return |             return | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -194,12 +142,13 @@ export default class OverpassFeatureSource implements FeatureSource { | ||||||
|         if (overpassUrls === undefined || overpassUrls.length === 0) { |         if (overpassUrls === undefined || overpassUrls.length === 0) { | ||||||
|             throw "Panic: overpassFeatureSource didn't receive any overpassUrls" |             throw "Panic: overpassFeatureSource didn't receive any overpassUrls" | ||||||
|         } |         } | ||||||
|  |         // Note: the bounds are updated between attempts, in case that the user zoomed around
 | ||||||
|         let bounds: BBox |         let bounds: BBox | ||||||
|         do { |         do { | ||||||
|             try { |             try { | ||||||
|                 bounds = this.state.currentBounds.data |                 bounds = this.state.bounds.data | ||||||
|                     ?.pad(this.state.layoutToUse.widenFactor) |                     ?.pad(this.state.layoutToUse.widenFactor) | ||||||
|                     ?.expandToTileBounds(padToZoomLevel) |                     ?.expandToTileBounds(this.padToZoomLevel?.data) | ||||||
| 
 | 
 | ||||||
|                 if (bounds === undefined) { |                 if (bounds === undefined) { | ||||||
|                     return undefined |                     return undefined | ||||||
|  | @ -228,7 +177,6 @@ export default class OverpassFeatureSource implements FeatureSource { | ||||||
| 
 | 
 | ||||||
|                     while (self.timeout.data > 0) { |                     while (self.timeout.data > 0) { | ||||||
|                         await Utils.waitFor(1000) |                         await Utils.waitFor(1000) | ||||||
|                         console.log(self.timeout.data) |  | ||||||
|                         self.timeout.data-- |                         self.timeout.data-- | ||||||
|                         self.timeout.ping() |                         self.timeout.ping() | ||||||
|                     } |                     } | ||||||
|  | @ -240,14 +188,7 @@ export default class OverpassFeatureSource implements FeatureSource { | ||||||
|             if (data === undefined) { |             if (data === undefined) { | ||||||
|                 return undefined |                 return undefined | ||||||
|             } |             } | ||||||
|             data.features.forEach((feature) => |             self.features.setData(data.features) | ||||||
|                 SimpleMetaTagger.objectMetaInfo.applyMetaTagsOnFeature( |  | ||||||
|                     feature, |  | ||||||
|                     undefined, |  | ||||||
|                     this.state |  | ||||||
|                 ) |  | ||||||
|             ) |  | ||||||
|             self.features.setData(data.features.map((f) => ({ feature: f, freshness: date }))) |  | ||||||
|             return [bounds, date, layersToDownload] |             return [bounds, date, layersToDownload] | ||||||
|         } catch (e) { |         } catch (e) { | ||||||
|             console.error("Got the overpass response, but could not process it: ", e, e.stack) |             console.error("Got the overpass response, but could not process it: ", e, e.stack) | ||||||
|  |  | ||||||
|  | @ -2,12 +2,13 @@ | ||||||
|  * This actor will download the latest version of the selected element from OSM and update the tags if necessary. |  * This actor will download the latest version of the selected element from OSM and update the tags if necessary. | ||||||
|  */ |  */ | ||||||
| import { UIEventSource } from "../UIEventSource" | import { UIEventSource } from "../UIEventSource" | ||||||
| import { ElementStorage } from "../ElementStorage" |  | ||||||
| import { Changes } from "../Osm/Changes" | import { Changes } from "../Osm/Changes" | ||||||
| import { OsmObject } from "../Osm/OsmObject" | import { OsmObject } from "../Osm/OsmObject" | ||||||
| import { OsmConnection } from "../Osm/OsmConnection" | import { OsmConnection } from "../Osm/OsmConnection" | ||||||
| import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" | import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" | ||||||
| import SimpleMetaTagger from "../SimpleMetaTagger" | import SimpleMetaTagger from "../SimpleMetaTagger" | ||||||
|  | import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore" | ||||||
|  | import { Feature } from "geojson" | ||||||
| 
 | 
 | ||||||
| export default class SelectedElementTagsUpdater { | export default class SelectedElementTagsUpdater { | ||||||
|     private static readonly metatags = new Set([ |     private static readonly metatags = new Set([ | ||||||
|  | @ -19,28 +20,34 @@ export default class SelectedElementTagsUpdater { | ||||||
|         "id", |         "id", | ||||||
|     ]) |     ]) | ||||||
| 
 | 
 | ||||||
|  |     private readonly state: { | ||||||
|  |         selectedElement: UIEventSource<Feature> | ||||||
|  |         allElements: FeaturePropertiesStore | ||||||
|  |         changes: Changes | ||||||
|  |         osmConnection: OsmConnection | ||||||
|  |         layoutToUse: LayoutConfig | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     constructor(state: { |     constructor(state: { | ||||||
|         selectedElement: UIEventSource<any> |         selectedElement: UIEventSource<Feature> | ||||||
|         allElements: ElementStorage |         allElements: FeaturePropertiesStore | ||||||
|         changes: Changes |         changes: Changes | ||||||
|         osmConnection: OsmConnection |         osmConnection: OsmConnection | ||||||
|         layoutToUse: LayoutConfig |         layoutToUse: LayoutConfig | ||||||
|     }) { |     }) { | ||||||
|  |         this.state = state | ||||||
|         state.osmConnection.isLoggedIn.addCallbackAndRun((isLoggedIn) => { |         state.osmConnection.isLoggedIn.addCallbackAndRun((isLoggedIn) => { | ||||||
|             if (isLoggedIn) { |             if (!isLoggedIn) { | ||||||
|                 SelectedElementTagsUpdater.installCallback(state) |                 return | ||||||
|                 return true |  | ||||||
|             } |             } | ||||||
|  |             this.installCallback() | ||||||
|  |             // We only have to do this once...
 | ||||||
|  |             return true | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static installCallback(state: { |     private installCallback() { | ||||||
|         selectedElement: UIEventSource<any> |         const state = this.state | ||||||
|         allElements: ElementStorage |  | ||||||
|         changes: Changes |  | ||||||
|         osmConnection: OsmConnection |  | ||||||
|         layoutToUse: LayoutConfig |  | ||||||
|     }) { |  | ||||||
|         state.selectedElement.addCallbackAndRunD(async (s) => { |         state.selectedElement.addCallbackAndRunD(async (s) => { | ||||||
|             let id = s.properties?.id |             let id = s.properties?.id | ||||||
| 
 | 
 | ||||||
|  | @ -62,7 +69,7 @@ export default class SelectedElementTagsUpdater { | ||||||
|                 const latestTags = await OsmObject.DownloadPropertiesOf(id) |                 const latestTags = await OsmObject.DownloadPropertiesOf(id) | ||||||
|                 if (latestTags === "deleted") { |                 if (latestTags === "deleted") { | ||||||
|                     console.warn("The current selected element has been deleted upstream!") |                     console.warn("The current selected element has been deleted upstream!") | ||||||
|                     const currentTagsSource = state.allElements.getEventSourceById(id) |                     const currentTagsSource = state.allElements.getStore(id) | ||||||
|                     if (currentTagsSource.data["_deleted"] === "yes") { |                     if (currentTagsSource.data["_deleted"] === "yes") { | ||||||
|                         return |                         return | ||||||
|                     } |                     } | ||||||
|  | @ -70,25 +77,15 @@ export default class SelectedElementTagsUpdater { | ||||||
|                     currentTagsSource.ping() |                     currentTagsSource.ping() | ||||||
|                     return |                     return | ||||||
|                 } |                 } | ||||||
|                 SelectedElementTagsUpdater.applyUpdate(state, latestTags, id) |                 this.applyUpdate(latestTags, id) | ||||||
|                 console.log("Updated", id) |                 console.log("Updated", id) | ||||||
|             } catch (e) { |             } catch (e) { | ||||||
|                 console.warn("Could not update", id, " due to", e) |                 console.warn("Could not update", id, " due to", e) | ||||||
|             } |             } | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 |     private applyUpdate(latestTags: any, id: string) { | ||||||
|     public static applyUpdate( |         const state = this.state | ||||||
|         state: { |  | ||||||
|             selectedElement: UIEventSource<any> |  | ||||||
|             allElements: ElementStorage |  | ||||||
|             changes: Changes |  | ||||||
|             osmConnection: OsmConnection |  | ||||||
|             layoutToUse: LayoutConfig |  | ||||||
|         }, |  | ||||||
|         latestTags: any, |  | ||||||
|         id: string |  | ||||||
|     ) { |  | ||||||
|         try { |         try { | ||||||
|             const leftRightSensitive = state.layoutToUse.isLeftRightSensitive() |             const leftRightSensitive = state.layoutToUse.isLeftRightSensitive() | ||||||
| 
 | 
 | ||||||
|  | @ -115,7 +112,7 @@ export default class SelectedElementTagsUpdater { | ||||||
| 
 | 
 | ||||||
|             // With the changes applied, we merge them onto the upstream object
 |             // With the changes applied, we merge them onto the upstream object
 | ||||||
|             let somethingChanged = false |             let somethingChanged = false | ||||||
|             const currentTagsSource = state.allElements.getEventSourceById(id) |             const currentTagsSource = state.allElements.getStore(id) | ||||||
|             const currentTags = currentTagsSource.data |             const currentTags = currentTagsSource.data | ||||||
|             for (const key in latestTags) { |             for (const key in latestTags) { | ||||||
|                 let osmValue = latestTags[key] |                 let osmValue = latestTags[key] | ||||||
|  | @ -135,7 +132,7 @@ export default class SelectedElementTagsUpdater { | ||||||
|                 if (currentKey.startsWith("_")) { |                 if (currentKey.startsWith("_")) { | ||||||
|                     continue |                     continue | ||||||
|                 } |                 } | ||||||
|                 if (this.metatags.has(currentKey)) { |                 if (SelectedElementTagsUpdater.metatags.has(currentKey)) { | ||||||
|                     continue |                     continue | ||||||
|                 } |                 } | ||||||
|                 if (currentKey in latestTags) { |                 if (currentKey in latestTags) { | ||||||
|  |  | ||||||
|  | @ -214,6 +214,9 @@ export class BBox { | ||||||
|      * @param zoomlevel |      * @param zoomlevel | ||||||
|      */ |      */ | ||||||
|     expandToTileBounds(zoomlevel: number): BBox { |     expandToTileBounds(zoomlevel: number): BBox { | ||||||
|  |         if(zoomlevel === undefined){ | ||||||
|  |             return this | ||||||
|  |         } | ||||||
|         const ul = Tiles.embedded_tile(this.minLat, this.minLon, zoomlevel) |         const ul = Tiles.embedded_tile(this.minLat, this.minLon, zoomlevel) | ||||||
|         const lr = Tiles.embedded_tile(this.maxLat, this.maxLon, zoomlevel) |         const lr = Tiles.embedded_tile(this.maxLat, this.maxLon, zoomlevel) | ||||||
|         const boundsul = Tiles.tile_bounds_lon_lat(ul.z, ul.x, ul.y) |         const boundsul = Tiles.tile_bounds_lon_lat(ul.z, ul.x, ul.y) | ||||||
|  |  | ||||||
|  | @ -1,120 +0,0 @@ | ||||||
| /** |  | ||||||
|  * Keeps track of a dictionary 'elementID' -> UIEventSource<tags> |  | ||||||
|  */ |  | ||||||
| import { UIEventSource } from "./UIEventSource" |  | ||||||
| import { GeoJSONObject } from "@turf/turf" |  | ||||||
| import { Feature, Geometry, Point } from "geojson" |  | ||||||
| import { OsmTags } from "../Models/OsmFeature" |  | ||||||
| 
 |  | ||||||
| export class ElementStorage { |  | ||||||
|     public ContainingFeatures = new Map<string, Feature<Geometry, OsmTags>>() |  | ||||||
|     private _elements = new Map<string, UIEventSource<any>>() |  | ||||||
| 
 |  | ||||||
|     constructor() {} |  | ||||||
| 
 |  | ||||||
|     addElementById(id: string, eventSource: UIEventSource<any>) { |  | ||||||
|         this._elements.set(id, eventSource) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * Creates a UIEventSource for the tags of the given feature. |  | ||||||
|      * If an UIEventsource has been created previously, the same UIEventSource will be returned |  | ||||||
|      * |  | ||||||
|      * Note: it will cleverly merge the tags, if needed |  | ||||||
|      */ |  | ||||||
|     addOrGetElement(feature: Feature<Geometry, OsmTags>): UIEventSource<any> { |  | ||||||
|         const elementId = feature.properties.id |  | ||||||
|         const newProperties = feature.properties |  | ||||||
| 
 |  | ||||||
|         const es = this.addOrGetById(elementId, newProperties) |  | ||||||
| 
 |  | ||||||
|         // At last, we overwrite the tag of the new feature to use the tags in the already existing event source
 |  | ||||||
|         feature.properties = es.data |  | ||||||
| 
 |  | ||||||
|         if (!this.ContainingFeatures.has(elementId)) { |  | ||||||
|             this.ContainingFeatures.set(elementId, feature) |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return es |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     getEventSourceById(elementId): UIEventSource<any> { |  | ||||||
|         if (elementId === undefined) { |  | ||||||
|             return undefined |  | ||||||
|         } |  | ||||||
|         return this._elements.get(elementId) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     has(id) { |  | ||||||
|         return this._elements.has(id) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     addAlias(oldId: string, newId: string) { |  | ||||||
|         if (newId === undefined) { |  | ||||||
|             // We removed the node/way/relation with type 'type' and id 'oldId' on openstreetmap!
 |  | ||||||
|             const element = this.getEventSourceById(oldId) |  | ||||||
|             element.data._deleted = "yes" |  | ||||||
|             element.ping() |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (oldId == newId) { |  | ||||||
|             return undefined |  | ||||||
|         } |  | ||||||
|         const element = this.getEventSourceById(oldId) |  | ||||||
|         if (element === undefined) { |  | ||||||
|             // Element to rewrite not found, probably a node or relation that is not rendered
 |  | ||||||
|             return undefined |  | ||||||
|         } |  | ||||||
|         element.data.id = newId |  | ||||||
|         this.addElementById(newId, element) |  | ||||||
|         this.ContainingFeatures.set(newId, this.ContainingFeatures.get(oldId)) |  | ||||||
|         element.ping() |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private addOrGetById(elementId: string, newProperties: any): UIEventSource<any> { |  | ||||||
|         if (!this._elements.has(elementId)) { |  | ||||||
|             const eventSource = new UIEventSource<any>(newProperties, "tags of " + elementId) |  | ||||||
|             this._elements.set(elementId, eventSource) |  | ||||||
|             return eventSource |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         const es = this._elements.get(elementId) |  | ||||||
|         if (es.data == newProperties) { |  | ||||||
|             // Reference comparison gives the same object! we can just return the event source
 |  | ||||||
|             return es |  | ||||||
|         } |  | ||||||
|         const keptKeys = es.data |  | ||||||
|         // The element already exists
 |  | ||||||
|         // We use the new feature to overwrite all the properties in the already existing eventsource
 |  | ||||||
|         const debug_msg = [] |  | ||||||
|         let somethingChanged = false |  | ||||||
|         for (const k in newProperties) { |  | ||||||
|             if (!newProperties.hasOwnProperty(k)) { |  | ||||||
|                 continue |  | ||||||
|             } |  | ||||||
|             const v = newProperties[k] |  | ||||||
| 
 |  | ||||||
|             if (keptKeys[k] !== v) { |  | ||||||
|                 if (v === undefined) { |  | ||||||
|                     // The new value is undefined; the tag might have been removed
 |  | ||||||
|                     // It might be a metatag as well
 |  | ||||||
|                     // In the latter case, we do keep the tag!
 |  | ||||||
|                     if (!k.startsWith("_")) { |  | ||||||
|                         delete keptKeys[k] |  | ||||||
|                         debug_msg.push("Erased " + k) |  | ||||||
|                     } |  | ||||||
|                 } else { |  | ||||||
|                     keptKeys[k] = v |  | ||||||
|                     debug_msg.push(k + " --> " + v) |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 somethingChanged = true |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (somethingChanged) { |  | ||||||
|             es.ping() |  | ||||||
|         } |  | ||||||
|         return es |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | @ -14,7 +14,6 @@ export interface ExtraFuncParams { | ||||||
|      * Format: [ [ geojson, geojson, geojson, ... ], [geojson, ...], ...] |      * Format: [ [ geojson, geojson, geojson, ... ], [geojson, ...], ...] | ||||||
|      */ |      */ | ||||||
|     getFeaturesWithin: (layerId: string, bbox: BBox) => Feature<Geometry, { id: string }>[][] |     getFeaturesWithin: (layerId: string, bbox: BBox) => Feature<Geometry, { id: string }>[][] | ||||||
|     memberships: RelationsTracker |  | ||||||
|     getFeatureById: (id: string) => Feature<Geometry, { id: string }> |     getFeatureById: (id: string) => Feature<Geometry, { id: string }> | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -401,19 +400,6 @@ class ClosestNObjectFunc implements ExtraFunction { | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class Memberships implements ExtraFunction { |  | ||||||
|     _name = "memberships" |  | ||||||
|     _doc = |  | ||||||
|         "Gives a list of `{role: string, relation: Relation}`-objects, containing all the relations that this feature is part of. " + |  | ||||||
|         "\n\n" + |  | ||||||
|         "For example: `_part_of_walking_routes=feat.memberships().map(r => r.relation.tags.name).join(';')`" |  | ||||||
|     _args = [] |  | ||||||
| 
 |  | ||||||
|     _f(params, feat) { |  | ||||||
|         return () => params.memberships.knownRelations.data.get(feat.properties.id) ?? [] |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| class GetParsed implements ExtraFunction { | class GetParsed implements ExtraFunction { | ||||||
|     _name = "get" |     _name = "get" | ||||||
|     _doc = |     _doc = | ||||||
|  | @ -481,7 +467,6 @@ export class ExtraFunctions { | ||||||
|         new IntersectionFunc(), |         new IntersectionFunc(), | ||||||
|         new ClosestObjectFunc(), |         new ClosestObjectFunc(), | ||||||
|         new ClosestNObjectFunc(), |         new ClosestNObjectFunc(), | ||||||
|         new Memberships(), |  | ||||||
|         new GetParsed(), |         new GetParsed(), | ||||||
|     ] |     ] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										107
									
								
								Logic/FeatureSource/Actors/FeaturePropertiesStore.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								Logic/FeatureSource/Actors/FeaturePropertiesStore.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,107 @@ | ||||||
|  | import FeatureSource, { IndexedFeatureSource } from "../FeatureSource" | ||||||
|  | import { UIEventSource } from "../../UIEventSource" | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Constructs a UIEventStore for the properties of every Feature, indexed by id | ||||||
|  |  */ | ||||||
|  | export default class FeaturePropertiesStore { | ||||||
|  |     private readonly _source: FeatureSource & IndexedFeatureSource | ||||||
|  |     private readonly _elements = new Map<string, UIEventSource<any>>() | ||||||
|  | 
 | ||||||
|  |     constructor(source: FeatureSource & IndexedFeatureSource) { | ||||||
|  |         this._source = source | ||||||
|  |         const self = this | ||||||
|  |         source.features.addCallbackAndRunD((features) => { | ||||||
|  |             for (const feature of features) { | ||||||
|  |                 const id = feature.properties.id | ||||||
|  |                 if (id === undefined) { | ||||||
|  |                     console.trace("Error: feature without ID:", feature) | ||||||
|  |                     throw "Error: feature without ID" | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 const source = self._elements.get(id) | ||||||
|  |                 if (source === undefined) { | ||||||
|  |                     self._elements.set(id, new UIEventSource<any>(feature.properties)) | ||||||
|  |                     continue | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 if (source.data === feature.properties) { | ||||||
|  |                     continue | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 // Update the tags in the old store and link them
 | ||||||
|  |                 const changeMade = FeaturePropertiesStore.mergeTags(source.data, feature.properties) | ||||||
|  |                 feature.properties = source.data | ||||||
|  |                 if (changeMade) { | ||||||
|  |                     source.ping() | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public getStore(id: string): UIEventSource<Record<string, string>> { | ||||||
|  |         return this._elements.get(id) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Overwrites the tags of the old properties object, returns true if a change was made. | ||||||
|  |      * Metatags are overriden if they are in the new properties, but not removed | ||||||
|  |      * @param oldProperties | ||||||
|  |      * @param newProperties | ||||||
|  |      * @private | ||||||
|  |      */ | ||||||
|  |     private static mergeTags( | ||||||
|  |         oldProperties: Record<string, any>, | ||||||
|  |         newProperties: Record<string, any> | ||||||
|  |     ): boolean { | ||||||
|  |         let changeMade = false | ||||||
|  | 
 | ||||||
|  |         for (const oldPropertiesKey in oldProperties) { | ||||||
|  |             // Delete properties from the old record if it is not in the new store anymore
 | ||||||
|  |             if (oldPropertiesKey.startsWith("_")) { | ||||||
|  |                 continue | ||||||
|  |             } | ||||||
|  |             if (newProperties[oldPropertiesKey] === undefined) { | ||||||
|  |                 changeMade = true | ||||||
|  |                 delete oldProperties[oldPropertiesKey] | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // Copy all properties from the new record into the old
 | ||||||
|  |         for (const newPropertiesKey in newProperties) { | ||||||
|  |             const v = newProperties[newPropertiesKey] | ||||||
|  |             if (oldProperties[newPropertiesKey] !== v) { | ||||||
|  |                 oldProperties[newPropertiesKey] = v | ||||||
|  |                 changeMade = true | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return changeMade | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     addAlias(oldId: string, newId: string): void { | ||||||
|  |         if (newId === undefined) { | ||||||
|  |             // We removed the node/way/relation with type 'type' and id 'oldId' on openstreetmap!
 | ||||||
|  |             const element = this._elements.get(oldId) | ||||||
|  |             element.data._deleted = "yes" | ||||||
|  |             element.ping() | ||||||
|  |             return | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (oldId == newId) { | ||||||
|  |             return | ||||||
|  |         } | ||||||
|  |         const element = this._elements.get(oldId) | ||||||
|  |         if (element === undefined) { | ||||||
|  |             // Element to rewrite not found, probably a node or relation that is not rendered
 | ||||||
|  |             return | ||||||
|  |         } | ||||||
|  |         element.data.id = newId | ||||||
|  |         this._elements.set(newId, element) | ||||||
|  |         element.ping() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     has(id: string) { | ||||||
|  |         return this._elements.has(id) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -1,6 +1,5 @@ | ||||||
| import { FeatureSourceForLayer, Tiled } from "../FeatureSource" | import { FeatureSourceForLayer, Tiled } from "../FeatureSource" | ||||||
| import MetaTagging from "../../MetaTagging" | import MetaTagging from "../../MetaTagging" | ||||||
| import { ElementStorage } from "../../ElementStorage" |  | ||||||
| import { ExtraFuncParams } from "../../ExtraFunctions" | import { ExtraFuncParams } from "../../ExtraFunctions" | ||||||
| import FeaturePipeline from "../FeaturePipeline" | import FeaturePipeline from "../FeaturePipeline" | ||||||
| import { BBox } from "../../BBox" | import { BBox } from "../../BBox" | ||||||
|  | @ -39,7 +38,6 @@ class MetatagUpdater { | ||||||
|                 } |                 } | ||||||
|                 return featurePipeline.GetFeaturesWithin(layerId, bbox) |                 return featurePipeline.GetFeaturesWithin(layerId, bbox) | ||||||
|             }, |             }, | ||||||
|             memberships: featurePipeline.relationTracker, |  | ||||||
|         } |         } | ||||||
|         this.isDirty.stabilized(100).addCallback((dirty) => { |         this.isDirty.stabilized(100).addCallback((dirty) => { | ||||||
|             if (dirty) { |             if (dirty) { | ||||||
|  |  | ||||||
|  | @ -1,20 +0,0 @@ | ||||||
| import FeatureSource from "../FeatureSource"; |  | ||||||
| import { Store } from "../../UIEventSource"; |  | ||||||
| import { ElementStorage } from "../../ElementStorage"; |  | ||||||
| import { Feature } from "geojson"; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Makes sure that every feature is added to the ElementsStorage, so that the tags-eventsource can be retrieved |  | ||||||
|  */ |  | ||||||
| export default class RegisteringAllFromFeatureSourceActor { |  | ||||||
|     public readonly features: Store<Feature[]> |  | ||||||
| 
 |  | ||||||
|     constructor(source: FeatureSource, allElements: ElementStorage) { |  | ||||||
|         this.features = source.features |  | ||||||
|         this.features.addCallbackAndRunD((features) => { |  | ||||||
|             for (const feature of features) { |  | ||||||
|                 allElements.addOrGetElement(<any> feature) |  | ||||||
|             } |  | ||||||
|         }) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | @ -13,16 +13,18 @@ import RegisteringAllFromFeatureSourceActor from "./Actors/RegisteringAllFromFea | ||||||
| import SaveTileToLocalStorageActor from "./Actors/SaveTileToLocalStorageActor" | import SaveTileToLocalStorageActor from "./Actors/SaveTileToLocalStorageActor" | ||||||
| import DynamicGeoJsonTileSource from "./TiledFeatureSource/DynamicGeoJsonTileSource" | import DynamicGeoJsonTileSource from "./TiledFeatureSource/DynamicGeoJsonTileSource" | ||||||
| import { TileHierarchyMerger } from "./TiledFeatureSource/TileHierarchyMerger" | import { TileHierarchyMerger } from "./TiledFeatureSource/TileHierarchyMerger" | ||||||
| import RelationsTracker from "../Osm/RelationsTracker" |  | ||||||
| import { NewGeometryFromChangesFeatureSource } from "./Sources/NewGeometryFromChangesFeatureSource" | import { NewGeometryFromChangesFeatureSource } from "./Sources/NewGeometryFromChangesFeatureSource" | ||||||
| import ChangeGeometryApplicator from "./Sources/ChangeGeometryApplicator" | import ChangeGeometryApplicator from "./Sources/ChangeGeometryApplicator" | ||||||
|  | /** | ||||||
|  |  * Keeps track of the age of the loaded data. | ||||||
|  |  * Has one freshness-Calculator for every layer | ||||||
|  |  * @private | ||||||
|  |  */ | ||||||
| import { BBox } from "../BBox" | import { BBox } from "../BBox" | ||||||
| import OsmFeatureSource from "./TiledFeatureSource/OsmFeatureSource" | import OsmFeatureSource from "./TiledFeatureSource/OsmFeatureSource" | ||||||
| import { Tiles } from "../../Models/TileRange" | import { Tiles } from "../../Models/TileRange" | ||||||
| import TileFreshnessCalculator from "./TileFreshnessCalculator" |  | ||||||
| import FullNodeDatabaseSource from "./TiledFeatureSource/FullNodeDatabaseSource" | import FullNodeDatabaseSource from "./TiledFeatureSource/FullNodeDatabaseSource" | ||||||
| import MapState from "../State/MapState" | import MapState from "../State/MapState" | ||||||
| import { ElementStorage } from "../ElementStorage" |  | ||||||
| import { OsmFeature } from "../../Models/OsmFeature" | import { OsmFeature } from "../../Models/OsmFeature" | ||||||
| import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | ||||||
| import { FilterState } from "../../Models/FilteredLayer" | import { FilterState } from "../../Models/FilteredLayer" | ||||||
|  | @ -47,7 +49,6 @@ export default class FeaturePipeline { | ||||||
|     public readonly somethingLoaded: UIEventSource<boolean> = new UIEventSource<boolean>(false) |     public readonly somethingLoaded: UIEventSource<boolean> = new UIEventSource<boolean>(false) | ||||||
|     public readonly newDataLoadedSignal: UIEventSource<FeatureSource> = |     public readonly newDataLoadedSignal: UIEventSource<FeatureSource> = | ||||||
|         new UIEventSource<FeatureSource>(undefined) |         new UIEventSource<FeatureSource>(undefined) | ||||||
|     public readonly relationTracker: RelationsTracker |  | ||||||
|     /** |     /** | ||||||
|      * Keeps track of all raw OSM-nodes. |      * Keeps track of all raw OSM-nodes. | ||||||
|      * Only initialized if `ReplaceGeometryAction` is needed somewhere |      * Only initialized if `ReplaceGeometryAction` is needed somewhere | ||||||
|  | @ -56,12 +57,6 @@ export default class FeaturePipeline { | ||||||
|     private readonly overpassUpdater: OverpassFeatureSource |     private readonly overpassUpdater: OverpassFeatureSource | ||||||
|     private state: MapState |     private state: MapState | ||||||
|     private readonly perLayerHierarchy: Map<string, TileHierarchyMerger> |     private readonly perLayerHierarchy: Map<string, TileHierarchyMerger> | ||||||
|     /** |  | ||||||
|      * Keeps track of the age of the loaded data. |  | ||||||
|      * Has one freshness-Calculator for every layer |  | ||||||
|      * @private |  | ||||||
|      */ |  | ||||||
|     private readonly freshnesses = new Map<string, TileFreshnessCalculator>() |  | ||||||
|     private readonly oldestAllowedDate: Date |     private readonly oldestAllowedDate: Date | ||||||
|     private readonly osmSourceZoomLevel |     private readonly osmSourceZoomLevel | ||||||
|     private readonly localStorageSavers = new Map<string, SaveTileToLocalStorageActor>() |     private readonly localStorageSavers = new Map<string, SaveTileToLocalStorageActor>() | ||||||
|  | @ -87,7 +82,6 @@ export default class FeaturePipeline { | ||||||
|         const useOsmApi = state.locationControl.map( |         const useOsmApi = state.locationControl.map( | ||||||
|             (l) => l.zoom > (state.overpassMaxZoom.data ?? 12) |             (l) => l.zoom > (state.overpassMaxZoom.data ?? 12) | ||||||
|         ) |         ) | ||||||
|         this.relationTracker = new RelationsTracker() |  | ||||||
| 
 | 
 | ||||||
|         state.changes.allChanges.addCallbackAndRun((allChanges) => { |         state.changes.allChanges.addCallbackAndRun((allChanges) => { | ||||||
|             allChanges |             allChanges | ||||||
|  | @ -141,11 +135,8 @@ export default class FeaturePipeline { | ||||||
|             ) |             ) | ||||||
|             perLayerHierarchy.set(id, hierarchy) |             perLayerHierarchy.set(id, hierarchy) | ||||||
| 
 | 
 | ||||||
|             this.freshnesses.set(id, new TileFreshnessCalculator()) |  | ||||||
| 
 |  | ||||||
|             if (id === "type_node") { |             if (id === "type_node") { | ||||||
|                 this.fullNodeDatabase = new FullNodeDatabaseSource(filteredLayer, (tile) => { |                 this.fullNodeDatabase = new FullNodeDatabaseSource(filteredLayer, (tile) => { | ||||||
|                     new RegisteringAllFromFeatureSourceActor(tile, state.allElements) |  | ||||||
|                     perLayerHierarchy.get(tile.layer.layerDef.id).registerTile(tile) |                     perLayerHierarchy.get(tile.layer.layerDef.id).registerTile(tile) | ||||||
|                     tile.features.addCallbackAndRunD((_) => self.onNewDataLoaded(tile)) |                     tile.features.addCallbackAndRunD((_) => self.onNewDataLoaded(tile)) | ||||||
|                 }) |                 }) | ||||||
|  | @ -473,7 +464,6 @@ export default class FeaturePipeline { | ||||||
| 
 | 
 | ||||||
|     private initOverpassUpdater( |     private initOverpassUpdater( | ||||||
|         state: { |         state: { | ||||||
|             allElements: ElementStorage |  | ||||||
|             layoutToUse: LayoutConfig |             layoutToUse: LayoutConfig | ||||||
|             currentBounds: Store<BBox> |             currentBounds: Store<BBox> | ||||||
|             locationControl: Store<Loc> |             locationControl: Store<Loc> | ||||||
|  | @ -513,26 +503,10 @@ export default class FeaturePipeline { | ||||||
|             [state.locationControl] |             [state.locationControl] | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         const self = this |         return new OverpassFeatureSource(state, { | ||||||
|         const updater = new OverpassFeatureSource(state, { |  | ||||||
|             padToTiles: state.locationControl.map((l) => Math.min(15, l.zoom + 1)), |             padToTiles: state.locationControl.map((l) => Math.min(15, l.zoom + 1)), | ||||||
|             relationTracker: this.relationTracker, |  | ||||||
|             isActive: useOsmApi.map((b) => !b && overpassIsActive.data, [overpassIsActive]), |             isActive: useOsmApi.map((b) => !b && overpassIsActive.data, [overpassIsActive]), | ||||||
|             freshnesses: this.freshnesses, |  | ||||||
|             onBboxLoaded: (bbox, date, downloadedLayers, paddedToZoomLevel) => { |  | ||||||
|                 Tiles.MapRange(bbox.containingTileRange(paddedToZoomLevel), (x, y) => { |  | ||||||
|                     const tileIndex = Tiles.tile_index(paddedToZoomLevel, x, y) |  | ||||||
|                     downloadedLayers.forEach((layer) => { |  | ||||||
|                         self.freshnesses.get(layer.id).addTileLoad(tileIndex, date) |  | ||||||
|                         self.localStorageSavers.get(layer.id)?.MarkVisited(tileIndex, date) |  | ||||||
|         }) |         }) | ||||||
|                 }) |  | ||||||
|             }, |  | ||||||
|         }) |  | ||||||
| 
 |  | ||||||
|         // Register everything in the state' 'AllElements'
 |  | ||||||
|         new RegisteringAllFromFeatureSourceActor(updater, state.allElements) |  | ||||||
|         return updater |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  |  | ||||||
|  | @ -23,5 +23,5 @@ export interface FeatureSourceForLayer extends FeatureSource { | ||||||
|  * A feature source which is aware of the indexes it contains |  * A feature source which is aware of the indexes it contains | ||||||
|  */ |  */ | ||||||
| export interface IndexedFeatureSource extends FeatureSource { | export interface IndexedFeatureSource extends FeatureSource { | ||||||
|     readonly containedIds: Store<Set<string>> |     readonly featuresById: Store<Map<string, Feature>> | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										129
									
								
								Logic/FeatureSource/LayoutSource.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								Logic/FeatureSource/LayoutSource.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,129 @@ | ||||||
|  | import FeatureSource from "./FeatureSource" | ||||||
|  | import { Store } from "../UIEventSource" | ||||||
|  | import FeatureSwitchState from "../State/FeatureSwitchState" | ||||||
|  | import OverpassFeatureSource from "../Actors/OverpassFeatureSource" | ||||||
|  | import { BBox } from "../BBox" | ||||||
|  | import OsmFeatureSource from "./TiledFeatureSource/OsmFeatureSource" | ||||||
|  | import { Or } from "../Tags/Or" | ||||||
|  | import FeatureSourceMerger from "./Sources/FeatureSourceMerger" | ||||||
|  | import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | ||||||
|  | import GeoJsonSource from "./Sources/GeoJsonSource" | ||||||
|  | import DynamicGeoJsonTileSource from "./TiledFeatureSource/DynamicGeoJsonTileSource" | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * This source will fetch the needed data from various sources for the given layout. | ||||||
|  |  * | ||||||
|  |  * Note that special layers (with `source=null` will be ignored) | ||||||
|  |  */ | ||||||
|  | export default class LayoutSource extends FeatureSourceMerger { | ||||||
|  |     constructor( | ||||||
|  |         filteredLayers: LayerConfig[], | ||||||
|  |         featureSwitches: FeatureSwitchState, | ||||||
|  |         newAndChangedElements: FeatureSource, | ||||||
|  |         mapProperties: { bounds: Store<BBox>; zoom: Store<number> }, | ||||||
|  |         backend: string, | ||||||
|  |         isLayerActive: (id: string) => Store<boolean> | ||||||
|  |     ) { | ||||||
|  |         const { bounds, zoom } = mapProperties | ||||||
|  |         // remove all 'special' layers
 | ||||||
|  |         filteredLayers = filteredLayers.filter((flayer) => flayer.source !== null) | ||||||
|  | 
 | ||||||
|  |         const geojsonlayers = filteredLayers.filter( | ||||||
|  |             (flayer) => flayer.source.geojsonSource !== undefined | ||||||
|  |         ) | ||||||
|  |         const osmLayers = filteredLayers.filter( | ||||||
|  |             (flayer) => flayer.source.geojsonSource === undefined | ||||||
|  |         ) | ||||||
|  |         const overpassSource = LayoutSource.setupOverpass(osmLayers, bounds, zoom, featureSwitches) | ||||||
|  |         const osmApiSource = LayoutSource.setupOsmApiSource( | ||||||
|  |             osmLayers, | ||||||
|  |             bounds, | ||||||
|  |             zoom, | ||||||
|  |             backend, | ||||||
|  |             featureSwitches | ||||||
|  |         ) | ||||||
|  |         const geojsonSources: FeatureSource[] = geojsonlayers.map((l) => | ||||||
|  |             LayoutSource.setupGeojsonSource(l, mapProperties) | ||||||
|  |         ) | ||||||
|  | 
 | ||||||
|  |         const expiryInSeconds = Math.min(...(filteredLayers?.map((l) => l.maxAgeOfCache) ?? [])) | ||||||
|  |         super(overpassSource, osmApiSource, newAndChangedElements, ...geojsonSources) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private static setupGeojsonSource( | ||||||
|  |         layer: LayerConfig, | ||||||
|  |         mapProperties: { zoom: Store<number>; bounds: Store<BBox> }, | ||||||
|  |         isActive?: Store<boolean> | ||||||
|  |     ): FeatureSource { | ||||||
|  |         const source = layer.source | ||||||
|  |         if (source.geojsonZoomLevel === undefined) { | ||||||
|  |             // This is a 'load everything at once' geojson layer
 | ||||||
|  |             return new GeoJsonSource(layer, { isActive }) | ||||||
|  |         } else { | ||||||
|  |             return new DynamicGeoJsonTileSource(layer, mapProperties, { isActive }) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private static setupOsmApiSource( | ||||||
|  |         osmLayers: LayerConfig[], | ||||||
|  |         bounds: Store<BBox>, | ||||||
|  |         zoom: Store<number>, | ||||||
|  |         backend: string, | ||||||
|  |         featureSwitches: FeatureSwitchState | ||||||
|  |     ): FeatureSource { | ||||||
|  |         const minzoom = Math.min(...osmLayers.map((layer) => layer.minzoom)) | ||||||
|  |         const isActive = zoom.mapD((z) => { | ||||||
|  |             if (z < minzoom) { | ||||||
|  |                 // We are zoomed out over the zoomlevel of any layer
 | ||||||
|  |                 console.debug("Disabling overpass source: zoom < minzoom") | ||||||
|  |                 return false | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             // Overpass should handle this if zoomed out a bit
 | ||||||
|  |             return z > featureSwitches.overpassMaxZoom.data | ||||||
|  |         }) | ||||||
|  |         const allowedFeatures = new Or(osmLayers.map((l) => l.source.osmTags)).optimize() | ||||||
|  |         if (typeof allowedFeatures === "boolean") { | ||||||
|  |             throw "Invalid filter to init OsmFeatureSource: it optimizes away to " + allowedFeatures | ||||||
|  |         } | ||||||
|  |         return new OsmFeatureSource({ | ||||||
|  |             allowedFeatures, | ||||||
|  |             bounds, | ||||||
|  |             backend, | ||||||
|  |             isActive, | ||||||
|  |         }) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private static setupOverpass( | ||||||
|  |         osmLayers: LayerConfig[], | ||||||
|  |         bounds: Store<BBox>, | ||||||
|  |         zoom: Store<number>, | ||||||
|  |         featureSwitches: FeatureSwitchState | ||||||
|  |     ): FeatureSource { | ||||||
|  |         const minzoom = Math.min(...osmLayers.map((layer) => layer.minzoom)) | ||||||
|  |         const isActive = zoom.mapD((z) => { | ||||||
|  |             if (z < minzoom) { | ||||||
|  |                 // We are zoomed out over the zoomlevel of any layer
 | ||||||
|  |                 console.debug("Disabling overpass source: zoom < minzoom") | ||||||
|  |                 return false | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             return z <= featureSwitches.overpassMaxZoom.data | ||||||
|  |         }) | ||||||
|  | 
 | ||||||
|  |         return new OverpassFeatureSource( | ||||||
|  |             { | ||||||
|  |                 zoom, | ||||||
|  |                 bounds, | ||||||
|  |                 layoutToUse: featureSwitches.layoutToUse, | ||||||
|  |                 overpassUrl: featureSwitches.overpassUrl, | ||||||
|  |                 overpassTimeout: featureSwitches.overpassTimeout, | ||||||
|  |                 overpassMaxZoom: featureSwitches.overpassMaxZoom, | ||||||
|  |             }, | ||||||
|  |             { | ||||||
|  |                 padToTiles: zoom.map((zoom) => Math.min(15, zoom + 1)), | ||||||
|  |                 isActive, | ||||||
|  |             } | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import FeatureSource, { FeatureSourceForLayer, Tiled } from "./FeatureSource" | import FeatureSource from "./FeatureSource" | ||||||
| import { Store } from "../UIEventSource" | import { Store } from "../UIEventSource" | ||||||
| import FilteredLayer from "../../Models/FilteredLayer" | import FilteredLayer from "../../Models/FilteredLayer" | ||||||
| import SimpleFeatureSource from "./Sources/SimpleFeatureSource" | import SimpleFeatureSource from "./Sources/SimpleFeatureSource" | ||||||
|  | @ -12,7 +12,7 @@ import { Feature } from "geojson" | ||||||
| export default class PerLayerFeatureSourceSplitter { | export default class PerLayerFeatureSourceSplitter { | ||||||
|     constructor( |     constructor( | ||||||
|         layers: Store<FilteredLayer[]>, |         layers: Store<FilteredLayer[]>, | ||||||
|         handleLayerData: (source: FeatureSourceForLayer & Tiled) => void, |         handleLayerData: (source: FeatureSource, layer: FilteredLayer) => void, | ||||||
|         upstream: FeatureSource, |         upstream: FeatureSource, | ||||||
|         options?: { |         options?: { | ||||||
|             tileIndex?: number |             tileIndex?: number | ||||||
|  | @ -71,10 +71,10 @@ export default class PerLayerFeatureSourceSplitter { | ||||||
|                 let featureSource = knownLayers.get(id) |                 let featureSource = knownLayers.get(id) | ||||||
|                 if (featureSource === undefined) { |                 if (featureSource === undefined) { | ||||||
|                     // Not yet initialized - now is a good time
 |                     // Not yet initialized - now is a good time
 | ||||||
|                     featureSource = new SimpleFeatureSource(layer, options?.tileIndex) |                     featureSource = new SimpleFeatureSource(layer) | ||||||
|                     featureSource.features.setData(features) |                     featureSource.features.setData(features) | ||||||
|                     knownLayers.set(id, featureSource) |                     knownLayers.set(id, featureSource) | ||||||
|                     handleLayerData(featureSource) |                     handleLayerData(featureSource, layer) | ||||||
|                 } else { |                 } else { | ||||||
|                     featureSource.features.setData(features) |                     featureSource.features.setData(features) | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  | @ -1,58 +1,40 @@ | ||||||
| import { UIEventSource } from "../../UIEventSource" | import { Store, UIEventSource } from "../../UIEventSource" | ||||||
| import FeatureSource, { FeatureSourceForLayer, IndexedFeatureSource, Tiled } from "../FeatureSource" | import FeatureSource, { IndexedFeatureSource } from "../FeatureSource" | ||||||
| import FilteredLayer from "../../../Models/FilteredLayer" |  | ||||||
| import { BBox } from "../../BBox" |  | ||||||
| import { Feature } from "geojson" | import { Feature } from "geojson" | ||||||
| 
 | 
 | ||||||
| export default class FeatureSourceMerger |  | ||||||
|     implements FeatureSourceForLayer, Tiled, IndexedFeatureSource |  | ||||||
| { |  | ||||||
|     public features: UIEventSource<Feature[]> = new UIEventSource([]) |  | ||||||
|     public readonly layer: FilteredLayer |  | ||||||
|     public readonly tileIndex: number |  | ||||||
|     public readonly bbox: BBox |  | ||||||
|     public readonly containedIds: UIEventSource<Set<string>> = new UIEventSource<Set<string>>( |  | ||||||
|         new Set() |  | ||||||
|     ) |  | ||||||
|     private readonly _sources: UIEventSource<FeatureSource[]> |  | ||||||
| /** | /** | ||||||
|      * Merges features from different featureSources for a single layer |  * | ||||||
|      * Uses the freshest feature available in the case multiple sources offer data with the same identifier |  | ||||||
|  */ |  */ | ||||||
|     constructor( | export default class FeatureSourceMerger implements IndexedFeatureSource { | ||||||
|         layer: FilteredLayer, |     public features: UIEventSource<Feature[]> = new UIEventSource([]) | ||||||
|         tileIndex: number, |     public readonly featuresById: Store<Map<string, Feature>> | ||||||
|         bbox: BBox, |     private readonly _featuresById: UIEventSource<Map<string, Feature>> | ||||||
|         sources: UIEventSource<FeatureSource[]> |     private readonly _sources: FeatureSource[] = [] | ||||||
|     ) { |     /** | ||||||
|         this.tileIndex = tileIndex |      * Merges features from different featureSources. | ||||||
|         this.bbox = bbox |      * In case that multiple features have the same id, the latest `_version_number` will be used. Otherwise, we will take the last one | ||||||
|         this._sources = sources |      */ | ||||||
|         this.layer = layer |     constructor(...sources: FeatureSource[]) { | ||||||
|  |         this._featuresById = new UIEventSource<Map<string, Feature>>(undefined) | ||||||
|  |         this.featuresById = this._featuresById | ||||||
|         const self = this |         const self = this | ||||||
| 
 |         for (let source of sources) { | ||||||
|         const handledSources = new Set<FeatureSource>() |  | ||||||
| 
 |  | ||||||
|         sources.addCallbackAndRunD((sources) => { |  | ||||||
|             let newSourceRegistered = false |  | ||||||
|             for (let i = 0; i < sources.length; i++) { |  | ||||||
|                 let source = sources[i] |  | ||||||
|                 if (handledSources.has(source)) { |  | ||||||
|                     continue |  | ||||||
|                 } |  | ||||||
|                 handledSources.add(source) |  | ||||||
|                 newSourceRegistered = true |  | ||||||
|             source.features.addCallback(() => { |             source.features.addCallback(() => { | ||||||
|                     self.Update() |                 self.addData(sources.map((s) => s.features.data)) | ||||||
|             }) |             }) | ||||||
|                 if (newSourceRegistered) { |  | ||||||
|                     self.Update() |  | ||||||
|         } |         } | ||||||
|  |         this.addData(sources.map((s) => s.features.data)) | ||||||
|  |         this._sources = sources | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     protected addSource(source: FeatureSource) { | ||||||
|  |         this._sources.push(source) | ||||||
|  |         source.features.addCallbackAndRun(() => { | ||||||
|  |             this.addData(this._sources.map((s) => s.features.data)) | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private Update() { |     protected addData(featuress: Feature[][]) { | ||||||
|         let somethingChanged = false |         let somethingChanged = false | ||||||
|         const all: Map<string, Feature> = new Map() |         const all: Map<string, Feature> = new Map() | ||||||
|         // We seed the dictionary with the previously loaded features
 |         // We seed the dictionary with the previously loaded features
 | ||||||
|  | @ -61,11 +43,11 @@ export default class FeatureSourceMerger | ||||||
|             all.set(oldValue.properties.id, oldValue) |             all.set(oldValue.properties.id, oldValue) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         for (const source of this._sources.data) { |         for (const features of featuress) { | ||||||
|             if (source?.features?.data === undefined) { |             if (features === undefined) { | ||||||
|                 continue |                 continue | ||||||
|             } |             } | ||||||
|             for (const f of source.features.data) { |             for (const f of features) { | ||||||
|                 const id = f.properties.id |                 const id = f.properties.id | ||||||
|                 if (!all.has(id)) { |                 if (!all.has(id)) { | ||||||
|                     // This is a new feature
 |                     // This is a new feature
 | ||||||
|  | @ -77,7 +59,7 @@ export default class FeatureSourceMerger | ||||||
|                 // This value has been seen already, either in a previous run or by a previous datasource
 |                 // This value has been seen already, either in a previous run or by a previous datasource
 | ||||||
|                 // Let's figure out if something changed
 |                 // Let's figure out if something changed
 | ||||||
|                 const oldV = all.get(id) |                 const oldV = all.get(id) | ||||||
|                 if (oldV === f) { |                 if (oldV == f) { | ||||||
|                     continue |                     continue | ||||||
|                 } |                 } | ||||||
|                 all.set(id, f) |                 all.set(id, f) | ||||||
|  | @ -91,10 +73,10 @@ export default class FeatureSourceMerger | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const newList = [] |         const newList = [] | ||||||
|         all.forEach((value, _) => { |         all.forEach((value, key) => { | ||||||
|             newList.push(value) |             newList.push(value) | ||||||
|         }) |         }) | ||||||
|         this.containedIds.setData(new Set(all.keys())) |  | ||||||
|         this.features.setData(newList) |         this.features.setData(newList) | ||||||
|  |         this._featuresById.setData(all) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,45 +1,32 @@ | ||||||
| import { Store, UIEventSource } from "../../UIEventSource" | import { Store, UIEventSource } from "../../UIEventSource" | ||||||
| import FilteredLayer, { FilterState } from "../../../Models/FilteredLayer" | import FilteredLayer, { FilterState } from "../../../Models/FilteredLayer" | ||||||
| import { FeatureSourceForLayer, Tiled } from "../FeatureSource" | import FeatureSource from "../FeatureSource" | ||||||
| import { BBox } from "../../BBox" |  | ||||||
| import { ElementStorage } from "../../ElementStorage" |  | ||||||
| import { TagsFilter } from "../../Tags/TagsFilter" | import { TagsFilter } from "../../Tags/TagsFilter" | ||||||
| import { Feature } from "geojson" | import { Feature } from "geojson" | ||||||
|  | import { OsmTags } from "../../../Models/OsmFeature" | ||||||
| 
 | 
 | ||||||
| export default class FilteringFeatureSource implements FeatureSourceForLayer, Tiled { | export default class FilteringFeatureSource implements FeatureSource { | ||||||
|     public features: UIEventSource<Feature[]> = new UIEventSource([]) |     public features: UIEventSource<Feature[]> = new UIEventSource([]) | ||||||
|     public readonly layer: FilteredLayer |     private readonly upstream: FeatureSource | ||||||
|     public readonly tileIndex: number |     private readonly _fetchStore?: (id: String) => Store<OsmTags> | ||||||
|     public readonly bbox: BBox |     private readonly _globalFilters?: Store<{ filter: FilterState }[]> | ||||||
|     private readonly upstream: FeatureSourceForLayer |     private readonly _alreadyRegistered = new Set<Store<any>>() | ||||||
|     private readonly state: { |  | ||||||
|         locationControl: Store<{ zoom: number }> |  | ||||||
|         selectedElement: Store<any> |  | ||||||
|         globalFilters?: Store<{ filter: FilterState }[]> |  | ||||||
|         allElements: ElementStorage |  | ||||||
|     } |  | ||||||
|     private readonly _alreadyRegistered = new Set<UIEventSource<any>>() |  | ||||||
|     private readonly _is_dirty = new UIEventSource(false) |     private readonly _is_dirty = new UIEventSource(false) | ||||||
|  |     private readonly _layer: FilteredLayer | ||||||
|     private previousFeatureSet: Set<any> = undefined |     private previousFeatureSet: Set<any> = undefined | ||||||
| 
 | 
 | ||||||
|     constructor( |     constructor( | ||||||
|         state: { |         layer: FilteredLayer, | ||||||
|             locationControl: Store<{ zoom: number }> |         upstream: FeatureSource, | ||||||
|             selectedElement: Store<any> |         fetchStore?: (id: String) => Store<OsmTags>, | ||||||
|             allElements: ElementStorage |         globalFilters?: Store<{ filter: FilterState }[]>, | ||||||
|             globalFilters?: Store<{ filter: FilterState }[]> |         metataggingUpdated?: Store<any> | ||||||
|         }, |  | ||||||
|         tileIndex, |  | ||||||
|         upstream: FeatureSourceForLayer, |  | ||||||
|         metataggingUpdated?: UIEventSource<any> |  | ||||||
|     ) { |     ) { | ||||||
|         this.tileIndex = tileIndex |  | ||||||
|         this.bbox = tileIndex === undefined ? undefined : BBox.fromTileIndex(tileIndex) |  | ||||||
|         this.upstream = upstream |         this.upstream = upstream | ||||||
|         this.state = state |         this._fetchStore = fetchStore | ||||||
|  |         this._layer = layer | ||||||
|  |         this._globalFilters = globalFilters | ||||||
| 
 | 
 | ||||||
|         this.layer = upstream.layer |  | ||||||
|         const layer = upstream.layer |  | ||||||
|         const self = this |         const self = this | ||||||
|         upstream.features.addCallback(() => { |         upstream.features.addCallback(() => { | ||||||
|             self.update() |             self.update() | ||||||
|  | @ -59,7 +46,7 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti | ||||||
|             self._is_dirty.setData(true) |             self._is_dirty.setData(true) | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
|         state.globalFilters?.addCallback((_) => { |         globalFilters?.addCallback((_) => { | ||||||
|             self.update() |             self.update() | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
|  | @ -68,10 +55,10 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti | ||||||
| 
 | 
 | ||||||
|     private update() { |     private update() { | ||||||
|         const self = this |         const self = this | ||||||
|         const layer = this.upstream.layer |         const layer = this._layer | ||||||
|         const features: Feature[] = this.upstream.features.data ?? [] |         const features: Feature[] = this.upstream.features.data ?? [] | ||||||
|         const includedFeatureIds = new Set<string>() |         const includedFeatureIds = new Set<string>() | ||||||
|         const globalFilters = self.state.globalFilters?.data?.map((f) => f.filter) |         const globalFilters = self._globalFilters?.data?.map((f) => f.filter) | ||||||
|         const newFeatures = (features ?? []).filter((f) => { |         const newFeatures = (features ?? []).filter((f) => { | ||||||
|             self.registerCallback(f) |             self.registerCallback(f) | ||||||
| 
 | 
 | ||||||
|  | @ -126,7 +113,10 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private registerCallback(feature: any) { |     private registerCallback(feature: any) { | ||||||
|         const src = this.state?.allElements?.addOrGetElement(feature) |         if (this._fetchStore === undefined) { | ||||||
|  |             return | ||||||
|  |         } | ||||||
|  |         const src = this._fetchStore(feature) | ||||||
|         if (src == undefined) { |         if (src == undefined) { | ||||||
|             return |             return | ||||||
|         } |         } | ||||||
|  | @ -136,7 +126,7 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti | ||||||
|         this._alreadyRegistered.add(src) |         this._alreadyRegistered.add(src) | ||||||
| 
 | 
 | ||||||
|         const self = this |         const self = this | ||||||
|         // Add a callback as a changed tag migh change the filter
 |         // Add a callback as a changed tag might change the filter
 | ||||||
|         src.addCallbackAndRunD((_) => { |         src.addCallbackAndRunD((_) => { | ||||||
|             self._is_dirty.setData(true) |             self._is_dirty.setData(true) | ||||||
|         }) |         }) | ||||||
|  |  | ||||||
|  | @ -1,59 +1,53 @@ | ||||||
| /** | /** | ||||||
|  * Fetches a geojson file somewhere and passes it along |  * Fetches a geojson file somewhere and passes it along | ||||||
|  */ |  */ | ||||||
| import { UIEventSource } from "../../UIEventSource" | import { Store, UIEventSource } from "../../UIEventSource" | ||||||
| import FilteredLayer from "../../../Models/FilteredLayer" |  | ||||||
| import { Utils } from "../../../Utils" | import { Utils } from "../../../Utils" | ||||||
| import { FeatureSourceForLayer, Tiled } from "../FeatureSource" | import FeatureSource from "../FeatureSource" | ||||||
| import { Tiles } from "../../../Models/TileRange" |  | ||||||
| import { BBox } from "../../BBox" | import { BBox } from "../../BBox" | ||||||
| import { GeoOperations } from "../../GeoOperations" | import { GeoOperations } from "../../GeoOperations" | ||||||
| import { Feature } from "geojson" | import { Feature } from "geojson" | ||||||
|  | import LayerConfig from "../../../Models/ThemeConfig/LayerConfig" | ||||||
|  | import { Tiles } from "../../../Models/TileRange" | ||||||
| 
 | 
 | ||||||
| export default class GeoJsonSource implements FeatureSourceForLayer, Tiled { | export default class GeoJsonSource implements FeatureSource { | ||||||
|     public readonly features: UIEventSource<Feature[]> |     public readonly features: Store<Feature[]> | ||||||
|     public readonly state = new UIEventSource<undefined | { error: string } | "loaded">(undefined) |  | ||||||
|     public readonly name |  | ||||||
|     public readonly isOsmCache: boolean |  | ||||||
|     public readonly layer: FilteredLayer |  | ||||||
|     public readonly tileIndex |  | ||||||
|     public readonly bbox |  | ||||||
|     private readonly seenids: Set<string> |     private readonly seenids: Set<string> | ||||||
|     private readonly idKey?: string |     private readonly idKey?: string | ||||||
| 
 | 
 | ||||||
|     public constructor( |     public constructor( | ||||||
|         flayer: FilteredLayer, |         layer: LayerConfig, | ||||||
|         zxy?: [number, number, number] | BBox, |  | ||||||
|         options?: { |         options?: { | ||||||
|  |             zxy?: number | [number, number, number] | BBox | ||||||
|             featureIdBlacklist?: Set<string> |             featureIdBlacklist?: Set<string> | ||||||
|  |             isActive?: Store<boolean> | ||||||
|         } |         } | ||||||
|     ) { |     ) { | ||||||
|         if (flayer.layerDef.source.geojsonZoomLevel !== undefined && zxy === undefined) { |         if (layer.source.geojsonZoomLevel !== undefined && options?.zxy === undefined) { | ||||||
|             throw "Dynamic layers are not supported. Use 'DynamicGeoJsonTileSource instead" |             throw "Dynamic layers are not supported. Use 'DynamicGeoJsonTileSource instead" | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.layer = flayer |         this.idKey = layer.source.idKey | ||||||
|         this.idKey = flayer.layerDef.source.idKey |  | ||||||
|         this.seenids = options?.featureIdBlacklist ?? new Set<string>() |         this.seenids = options?.featureIdBlacklist ?? new Set<string>() | ||||||
|         let url = flayer.layerDef.source.geojsonSource.replace("{layer}", flayer.layerDef.id) |         let url = layer.source.geojsonSource.replace("{layer}", layer.id) | ||||||
|  |         let zxy = options?.zxy | ||||||
|         if (zxy !== undefined) { |         if (zxy !== undefined) { | ||||||
|             let tile_bbox: BBox |             let tile_bbox: BBox | ||||||
|  |             if (typeof zxy === "number") { | ||||||
|  |                 zxy = Tiles.tile_from_index(zxy) | ||||||
|  |             } | ||||||
|             if (zxy instanceof BBox) { |             if (zxy instanceof BBox) { | ||||||
|                 tile_bbox = zxy |                 tile_bbox = zxy | ||||||
|             } else { |             } else { | ||||||
|                 const [z, x, y] = zxy |                 const [z, x, y] = zxy | ||||||
|                 tile_bbox = BBox.fromTile(z, x, y) |                 tile_bbox = BBox.fromTile(z, x, y) | ||||||
| 
 |  | ||||||
|                 this.tileIndex = Tiles.tile_index(z, x, y) |  | ||||||
|                 this.bbox = BBox.fromTile(z, x, y) |  | ||||||
|                 url = url |                 url = url | ||||||
|                     .replace("{z}", "" + z) |                     .replace("{z}", "" + z) | ||||||
|                     .replace("{x}", "" + x) |                     .replace("{x}", "" + x) | ||||||
|                     .replace("{y}", "" + y) |                     .replace("{y}", "" + y) | ||||||
|             } |             } | ||||||
|             let bounds: { minLat: number; maxLat: number; minLon: number; maxLon: number } = |             let bounds: Record<"minLat" | "maxLat" | "minLon" | "maxLon", number> = tile_bbox | ||||||
|                 tile_bbox |             if (layer.source.mercatorCrs) { | ||||||
|             if (this.layer.layerDef.source.mercatorCrs) { |  | ||||||
|                 bounds = tile_bbox.toMercator() |                 bounds = tile_bbox.toMercator() | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  | @ -62,51 +56,40 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled { | ||||||
|                 .replace("{y_max}", "" + bounds.maxLat) |                 .replace("{y_max}", "" + bounds.maxLat) | ||||||
|                 .replace("{x_min}", "" + bounds.minLon) |                 .replace("{x_min}", "" + bounds.minLon) | ||||||
|                 .replace("{x_max}", "" + bounds.maxLon) |                 .replace("{x_max}", "" + bounds.maxLon) | ||||||
|         } else { |  | ||||||
|             this.tileIndex = Tiles.tile_index(0, 0, 0) |  | ||||||
|             this.bbox = BBox.global |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.name = "GeoJsonSource of " + url |         const eventsource = new UIEventSource<Feature[]>(undefined) | ||||||
| 
 |         if (options?.isActive !== undefined) { | ||||||
|         this.isOsmCache = flayer.layerDef.source.isOsmCacheLayer |             options.isActive.addCallbackAndRunD(async (active) => { | ||||||
|         this.features = new UIEventSource<Feature[]>([]) |                 if (!active) { | ||||||
|         this.LoadJSONFrom(url) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private LoadJSONFrom(url: string) { |  | ||||||
|         const eventSource = this.features |  | ||||||
|         const self = this |  | ||||||
|         Utils.downloadJsonCached(url, 60 * 60) |  | ||||||
|             .then((json) => { |  | ||||||
|                 self.state.setData("loaded") |  | ||||||
|                 // TODO: move somewhere else, just for testing
 |  | ||||||
|                 // Check for maproulette data
 |  | ||||||
|                 if (url.startsWith("https://maproulette.org/api/v2/tasks/box/")) { |  | ||||||
|                     console.log("MapRoulette data detected") |  | ||||||
|                     const data = json |  | ||||||
|                     let maprouletteFeatures: any[] = [] |  | ||||||
|                     data.forEach((element) => { |  | ||||||
|                         maprouletteFeatures.push({ |  | ||||||
|                             type: "Feature", |  | ||||||
|                             geometry: { |  | ||||||
|                                 type: "Point", |  | ||||||
|                                 coordinates: [element.point.lng, element.point.lat], |  | ||||||
|                             }, |  | ||||||
|                             properties: { |  | ||||||
|                                 // Map all properties to the feature
 |  | ||||||
|                                 ...element, |  | ||||||
|                             }, |  | ||||||
|                         }) |  | ||||||
|                     }) |  | ||||||
|                     json.features = maprouletteFeatures |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 if (json.features === undefined || json.features === null) { |  | ||||||
|                     return |                     return | ||||||
|                 } |                 } | ||||||
|  |                 this.LoadJSONFrom(url, eventsource, layer) | ||||||
|  |                     .then((_) => console.log("Loaded geojson " + url)) | ||||||
|  |                     .catch((err) => console.error("Could not load ", url, "due to", err)) | ||||||
|  |                 return true | ||||||
|  |             }) | ||||||
|  |         } else { | ||||||
|  |             this.LoadJSONFrom(url, eventsource, layer) | ||||||
|  |                 .then((_) => console.log("Loaded geojson " + url)) | ||||||
|  |                 .catch((err) => console.error("Could not load ", url, "due to", err)) | ||||||
|  |         } | ||||||
|  |         this.features = eventsource | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|                 if (self.layer.layerDef.source.mercatorCrs) { |     private async LoadJSONFrom( | ||||||
|  |         url: string, | ||||||
|  |         eventSource: UIEventSource<Feature[]>, | ||||||
|  |         layer: LayerConfig | ||||||
|  |     ): Promise<void> { | ||||||
|  |         const self = this | ||||||
|  |         let json = await Utils.downloadJsonCached(url, 60 * 60) | ||||||
|  | 
 | ||||||
|  |         if (json.features === undefined || json.features === null) { | ||||||
|  |             json.features = [] | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (layer.source.mercatorCrs) { | ||||||
|             json = GeoOperations.GeoJsonToWGS84(json) |             json = GeoOperations.GeoJsonToWGS84(json) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -150,15 +133,6 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled { | ||||||
|             newFeatures.push(feature) |             newFeatures.push(feature) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|                 if (newFeatures.length == 0) { |         eventSource.setData(newFeatures) | ||||||
|                     return |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 eventSource.setData(eventSource.data.concat(newFeatures)) |  | ||||||
|             }) |  | ||||||
|             .catch((msg) => { |  | ||||||
|                 console.debug("Could not load geojson layer", url, "due to", msg) |  | ||||||
|                 self.state.setData({ error: msg }) |  | ||||||
|             }) |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -4,16 +4,12 @@ import { FeatureSourceForLayer, Tiled } from "../FeatureSource" | ||||||
| import { BBox } from "../../BBox" | import { BBox } from "../../BBox" | ||||||
| import { Feature } from "geojson" | import { Feature } from "geojson" | ||||||
| 
 | 
 | ||||||
| export default class SimpleFeatureSource implements FeatureSourceForLayer, Tiled { | export default class SimpleFeatureSource implements FeatureSourceForLayer { | ||||||
|     public readonly features: UIEventSource<Feature[]> |     public readonly features: UIEventSource<Feature[]> | ||||||
|     public readonly layer: FilteredLayer |     public readonly layer: FilteredLayer | ||||||
|     public readonly bbox: BBox = BBox.global |  | ||||||
|     public readonly tileIndex: number |  | ||||||
| 
 | 
 | ||||||
|     constructor(layer: FilteredLayer, tileIndex: number, featureSource?: UIEventSource<Feature[]>) { |     constructor(layer: FilteredLayer, featureSource?: UIEventSource<Feature[]>) { | ||||||
|         this.layer = layer |         this.layer = layer | ||||||
|         this.tileIndex = tileIndex ?? 0 |  | ||||||
|         this.bbox = BBox.fromTileIndex(this.tileIndex) |  | ||||||
|         this.features = featureSource ?? new UIEventSource<Feature[]>([]) |         this.features = featureSource ?? new UIEventSource<Feature[]>([]) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,64 +0,0 @@ | ||||||
| import { Tiles } from "../../Models/TileRange" |  | ||||||
| 
 |  | ||||||
| export default class TileFreshnessCalculator { |  | ||||||
|     /** |  | ||||||
|      * All the freshnesses per tile index |  | ||||||
|      * @private |  | ||||||
|      */ |  | ||||||
|     private readonly freshnesses = new Map<number, Date>() |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * Marks that some data got loaded for this layer |  | ||||||
|      * @param tileId |  | ||||||
|      * @param freshness |  | ||||||
|      */ |  | ||||||
|     public addTileLoad(tileId: number, freshness: Date) { |  | ||||||
|         const existingFreshness = this.freshnessFor(...Tiles.tile_from_index(tileId)) |  | ||||||
|         if (existingFreshness >= freshness) { |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
|         this.freshnesses.set(tileId, freshness) |  | ||||||
| 
 |  | ||||||
|         // Do we have freshness for the neighbouring tiles? If so, we can mark the tile above as loaded too!
 |  | ||||||
|         let [z, x, y] = Tiles.tile_from_index(tileId) |  | ||||||
|         if (z === 0) { |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
|         x = x - (x % 2) // Make the tiles always even
 |  | ||||||
|         y = y - (y % 2) |  | ||||||
| 
 |  | ||||||
|         const ul = this.freshnessFor(z, x, y)?.getTime() |  | ||||||
|         if (ul === undefined) { |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
|         const ur = this.freshnessFor(z, x + 1, y)?.getTime() |  | ||||||
|         if (ur === undefined) { |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
|         const ll = this.freshnessFor(z, x, y + 1)?.getTime() |  | ||||||
|         if (ll === undefined) { |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
|         const lr = this.freshnessFor(z, x + 1, y + 1)?.getTime() |  | ||||||
|         if (lr === undefined) { |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         const leastFresh = Math.min(ul, ur, ll, lr) |  | ||||||
|         const date = new Date() |  | ||||||
|         date.setTime(leastFresh) |  | ||||||
|         this.addTileLoad(Tiles.tile_index(z - 1, Math.floor(x / 2), Math.floor(y / 2)), date) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public freshnessFor(z: number, x: number, y: number): Date { |  | ||||||
|         if (z < 0) { |  | ||||||
|             return undefined |  | ||||||
|         } |  | ||||||
|         const tileId = Tiles.tile_index(z, x, y) |  | ||||||
|         if (this.freshnesses.has(tileId)) { |  | ||||||
|             return this.freshnesses.get(tileId) |  | ||||||
|         } |  | ||||||
|         // recurse up
 |  | ||||||
|         return this.freshnessFor(z - 1, Math.floor(x / 2), Math.floor(y / 2)) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | @ -1,23 +1,24 @@ | ||||||
| import FilteredLayer from "../../../Models/FilteredLayer" | import { Store } from "../../UIEventSource" | ||||||
| import { FeatureSourceForLayer, Tiled } from "../FeatureSource" |  | ||||||
| import { UIEventSource } from "../../UIEventSource" |  | ||||||
| import DynamicTileSource from "./DynamicTileSource" | import DynamicTileSource from "./DynamicTileSource" | ||||||
| import { Utils } from "../../../Utils" | import { Utils } from "../../../Utils" | ||||||
| import GeoJsonSource from "../Sources/GeoJsonSource" | import GeoJsonSource from "../Sources/GeoJsonSource" | ||||||
| import { BBox } from "../../BBox" | import { BBox } from "../../BBox" | ||||||
|  | import LayerConfig from "../../../Models/ThemeConfig/LayerConfig" | ||||||
| 
 | 
 | ||||||
| export default class DynamicGeoJsonTileSource extends DynamicTileSource { | export default class DynamicGeoJsonTileSource extends DynamicTileSource { | ||||||
|     private static whitelistCache = new Map<string, any>() |     private static whitelistCache = new Map<string, any>() | ||||||
| 
 | 
 | ||||||
|     constructor( |     constructor( | ||||||
|         layer: FilteredLayer, |         layer: LayerConfig, | ||||||
|         registerLayer: (layer: FeatureSourceForLayer & Tiled) => void, |         mapProperties: { | ||||||
|         state: { |             zoom: Store<number> | ||||||
|             locationControl?: UIEventSource<{ zoom?: number }> |             bounds: Store<BBox> | ||||||
|             currentBounds: UIEventSource<BBox> |         }, | ||||||
|  |         options?: { | ||||||
|  |             isActive?: Store<boolean> | ||||||
|         } |         } | ||||||
|     ) { |     ) { | ||||||
|         const source = layer.layerDef.source |         const source = layer.source | ||||||
|         if (source.geojsonZoomLevel === undefined) { |         if (source.geojsonZoomLevel === undefined) { | ||||||
|             throw "Invalid layer: geojsonZoomLevel expected" |             throw "Invalid layer: geojsonZoomLevel expected" | ||||||
|         } |         } | ||||||
|  | @ -30,7 +31,7 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource { | ||||||
|             const whitelistUrl = source.geojsonSource |             const whitelistUrl = source.geojsonSource | ||||||
|                 .replace("{z}", "" + source.geojsonZoomLevel) |                 .replace("{z}", "" + source.geojsonZoomLevel) | ||||||
|                 .replace("{x}_{y}.geojson", "overview.json") |                 .replace("{x}_{y}.geojson", "overview.json") | ||||||
|                 .replace("{layer}", layer.layerDef.id) |                 .replace("{layer}", layer.id) | ||||||
| 
 | 
 | ||||||
|             if (DynamicGeoJsonTileSource.whitelistCache.has(whitelistUrl)) { |             if (DynamicGeoJsonTileSource.whitelistCache.has(whitelistUrl)) { | ||||||
|                 whitelist = DynamicGeoJsonTileSource.whitelistCache.get(whitelistUrl) |                 whitelist = DynamicGeoJsonTileSource.whitelistCache.get(whitelistUrl) | ||||||
|  | @ -56,14 +57,13 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource { | ||||||
|                         DynamicGeoJsonTileSource.whitelistCache.set(whitelistUrl, whitelist) |                         DynamicGeoJsonTileSource.whitelistCache.set(whitelistUrl, whitelist) | ||||||
|                     }) |                     }) | ||||||
|                     .catch((err) => { |                     .catch((err) => { | ||||||
|                         console.warn("No whitelist found for ", layer.layerDef.id, err) |                         console.warn("No whitelist found for ", layer.id, err) | ||||||
|                     }) |                     }) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const blackList = new Set<string>() |         const blackList = new Set<string>() | ||||||
|         super( |         super( | ||||||
|             layer, |  | ||||||
|             source.geojsonZoomLevel, |             source.geojsonZoomLevel, | ||||||
|             (zxy) => { |             (zxy) => { | ||||||
|                 if (whitelist !== undefined) { |                 if (whitelist !== undefined) { | ||||||
|  | @ -78,25 +78,13 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource { | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 const src = new GeoJsonSource(layer, zxy, { |                 return new GeoJsonSource(layer, { | ||||||
|  |                     zxy, | ||||||
|                     featureIdBlacklist: blackList, |                     featureIdBlacklist: blackList, | ||||||
|                 }) |                 }) | ||||||
| 
 |  | ||||||
|                 registerLayer(src) |  | ||||||
|                 return src |  | ||||||
|             }, |             }, | ||||||
|             state |             mapProperties, | ||||||
|  |             { isActive: options.isActive } | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     public static RegisterWhitelist(url: string, json: any) { |  | ||||||
|         const data = new Map<number, Set<number>>() |  | ||||||
|         for (const x in json) { |  | ||||||
|             if (x === "zoom") { |  | ||||||
|                 continue |  | ||||||
|             } |  | ||||||
|             data.set(Number(x), new Set(json[x])) |  | ||||||
|         } |  | ||||||
|         DynamicGeoJsonTileSource.whitelistCache.set(url, data) |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,50 +1,34 @@ | ||||||
| import FilteredLayer from "../../../Models/FilteredLayer" | import { Store, Stores } from "../../UIEventSource" | ||||||
| import { FeatureSourceForLayer, Tiled } from "../FeatureSource" |  | ||||||
| import { UIEventSource } from "../../UIEventSource" |  | ||||||
| import TileHierarchy from "./TileHierarchy" |  | ||||||
| import { Tiles } from "../../../Models/TileRange" | import { Tiles } from "../../../Models/TileRange" | ||||||
| import { BBox } from "../../BBox" | import { BBox } from "../../BBox" | ||||||
|  | import FeatureSource from "../FeatureSource" | ||||||
|  | import FeatureSourceMerger from "../Sources/FeatureSourceMerger" | ||||||
| 
 | 
 | ||||||
| /*** | /*** | ||||||
|  * A tiled source which dynamically loads the required tiles at a fixed zoom level |  * A tiled source which dynamically loads the required tiles at a fixed zoom level | ||||||
|  */ |  */ | ||||||
| export default class DynamicTileSource implements TileHierarchy<FeatureSourceForLayer & Tiled> { | export default class DynamicTileSource extends FeatureSourceMerger { | ||||||
|     public readonly loadedTiles: Map<number, FeatureSourceForLayer & Tiled> |  | ||||||
|     private readonly _loadedTiles = new Set<number>() |  | ||||||
| 
 |  | ||||||
|     constructor( |     constructor( | ||||||
|         layer: FilteredLayer, |  | ||||||
|         zoomlevel: number, |         zoomlevel: number, | ||||||
|         constructTile: (zxy: [number, number, number]) => FeatureSourceForLayer & Tiled, |         constructSource: (tileIndex) => FeatureSource, | ||||||
|         state: { |         mapProperties: { | ||||||
|             currentBounds: UIEventSource<BBox> |             bounds: Store<BBox> | ||||||
|             locationControl?: UIEventSource<{ zoom?: number }> |             zoom: Store<number> | ||||||
|  |         }, | ||||||
|  |         options?: { | ||||||
|  |             isActive?: Store<boolean> | ||||||
|         } |         } | ||||||
|     ) { |     ) { | ||||||
|         const self = this |         super() | ||||||
| 
 |         const loadedTiles = new Set<number>() | ||||||
|         this.loadedTiles = new Map<number, FeatureSourceForLayer & Tiled>() |         const neededTiles: Store<number[]> = Stores.ListStabilized( | ||||||
|         const neededTiles = state.currentBounds |             mapProperties.bounds | ||||||
|             .map( |                 .mapD( | ||||||
|                     (bounds) => { |                     (bounds) => { | ||||||
|                     if (bounds === undefined) { |                         if (options?.isActive?.data === false) { | ||||||
|                         // We'll retry later
 |  | ||||||
|                         return undefined |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     if (!layer.isDisplayed.data && !layer.layerDef.forceLoad) { |  | ||||||
|                             // No need to download! - the layer is disabled
 |                             // No need to download! - the layer is disabled
 | ||||||
|                             return undefined |                             return undefined | ||||||
|                         } |                         } | ||||||
| 
 |  | ||||||
|                     if ( |  | ||||||
|                         state.locationControl?.data?.zoom !== undefined && |  | ||||||
|                         state.locationControl.data.zoom < layer.layerDef.minzoom |  | ||||||
|                     ) { |  | ||||||
|                         // No need to download! - the layer is disabled
 |  | ||||||
|                         return undefined |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                         const tileRange = Tiles.TileRangeBetween( |                         const tileRange = Tiles.TileRangeBetween( | ||||||
|                             zoomlevel, |                             zoomlevel, | ||||||
|                             bounds.getNorth(), |                             bounds.getNorth(), | ||||||
|  | @ -61,27 +45,21 @@ export default class DynamicTileSource implements TileHierarchy<FeatureSourceFor | ||||||
| 
 | 
 | ||||||
|                         const needed = Tiles.MapRange(tileRange, (x, y) => |                         const needed = Tiles.MapRange(tileRange, (x, y) => | ||||||
|                             Tiles.tile_index(zoomlevel, x, y) |                             Tiles.tile_index(zoomlevel, x, y) | ||||||
|                     ).filter((i) => !self._loadedTiles.has(i)) |                         ).filter((i) => !loadedTiles.has(i)) | ||||||
|                         if (needed.length === 0) { |                         if (needed.length === 0) { | ||||||
|                             return undefined |                             return undefined | ||||||
|                         } |                         } | ||||||
|                         return needed |                         return needed | ||||||
|                     }, |                     }, | ||||||
|                 [layer.isDisplayed, state.locationControl] |                     [options?.isActive, mapProperties.zoom] | ||||||
|                 ) |                 ) | ||||||
|                 .stabilized(250) |                 .stabilized(250) | ||||||
|  |         ) | ||||||
| 
 | 
 | ||||||
|         neededTiles.addCallbackAndRunD((neededIndexes) => { |         neededTiles.addCallbackAndRunD((neededIndexes) => { | ||||||
|             console.log("Tiled geojson source ", layer.layerDef.id, " needs", neededIndexes) |  | ||||||
|             if (neededIndexes === undefined) { |  | ||||||
|                 return |  | ||||||
|             } |  | ||||||
|             for (const neededIndex of neededIndexes) { |             for (const neededIndex of neededIndexes) { | ||||||
|                 self._loadedTiles.add(neededIndex) |                 loadedTiles.add(neededIndex) | ||||||
|                 const src = constructTile(Tiles.tile_from_index(neededIndex)) |                 super.addSource(constructSource(neededIndex)) | ||||||
|                 if (src !== undefined) { |  | ||||||
|                     self.loadedTiles.set(neededIndex, src) |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -1,93 +1,68 @@ | ||||||
| import { Utils } from "../../../Utils" | import { Utils } from "../../../Utils" | ||||||
| import OsmToGeoJson from "osmtogeojson" | import OsmToGeoJson from "osmtogeojson" | ||||||
| import StaticFeatureSource from "../Sources/StaticFeatureSource" | import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource" | ||||||
| import PerLayerFeatureSourceSplitter from "../PerLayerFeatureSourceSplitter" |  | ||||||
| import { Store, UIEventSource } from "../../UIEventSource" |  | ||||||
| import FilteredLayer from "../../../Models/FilteredLayer" |  | ||||||
| import { FeatureSourceForLayer, Tiled } from "../FeatureSource" |  | ||||||
| import { Tiles } from "../../../Models/TileRange" | import { Tiles } from "../../../Models/TileRange" | ||||||
| import { BBox } from "../../BBox" | import { BBox } from "../../BBox" | ||||||
| import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig" |  | ||||||
| import { Or } from "../../Tags/Or" |  | ||||||
| import { TagsFilter } from "../../Tags/TagsFilter" | import { TagsFilter } from "../../Tags/TagsFilter" | ||||||
| import { OsmObject } from "../../Osm/OsmObject" | import { OsmObject } from "../../Osm/OsmObject" | ||||||
| import { FeatureCollection } from "@turf/turf" | import { Feature } from "geojson" | ||||||
|  | import FeatureSourceMerger from "../Sources/FeatureSourceMerger" | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * If a tile is needed (requested via the UIEventSource in the constructor), will download the appropriate tile and pass it via 'handleTile' |  * If a tile is needed (requested via the UIEventSource in the constructor), will download the appropriate tile and pass it via 'handleTile' | ||||||
|  */ |  */ | ||||||
| export default class OsmFeatureSource { | export default class OsmFeatureSource extends FeatureSourceMerger { | ||||||
|     public readonly isRunning: UIEventSource<boolean> = new UIEventSource<boolean>(false) |     private readonly _bounds: Store<BBox> | ||||||
|     public readonly downloadedTiles = new Set<number>() |     private readonly isActive: Store<boolean> | ||||||
|     public rawDataHandlers: ((osmJson: any, tileId: number) => void)[] = [] |  | ||||||
|     private readonly _backend: string |     private readonly _backend: string | ||||||
|     private readonly filteredLayers: Store<FilteredLayer[]> |  | ||||||
|     private readonly handleTile: (fs: FeatureSourceForLayer & Tiled) => void |  | ||||||
|     private isActive: Store<boolean> |  | ||||||
|     private options: { |  | ||||||
|         handleTile: (tile: FeatureSourceForLayer & Tiled) => void |  | ||||||
|         isActive: Store<boolean> |  | ||||||
|         neededTiles: Store<number[]> |  | ||||||
|         markTileVisited?: (tileId: number) => void |  | ||||||
|     } |  | ||||||
|     private readonly allowedTags: TagsFilter |     private readonly allowedTags: TagsFilter | ||||||
| 
 | 
 | ||||||
|  |     public readonly isRunning: UIEventSource<boolean> = new UIEventSource<boolean>(false) | ||||||
|  |     public rawDataHandlers: ((osmJson: any, tileIndex: number) => void)[] = [] | ||||||
|  | 
 | ||||||
|  |     private readonly _downloadedTiles: Set<number> = new Set<number>() | ||||||
|  |     private readonly _downloadedData: Feature[][] = [] | ||||||
|     /** |     /** | ||||||
|      * |      * Downloads data directly from the OSM-api within the given bounds. | ||||||
|      * @param options: allowedFeatures is normally calculated from the layoutToUse |      * All features which match the TagsFilter 'allowedFeatures' are kept and converted into geojson | ||||||
|      */ |      */ | ||||||
|     constructor(options: { |     constructor(options: { | ||||||
|         handleTile: (tile: FeatureSourceForLayer & Tiled) => void |         bounds: Store<BBox> | ||||||
|         isActive: Store<boolean> |         readonly allowedFeatures: TagsFilter | ||||||
|         neededTiles: Store<number[]> |         backend?: "https://openstreetmap.org/" | string | ||||||
|         state: { |         /** | ||||||
|             readonly filteredLayers: UIEventSource<FilteredLayer[]> |          * If given: this featureSwitch will not update if the store contains 'false' | ||||||
|             readonly osmConnection: { |          */ | ||||||
|                 Backend(): string |         isActive?: Store<boolean> | ||||||
|             } |  | ||||||
|             readonly layoutToUse?: LayoutConfig |  | ||||||
|         } |  | ||||||
|         readonly allowedFeatures?: TagsFilter |  | ||||||
|         markTileVisited?: (tileId: number) => void |  | ||||||
|     }) { |     }) { | ||||||
|         this.options = options |         super() | ||||||
|         this._backend = options.state.osmConnection.Backend() |         this._bounds = options.bounds | ||||||
|         this.filteredLayers = options.state.filteredLayers.map((layers) => |         this.allowedTags = options.allowedFeatures | ||||||
|             layers.filter((layer) => layer.layerDef.source.geojsonSource === undefined) |         this.isActive = options.isActive ?? new ImmutableStore(true) | ||||||
|         ) |         this._backend = options.backend ?? "https://www.openstreetmap.org" | ||||||
|         this.handleTile = options.handleTile |         this._bounds.addCallbackAndRunD((bbox) => this.loadData(bbox)) | ||||||
|         this.isActive = options.isActive |         console.log("Allowed tags are:", this.allowedTags) | ||||||
|         const self = this |  | ||||||
|         options.neededTiles.addCallbackAndRunD((neededTiles) => { |  | ||||||
|             self.Update(neededTiles) |  | ||||||
|         }) |  | ||||||
| 
 |  | ||||||
|         const neededLayers = (options.state.layoutToUse?.layers ?? []) |  | ||||||
|             .filter((layer) => !layer.doNotDownload) |  | ||||||
|             .filter( |  | ||||||
|                 (layer) => layer.source.geojsonSource === undefined || layer.source.isOsmCacheLayer |  | ||||||
|             ) |  | ||||||
|         this.allowedTags = |  | ||||||
|             options.allowedFeatures ?? new Or(neededLayers.map((l) => l.source.osmTags)) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private async Update(neededTiles: number[]) { |     private async loadData(bbox: BBox) { | ||||||
|         if (this.options.isActive?.data === false) { |         if (this.isActive?.data === false) { | ||||||
|  |             console.log("OsmFeatureSource: not triggering: inactive") | ||||||
|             return |             return | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         neededTiles = neededTiles.filter((tile) => !this.downloadedTiles.has(tile)) |         const z = 15 | ||||||
|  |         const neededTiles = Tiles.tileRangeFrom(bbox, z) | ||||||
| 
 | 
 | ||||||
|         if (neededTiles.length == 0) { |         if (neededTiles.total == 0) { | ||||||
|             return |             return | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.isRunning.setData(true) |         this.isRunning.setData(true) | ||||||
|         try { |         try { | ||||||
|             for (const neededTile of neededTiles) { |             const tileNumbers = Tiles.MapRange(neededTiles, (x, y) => { | ||||||
|                 this.downloadedTiles.add(neededTile) |                 return Tiles.tile_index(z, x, y) | ||||||
|                 await this.LoadTile(...Tiles.tile_from_index(neededTile)) |             }) | ||||||
|             } |             await Promise.all(tileNumbers.map((i) => this.LoadTile(...Tiles.tile_from_index(i)))) | ||||||
|         } catch (e) { |         } catch (e) { | ||||||
|             console.error(e) |             console.error(e) | ||||||
|         } finally { |         } finally { | ||||||
|  | @ -95,6 +70,11 @@ export default class OsmFeatureSource { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private registerFeatures(features: Feature[]): void { | ||||||
|  |         this._downloadedData.push(features) | ||||||
|  |         super.addData(this._downloadedData) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * The requested tile might only contain part of the relation. |      * The requested tile might only contain part of the relation. | ||||||
|      * |      * | ||||||
|  | @ -135,6 +115,11 @@ export default class OsmFeatureSource { | ||||||
|         if (z < 14) { |         if (z < 14) { | ||||||
|             throw `Zoom ${z} is too much for OSM to handle! Use a higher zoom level!` |             throw `Zoom ${z} is too much for OSM to handle! Use a higher zoom level!` | ||||||
|         } |         } | ||||||
|  |         const index = Tiles.tile_index(z, x, y) | ||||||
|  |         if (this._downloadedTiles.has(index)) { | ||||||
|  |             return | ||||||
|  |         } | ||||||
|  |         this._downloadedTiles.add(index) | ||||||
| 
 | 
 | ||||||
|         const bbox = BBox.fromTile(z, x, y) |         const bbox = BBox.fromTile(z, x, y) | ||||||
|         const url = `${this._backend}/api/0.6/map?bbox=${bbox.minLon},${bbox.minLat},${bbox.maxLon},${bbox.maxLat}` |         const url = `${this._backend}/api/0.6/map?bbox=${bbox.minLon},${bbox.minLat},${bbox.maxLon},${bbox.maxLat}` | ||||||
|  | @ -146,43 +131,28 @@ export default class OsmFeatureSource { | ||||||
|                 this.rawDataHandlers.forEach((handler) => |                 this.rawDataHandlers.forEach((handler) => | ||||||
|                     handler(osmJson, Tiles.tile_index(z, x, y)) |                     handler(osmJson, Tiles.tile_index(z, x, y)) | ||||||
|                 ) |                 ) | ||||||
|                 const geojson = <FeatureCollection<any, { id: string }>>OsmToGeoJson( |                 let features = <Feature<any, { id: string }>[]>OsmToGeoJson( | ||||||
|                     osmJson, |                     osmJson, | ||||||
|                     // @ts-ignore
 |                     // @ts-ignore
 | ||||||
|                     { |                     { | ||||||
|                         flatProperties: true, |                         flatProperties: true, | ||||||
|                     } |                     } | ||||||
|                 ) |                 ).features | ||||||
| 
 | 
 | ||||||
|                 // The geojson contains _all_ features at the given location
 |                 // The geojson contains _all_ features at the given location
 | ||||||
|                 // We only keep what is needed
 |                 // We only keep what is needed
 | ||||||
| 
 | 
 | ||||||
|                 geojson.features = geojson.features.filter((feature) => |                 features = features.filter((feature) => | ||||||
|                     this.allowedTags.matchesProperties(feature.properties) |                     this.allowedTags.matchesProperties(feature.properties) | ||||||
|                 ) |                 ) | ||||||
| 
 | 
 | ||||||
|                 for (let i = 0; i < geojson.features.length; i++) { |                 for (let i = 0; i < features.length; i++) { | ||||||
|                     geojson.features[i] = await this.patchIncompleteRelations( |                     features[i] = await this.patchIncompleteRelations(features[i], osmJson) | ||||||
|                         geojson.features[i], |  | ||||||
|                         osmJson |  | ||||||
|                     ) |  | ||||||
|                 } |                 } | ||||||
|                 geojson.features.forEach((f) => { |                 features.forEach((f) => { | ||||||
|                     f.properties["_backend"] = this._backend |                     f.properties["_backend"] = this._backend | ||||||
|                 }) |                 }) | ||||||
| 
 |                 this.registerFeatures(features) | ||||||
|                 const index = Tiles.tile_index(z, x, y) |  | ||||||
|                 new PerLayerFeatureSourceSplitter( |  | ||||||
|                     this.filteredLayers, |  | ||||||
|                     this.handleTile, |  | ||||||
|                     new StaticFeatureSource(geojson.features), |  | ||||||
|                     { |  | ||||||
|                         tileIndex: index, |  | ||||||
|                     } |  | ||||||
|                 ) |  | ||||||
|                 if (this.options.markTileVisited) { |  | ||||||
|                     this.options.markTileVisited(index) |  | ||||||
|                 } |  | ||||||
|             } catch (e) { |             } catch (e) { | ||||||
|                 console.error( |                 console.error( | ||||||
|                     "PANIC: got the tile from the OSM-api, but something crashed handling this tile" |                     "PANIC: got the tile from the OSM-api, but something crashed handling this tile" | ||||||
|  | @ -202,10 +172,12 @@ export default class OsmFeatureSource { | ||||||
|             if (e === "rate limited") { |             if (e === "rate limited") { | ||||||
|                 return |                 return | ||||||
|             } |             } | ||||||
|             await this.LoadTile(z + 1, x * 2, y * 2) |             await Promise.all([ | ||||||
|             await this.LoadTile(z + 1, 1 + x * 2, y * 2) |                 this.LoadTile(z + 1, x * 2, y * 2), | ||||||
|             await this.LoadTile(z + 1, x * 2, 1 + y * 2) |                 this.LoadTile(z + 1, 1 + x * 2, y * 2), | ||||||
|             await this.LoadTile(z + 1, 1 + x * 2, 1 + y * 2) |                 this.LoadTile(z + 1, x * 2, 1 + y * 2), | ||||||
|  |                 this.LoadTile(z + 1, 1 + x * 2, 1 + y * 2), | ||||||
|  |             ]) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (error !== undefined) { |         if (error !== undefined) { | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import FeatureSource, { Tiled } from "../FeatureSource" | import FeatureSource, { Tiled } from "../FeatureSource" | ||||||
| import { BBox } from "../../BBox" | import { BBox } from "../../BBox" | ||||||
| 
 | 
 | ||||||
| export default interface TileHierarchy<T extends FeatureSource & Tiled> { | export default interface TileHierarchy<T extends FeatureSource> { | ||||||
|     /** |     /** | ||||||
|      * A mapping from 'tile_index' to the actual tile featrues |      * A mapping from 'tile_index' to the actual tile featrues | ||||||
|      */ |      */ | ||||||
|  |  | ||||||
|  | @ -1,8 +1,9 @@ | ||||||
| import SimpleMetaTaggers, { SimpleMetaTagger } from "./SimpleMetaTagger" | import SimpleMetaTaggers, { SimpleMetaTagger } from "./SimpleMetaTagger" | ||||||
| import { ExtraFuncParams, ExtraFunctions } from "./ExtraFunctions" | import { ExtraFuncParams, ExtraFunctions } from "./ExtraFunctions" | ||||||
| import LayerConfig from "../Models/ThemeConfig/LayerConfig" | import LayerConfig from "../Models/ThemeConfig/LayerConfig" | ||||||
| import { ElementStorage } from "./ElementStorage" |  | ||||||
| import { Feature } from "geojson" | import { Feature } from "geojson" | ||||||
|  | import FeaturePropertiesStore from "./FeatureSource/Actors/FeaturePropertiesStore" | ||||||
|  | import LayoutConfig from "../Models/ThemeConfig/LayoutConfig" | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Metatagging adds various tags to the elements, e.g. lat, lon, surface area, ... |  * Metatagging adds various tags to the elements, e.g. lat, lon, surface area, ... | ||||||
|  | @ -12,7 +13,7 @@ import { Feature } from "geojson" | ||||||
| export default class MetaTagging { | export default class MetaTagging { | ||||||
|     private static errorPrintCount = 0 |     private static errorPrintCount = 0 | ||||||
|     private static readonly stopErrorOutputAt = 10 |     private static readonly stopErrorOutputAt = 10 | ||||||
|     private static retaggingFuncCache = new Map<string, ((feature: any) => void)[]>() |     private static retaggingFuncCache = new Map<string, ((feature: Feature) => void)[]>() | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * This method (re)calculates all metatags and calculated tags on every given object. |      * This method (re)calculates all metatags and calculated tags on every given object. | ||||||
|  | @ -24,7 +25,8 @@ export default class MetaTagging { | ||||||
|         features: Feature[], |         features: Feature[], | ||||||
|         params: ExtraFuncParams, |         params: ExtraFuncParams, | ||||||
|         layer: LayerConfig, |         layer: LayerConfig, | ||||||
|         state?: { allElements?: ElementStorage }, |         layout: LayoutConfig, | ||||||
|  |         featurePropertiesStores?: FeaturePropertiesStore, | ||||||
|         options?: { |         options?: { | ||||||
|             includeDates?: true | boolean |             includeDates?: true | boolean | ||||||
|             includeNonDates?: true | boolean |             includeNonDates?: true | boolean | ||||||
|  | @ -50,13 +52,14 @@ export default class MetaTagging { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // The calculated functions - per layer - which add the new keys
 |         // The calculated functions - per layer - which add the new keys
 | ||||||
|         const layerFuncs = this.createRetaggingFunc(layer, state) |         const layerFuncs = this.createRetaggingFunc(layer) | ||||||
|  |         const state = { layout } | ||||||
| 
 | 
 | ||||||
|         let atLeastOneFeatureChanged = false |         let atLeastOneFeatureChanged = false | ||||||
| 
 | 
 | ||||||
|         for (let i = 0; i < features.length; i++) { |         for (let i = 0; i < features.length; i++) { | ||||||
|             const ff = features[i] |             const feature = features[i] | ||||||
|             const feature = ff |             const tags = featurePropertiesStores?.getStore(feature.properties.id) | ||||||
|             let somethingChanged = false |             let somethingChanged = false | ||||||
|             let definedTags = new Set(Object.getOwnPropertyNames(feature.properties)) |             let definedTags = new Set(Object.getOwnPropertyNames(feature.properties)) | ||||||
|             for (const metatag of metatagsToApply) { |             for (const metatag of metatagsToApply) { | ||||||
|  | @ -72,14 +75,19 @@ export default class MetaTagging { | ||||||
|                             continue |                             continue | ||||||
|                         } |                         } | ||||||
|                         somethingChanged = true |                         somethingChanged = true | ||||||
|                         metatag.applyMetaTagsOnFeature(feature, layer, state) |                         metatag.applyMetaTagsOnFeature(feature, layer, tags, state) | ||||||
|                         if (options?.evaluateStrict) { |                         if (options?.evaluateStrict) { | ||||||
|                             for (const key of metatag.keys) { |                             for (const key of metatag.keys) { | ||||||
|                                 feature.properties[key] |                                 feature.properties[key] | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     } else { |                     } else { | ||||||
|                         const newValueAdded = metatag.applyMetaTagsOnFeature(feature, layer, state) |                         const newValueAdded = metatag.applyMetaTagsOnFeature( | ||||||
|  |                             feature, | ||||||
|  |                             layer, | ||||||
|  |                             tags, | ||||||
|  |                             state | ||||||
|  |                         ) | ||||||
|                         /* Note that the expression: |                         /* Note that the expression: | ||||||
|                          * `somethingChanged = newValueAdded || metatag.applyMetaTagsOnFeature(feature, freshness)` |                          * `somethingChanged = newValueAdded || metatag.applyMetaTagsOnFeature(feature, freshness)` | ||||||
|                          * Is WRONG |                          * Is WRONG | ||||||
|  | @ -111,7 +119,7 @@ export default class MetaTagging { | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (somethingChanged) { |             if (somethingChanged) { | ||||||
|                 state?.allElements?.getEventSourceById(feature.properties.id)?.ping() |                 featurePropertiesStores?.getStore(feature.properties.id)?.ping() | ||||||
|                 atLeastOneFeatureChanged = true |                 atLeastOneFeatureChanged = true | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | @ -199,20 +207,16 @@ export default class MetaTagging { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Creates the function which adds all the calculated tags to a feature. Called once per layer |      * Creates the function which adds all the calculated tags to a feature. Called once per layer | ||||||
|      * @param layer |  | ||||||
|      * @param state |  | ||||||
|      * @private |  | ||||||
|      */ |      */ | ||||||
|     private static createRetaggingFunc( |     private static createRetaggingFunc( | ||||||
|         layer: LayerConfig, |         layer: LayerConfig | ||||||
|         state |  | ||||||
|     ): (params: ExtraFuncParams, feature: any) => boolean { |     ): (params: ExtraFuncParams, feature: any) => boolean { | ||||||
|         const calculatedTags: [string, string, boolean][] = layer.calculatedTags |         const calculatedTags: [string, string, boolean][] = layer.calculatedTags | ||||||
|         if (calculatedTags === undefined || calculatedTags.length === 0) { |         if (calculatedTags === undefined || calculatedTags.length === 0) { | ||||||
|             return undefined |             return undefined | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         let functions: ((feature: any) => void)[] = MetaTagging.retaggingFuncCache.get(layer.id) |         let functions: ((feature: Feature) => void)[] = MetaTagging.retaggingFuncCache.get(layer.id) | ||||||
|         if (functions === undefined) { |         if (functions === undefined) { | ||||||
|             functions = MetaTagging.createFunctionsForFeature(layer.id, calculatedTags) |             functions = MetaTagging.createFunctionsForFeature(layer.id, calculatedTags) | ||||||
|             MetaTagging.retaggingFuncCache.set(layer.id, functions) |             MetaTagging.retaggingFuncCache.set(layer.id, functions) | ||||||
|  |  | ||||||
|  | @ -6,19 +6,18 @@ import { ChangeDescription, ChangeDescriptionTools } from "./Actions/ChangeDescr | ||||||
| import { Utils } from "../../Utils" | import { Utils } from "../../Utils" | ||||||
| import { LocalStorageSource } from "../Web/LocalStorageSource" | import { LocalStorageSource } from "../Web/LocalStorageSource" | ||||||
| import SimpleMetaTagger from "../SimpleMetaTagger" | import SimpleMetaTagger from "../SimpleMetaTagger" | ||||||
| import FeatureSource from "../FeatureSource/FeatureSource" | import FeatureSource, { IndexedFeatureSource } from "../FeatureSource/FeatureSource" | ||||||
| import { ElementStorage } from "../ElementStorage" |  | ||||||
| import { GeoLocationPointProperties } from "../State/GeoLocationState" | import { GeoLocationPointProperties } from "../State/GeoLocationState" | ||||||
| import { GeoOperations } from "../GeoOperations" | import { GeoOperations } from "../GeoOperations" | ||||||
| import { ChangesetHandler, ChangesetTag } from "./ChangesetHandler" | import { ChangesetHandler, ChangesetTag } from "./ChangesetHandler" | ||||||
| import { OsmConnection } from "./OsmConnection" | import { OsmConnection } from "./OsmConnection" | ||||||
|  | import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore" | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Handles all changes made to OSM. |  * Handles all changes made to OSM. | ||||||
|  * Needs an authenticator via OsmConnection |  * Needs an authenticator via OsmConnection | ||||||
|  */ |  */ | ||||||
| export class Changes { | export class Changes { | ||||||
|     public readonly name = "Newly added features" |  | ||||||
|     /** |     /** | ||||||
|      * All the newly created features as featureSource + all the modified features |      * All the newly created features as featureSource + all the modified features | ||||||
|      */ |      */ | ||||||
|  | @ -26,7 +25,7 @@ export class Changes { | ||||||
|     public readonly pendingChanges: UIEventSource<ChangeDescription[]> = |     public readonly pendingChanges: UIEventSource<ChangeDescription[]> = | ||||||
|         LocalStorageSource.GetParsed<ChangeDescription[]>("pending-changes", []) |         LocalStorageSource.GetParsed<ChangeDescription[]>("pending-changes", []) | ||||||
|     public readonly allChanges = new UIEventSource<ChangeDescription[]>(undefined) |     public readonly allChanges = new UIEventSource<ChangeDescription[]>(undefined) | ||||||
|     public readonly state: { allElements: ElementStorage; osmConnection: OsmConnection } |     public readonly state: { allElements: IndexedFeatureSource; osmConnection: OsmConnection } | ||||||
|     public readonly extraComment: UIEventSource<string> = new UIEventSource(undefined) |     public readonly extraComment: UIEventSource<string> = new UIEventSource(undefined) | ||||||
| 
 | 
 | ||||||
|     private readonly historicalUserLocations: FeatureSource |     private readonly historicalUserLocations: FeatureSource | ||||||
|  | @ -38,7 +37,9 @@ export class Changes { | ||||||
| 
 | 
 | ||||||
|     constructor( |     constructor( | ||||||
|         state?: { |         state?: { | ||||||
|             allElements: ElementStorage |             dryRun: UIEventSource<boolean> | ||||||
|  |             allElements: IndexedFeatureSource | ||||||
|  |             featurePropertiesStore: FeaturePropertiesStore | ||||||
|             osmConnection: OsmConnection |             osmConnection: OsmConnection | ||||||
|             historicalUserLocations: FeatureSource |             historicalUserLocations: FeatureSource | ||||||
|         }, |         }, | ||||||
|  | @ -50,8 +51,10 @@ export class Changes { | ||||||
|         // If a pending change contains a negative ID, we save that
 |         // If a pending change contains a negative ID, we save that
 | ||||||
|         this._nextId = Math.min(-1, ...(this.pendingChanges.data?.map((pch) => pch.id) ?? [])) |         this._nextId = Math.min(-1, ...(this.pendingChanges.data?.map((pch) => pch.id) ?? [])) | ||||||
|         this.state = state |         this.state = state | ||||||
|         this._changesetHandler = state?.osmConnection?.CreateChangesetHandler( |         this._changesetHandler = new ChangesetHandler( | ||||||
|             state.allElements, |             state.dryRun, | ||||||
|  |             state.osmConnection, | ||||||
|  |             state.featurePropertiesStore, | ||||||
|             this |             this | ||||||
|         ) |         ) | ||||||
|         this.historicalUserLocations = state.historicalUserLocations |         this.historicalUserLocations = state.historicalUserLocations | ||||||
|  | @ -187,7 +190,7 @@ export class Changes { | ||||||
| 
 | 
 | ||||||
|         const changedObjectCoordinates: [number, number][] = [] |         const changedObjectCoordinates: [number, number][] = [] | ||||||
| 
 | 
 | ||||||
|         const feature = this.state.allElements.ContainingFeatures.get(change.mainObjectId) |         const feature = this.state.allElements.featuresById.data.get(change.mainObjectId) | ||||||
|         if (feature !== undefined) { |         if (feature !== undefined) { | ||||||
|             changedObjectCoordinates.push(GeoOperations.centerpointCoordinates(feature)) |             changedObjectCoordinates.push(GeoOperations.centerpointCoordinates(feature)) | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| import escapeHtml from "escape-html" | import escapeHtml from "escape-html" | ||||||
| import UserDetails, { OsmConnection } from "./OsmConnection" | import UserDetails, { OsmConnection } from "./OsmConnection" | ||||||
| import { UIEventSource } from "../UIEventSource" | import { UIEventSource } from "../UIEventSource" | ||||||
| import { ElementStorage } from "../ElementStorage" |  | ||||||
| import Locale from "../../UI/i18n/Locale" | import Locale from "../../UI/i18n/Locale" | ||||||
| import Constants from "../../Models/Constants" | import Constants from "../../Models/Constants" | ||||||
| import { Changes } from "./Changes" | import { Changes } from "./Changes" | ||||||
|  | @ -14,12 +13,11 @@ export interface ChangesetTag { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class ChangesetHandler { | export class ChangesetHandler { | ||||||
|     private readonly allElements: ElementStorage |     private readonly allElements: { addAlias: (id0: String, id1: string) => void } | ||||||
|     private osmConnection: OsmConnection |     private osmConnection: OsmConnection | ||||||
|     private readonly changes: Changes |     private readonly changes: Changes | ||||||
|     private readonly _dryRun: UIEventSource<boolean> |     private readonly _dryRun: UIEventSource<boolean> | ||||||
|     private readonly userDetails: UIEventSource<UserDetails> |     private readonly userDetails: UIEventSource<UserDetails> | ||||||
|     private readonly auth: any |  | ||||||
|     private readonly backend: string |     private readonly backend: string | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -28,20 +26,11 @@ export class ChangesetHandler { | ||||||
|      */ |      */ | ||||||
|     private readonly _remappings = new Map<string, string>() |     private readonly _remappings = new Map<string, string>() | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Use 'osmConnection.CreateChangesetHandler' instead |  | ||||||
|      * @param dryRun |  | ||||||
|      * @param osmConnection |  | ||||||
|      * @param allElements |  | ||||||
|      * @param changes |  | ||||||
|      * @param auth |  | ||||||
|      */ |  | ||||||
|     constructor( |     constructor( | ||||||
|         dryRun: UIEventSource<boolean>, |         dryRun: UIEventSource<boolean>, | ||||||
|         osmConnection: OsmConnection, |         osmConnection: OsmConnection, | ||||||
|         allElements: ElementStorage, |         allElements: { addAlias: (id0: String, id1: string) => void }, | ||||||
|         changes: Changes, |         changes: Changes | ||||||
|         auth |  | ||||||
|     ) { |     ) { | ||||||
|         this.osmConnection = osmConnection |         this.osmConnection = osmConnection | ||||||
|         this.allElements = allElements |         this.allElements = allElements | ||||||
|  | @ -49,7 +38,6 @@ export class ChangesetHandler { | ||||||
|         this._dryRun = dryRun |         this._dryRun = dryRun | ||||||
|         this.userDetails = osmConnection.userDetails |         this.userDetails = osmConnection.userDetails | ||||||
|         this.backend = osmConnection._oauth_config.url |         this.backend = osmConnection._oauth_config.url | ||||||
|         this.auth = auth |  | ||||||
| 
 | 
 | ||||||
|         if (dryRun) { |         if (dryRun) { | ||||||
|             console.log("DRYRUN ENABLED") |             console.log("DRYRUN ENABLED") | ||||||
|  | @ -61,7 +49,7 @@ export class ChangesetHandler { | ||||||
|      * |      * | ||||||
|      * ChangesetHandler.removeDuplicateMetaTags([{key: "k", value: "v"}, {key: "k0", value: "v0"}, {key: "k", value:"v"}] // => [{key: "k", value: "v"}, {key: "k0", value: "v0"}]
 |      * ChangesetHandler.removeDuplicateMetaTags([{key: "k", value: "v"}, {key: "k0", value: "v0"}, {key: "k", value:"v"}] // => [{key: "k", value: "v"}, {key: "k0", value: "v0"}]
 | ||||||
|      */ |      */ | ||||||
|     public static removeDuplicateMetaTags(extraMetaTags: ChangesetTag[]): ChangesetTag[] { |     private static removeDuplicateMetaTags(extraMetaTags: ChangesetTag[]): ChangesetTag[] { | ||||||
|         const r: ChangesetTag[] = [] |         const r: ChangesetTag[] = [] | ||||||
|         const seen = new Set<string>() |         const seen = new Set<string>() | ||||||
|         for (const extraMetaTag of extraMetaTags) { |         for (const extraMetaTag of extraMetaTags) { | ||||||
|  | @ -82,7 +70,7 @@ export class ChangesetHandler { | ||||||
|      * @param rewriteIds |      * @param rewriteIds | ||||||
|      * @private |      * @private | ||||||
|      */ |      */ | ||||||
|     static rewriteMetaTags(extraMetaTags: ChangesetTag[], rewriteIds: Map<string, string>) { |     private static rewriteMetaTags(extraMetaTags: ChangesetTag[], rewriteIds: Map<string, string>) { | ||||||
|         let hasChange = false |         let hasChange = false | ||||||
|         for (const tag of extraMetaTags) { |         for (const tag of extraMetaTags) { | ||||||
|             const match = tag.key.match(/^([a-zA-Z0-9_]+):(node\/-[0-9])$/) |             const match = tag.key.match(/^([a-zA-Z0-9_]+):(node\/-[0-9])$/) | ||||||
|  | @ -198,7 +186,7 @@ export class ChangesetHandler { | ||||||
|      * @param rewriteIds: the mapping of ids |      * @param rewriteIds: the mapping of ids | ||||||
|      * @param oldChangesetMeta: the metadata-object of the already existing changeset |      * @param oldChangesetMeta: the metadata-object of the already existing changeset | ||||||
|      */ |      */ | ||||||
|     public RewriteTagsOf( |     private RewriteTagsOf( | ||||||
|         extraMetaTags: ChangesetTag[], |         extraMetaTags: ChangesetTag[], | ||||||
|         rewriteIds: Map<string, string>, |         rewriteIds: Map<string, string>, | ||||||
|         oldChangesetMeta: { |         oldChangesetMeta: { | ||||||
|  | @ -318,28 +306,14 @@ export class ChangesetHandler { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private async CloseChangeset(changesetId: number = undefined): Promise<void> { |     private async CloseChangeset(changesetId: number = undefined): Promise<void> { | ||||||
|         const self = this |  | ||||||
|         return new Promise<void>(function (resolve, reject) { |  | ||||||
|         if (changesetId === undefined) { |         if (changesetId === undefined) { | ||||||
|             return |             return | ||||||
|         } |         } | ||||||
|             self.auth.xhr( |         await this.osmConnection.put("changeset/" + changesetId + "/close") | ||||||
|                 { |  | ||||||
|                     method: "PUT", |  | ||||||
|                     path: "/api/0.6/changeset/" + changesetId + "/close", |  | ||||||
|                 }, |  | ||||||
|                 function (err, response) { |  | ||||||
|                     if (response == null) { |  | ||||||
|                         console.log("err", err) |  | ||||||
|                     } |  | ||||||
|         console.log("Closed changeset ", changesetId) |         console.log("Closed changeset ", changesetId) | ||||||
|                     resolve() |  | ||||||
|                 } |  | ||||||
|             ) |  | ||||||
|         }) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async GetChangesetMeta(csId: number): Promise<{ |     private async GetChangesetMeta(csId: number): Promise<{ | ||||||
|         id: number |         id: number | ||||||
|         open: boolean |         open: boolean | ||||||
|         uid: number |         uid: number | ||||||
|  | @ -358,8 +332,6 @@ export class ChangesetHandler { | ||||||
|     private async UpdateTags(csId: number, tags: ChangesetTag[]) { |     private async UpdateTags(csId: number, tags: ChangesetTag[]) { | ||||||
|         tags = ChangesetHandler.removeDuplicateMetaTags(tags) |         tags = ChangesetHandler.removeDuplicateMetaTags(tags) | ||||||
| 
 | 
 | ||||||
|         const self = this |  | ||||||
|         return new Promise<string>(function (resolve, reject) { |  | ||||||
|         tags = Utils.NoNull(tags).filter( |         tags = Utils.NoNull(tags).filter( | ||||||
|             (tag) => |             (tag) => | ||||||
|                 tag.key !== undefined && |                 tag.key !== undefined && | ||||||
|  | @ -368,24 +340,8 @@ export class ChangesetHandler { | ||||||
|                 tag.value !== "" |                 tag.value !== "" | ||||||
|         ) |         ) | ||||||
|         const metadata = tags.map((kv) => `<tag k="${kv.key}" v="${escapeHtml(kv.value)}"/>`) |         const metadata = tags.map((kv) => `<tag k="${kv.key}" v="${escapeHtml(kv.value)}"/>`) | ||||||
| 
 |         const content = [`<osm><changeset>`, metadata, `</changeset></osm>`].join("") | ||||||
|             self.auth.xhr( |         return this.osmConnection.put("changeset/" + csId, content, { "Content-Type": "text/xml" }) | ||||||
|                 { |  | ||||||
|                     method: "PUT", |  | ||||||
|                     path: "/api/0.6/changeset/" + csId, |  | ||||||
|                     options: { header: { "Content-Type": "text/xml" } }, |  | ||||||
|                     content: [`<osm><changeset>`, metadata, `</changeset></osm>`].join(""), |  | ||||||
|                 }, |  | ||||||
|                 function (err, response) { |  | ||||||
|                     if (response === undefined) { |  | ||||||
|                         console.error("Updating the tags of changeset " + csId + " failed:", err) |  | ||||||
|                         reject(err) |  | ||||||
|                     } else { |  | ||||||
|                         resolve(response) |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             ) |  | ||||||
|         }) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private defaultChangesetTags(): ChangesetTag[] { |     private defaultChangesetTags(): ChangesetTag[] { | ||||||
|  | @ -413,57 +369,35 @@ export class ChangesetHandler { | ||||||
|      * @constructor |      * @constructor | ||||||
|      * @private |      * @private | ||||||
|      */ |      */ | ||||||
|     private OpenChangeset(changesetTags: ChangesetTag[]): Promise<number> { |     private async OpenChangeset(changesetTags: ChangesetTag[]): Promise<number> { | ||||||
|         const self = this |  | ||||||
|         return new Promise<number>(function (resolve, reject) { |  | ||||||
|         const metadata = changesetTags |         const metadata = changesetTags | ||||||
|             .map((cstag) => [cstag.key, cstag.value]) |             .map((cstag) => [cstag.key, cstag.value]) | ||||||
|             .filter((kv) => (kv[1] ?? "") !== "") |             .filter((kv) => (kv[1] ?? "") !== "") | ||||||
|             .map((kv) => `<tag k="${kv[0]}" v="${escapeHtml(kv[1])}"/>`) |             .map((kv) => `<tag k="${kv[0]}" v="${escapeHtml(kv[1])}"/>`) | ||||||
|             .join("\n") |             .join("\n") | ||||||
| 
 | 
 | ||||||
|             self.auth.xhr( |         const csId = await this.osmConnection.put( | ||||||
|                 { |             "changeset/create", | ||||||
|                     method: "PUT", |             [`<osm><changeset>`, metadata, `</changeset></osm>`].join(""), | ||||||
|                     path: "/api/0.6/changeset/create", |             { "Content-Type": "text/xml" } | ||||||
|                     options: { header: { "Content-Type": "text/xml" } }, |  | ||||||
|                     content: [`<osm><changeset>`, metadata, `</changeset></osm>`].join(""), |  | ||||||
|                 }, |  | ||||||
|                 function (err, response) { |  | ||||||
|                     if (response === undefined) { |  | ||||||
|                         console.error("Opening a changeset failed:", err) |  | ||||||
|                         reject(err) |  | ||||||
|                     } else { |  | ||||||
|                         resolve(Number(response)) |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|         ) |         ) | ||||||
|         }) |         return Number(csId) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Upload a changesetXML |      * Upload a changesetXML | ||||||
|      */ |      */ | ||||||
|     private UploadChange(changesetId: number, changesetXML: string): Promise<Map<string, string>> { |     private async UploadChange( | ||||||
|         const self = this |         changesetId: number, | ||||||
|         return new Promise(function (resolve, reject) { |         changesetXML: string | ||||||
|             self.auth.xhr( |     ): Promise<Map<string, string>> { | ||||||
|                 { |         const response = await this.osmConnection.post( | ||||||
|                     method: "POST", |             "changeset/" + changesetId + "/upload", | ||||||
|                     options: { header: { "Content-Type": "text/xml" } }, |             changesetXML, | ||||||
|                     path: "/api/0.6/changeset/" + changesetId + "/upload", |             { "Content-Type": "text/xml" } | ||||||
|                     content: changesetXML, |  | ||||||
|                 }, |  | ||||||
|                 function (err, response) { |  | ||||||
|                     if (response == null) { |  | ||||||
|                         console.error("Uploading an actual change failed", err) |  | ||||||
|                         reject(err) |  | ||||||
|                     } |  | ||||||
|                     const changes = self.parseUploadChangesetResponse(response) |  | ||||||
|                     console.log("Uploaded changeset ", changesetId) |  | ||||||
|                     resolve(changes) |  | ||||||
|                 } |  | ||||||
|         ) |         ) | ||||||
|         }) |         const changes = this.parseUploadChangesetResponse(response) | ||||||
|  |         console.log("Uploaded changeset ", changesetId) | ||||||
|  |         return changes | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,13 +1,8 @@ | ||||||
| import osmAuth from "osm-auth" | import osmAuth from "osm-auth" | ||||||
| import { Store, Stores, UIEventSource } from "../UIEventSource" | import { Store, Stores, UIEventSource } from "../UIEventSource" | ||||||
| import { OsmPreferences } from "./OsmPreferences" | import { OsmPreferences } from "./OsmPreferences" | ||||||
| import { ChangesetHandler } from "./ChangesetHandler" |  | ||||||
| import { ElementStorage } from "../ElementStorage" |  | ||||||
| import Svg from "../../Svg" |  | ||||||
| import Img from "../../UI/Base/Img" |  | ||||||
| import { Utils } from "../../Utils" | import { Utils } from "../../Utils" | ||||||
| import { OsmObject } from "./OsmObject" | import { OsmObject } from "./OsmObject" | ||||||
| import { Changes } from "./Changes" |  | ||||||
| 
 | 
 | ||||||
| export default class UserDetails { | export default class UserDetails { | ||||||
|     public loggedIn = false |     public loggedIn = false | ||||||
|  | @ -148,16 +143,6 @@ export class OsmConnection { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public CreateChangesetHandler(allElements: ElementStorage, changes: Changes) { |  | ||||||
|         return new ChangesetHandler( |  | ||||||
|             this._dryRun, |  | ||||||
|             <any>/*casting is needed to make the tests work*/ this, |  | ||||||
|             allElements, |  | ||||||
|             changes, |  | ||||||
|             this.auth |  | ||||||
|         ) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public GetPreference( |     public GetPreference( | ||||||
|         key: string, |         key: string, | ||||||
|         defaultValue: string = undefined, |         defaultValue: string = undefined, | ||||||
|  | @ -288,6 +273,57 @@ export class OsmConnection { | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Interact with the API. | ||||||
|  |      * | ||||||
|  |      * @param path: the path to query, without host and without '/api/0.6'. Example 'notes/1234/close' | ||||||
|  |      */ | ||||||
|  |     public async interact( | ||||||
|  |         path: string, | ||||||
|  |         method: "GET" | "POST" | "PUT" | "DELETE", | ||||||
|  |         header?: Record<string, string | number>, | ||||||
|  |         content?: string | ||||||
|  |     ): Promise<any> { | ||||||
|  |         return new Promise((ok, error) => { | ||||||
|  |             this.auth.xhr( | ||||||
|  |                 { | ||||||
|  |                     method, | ||||||
|  |                     options: { | ||||||
|  |                         header, | ||||||
|  |                     }, | ||||||
|  |                     content, | ||||||
|  |                     path: `/api/0.6/${path}`, | ||||||
|  |                 }, | ||||||
|  |                 function (err, response) { | ||||||
|  |                     if (err !== null) { | ||||||
|  |                         error(err) | ||||||
|  |                     } else { | ||||||
|  |                         ok(response) | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             ) | ||||||
|  |         }) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public async post( | ||||||
|  |         path: string, | ||||||
|  |         content?: string, | ||||||
|  |         header?: Record<string, string | number> | ||||||
|  |     ): Promise<any> { | ||||||
|  |         return await this.interact(path, "POST", header, content) | ||||||
|  |     } | ||||||
|  |     public async put( | ||||||
|  |         path: string, | ||||||
|  |         content?: string, | ||||||
|  |         header?: Record<string, string | number> | ||||||
|  |     ): Promise<any> { | ||||||
|  |         return await this.interact(path, "PUT", header, content) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public async get(path: string, header?: Record<string, string | number>): Promise<any> { | ||||||
|  |         return await this.interact(path, "GET", header) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public closeNote(id: number | string, text?: string): Promise<void> { |     public closeNote(id: number | string, text?: string): Promise<void> { | ||||||
|         let textSuffix = "" |         let textSuffix = "" | ||||||
|         if ((text ?? "") !== "") { |         if ((text ?? "") !== "") { | ||||||
|  | @ -299,21 +335,7 @@ export class OsmConnection { | ||||||
|                 ok() |                 ok() | ||||||
|             }) |             }) | ||||||
|         } |         } | ||||||
|         return new Promise((ok, error) => { |         return this.post(`notes/${id}/close${textSuffix}`) | ||||||
|             this.auth.xhr( |  | ||||||
|                 { |  | ||||||
|                     method: "POST", |  | ||||||
|                     path: `/api/0.6/notes/${id}/close${textSuffix}`, |  | ||||||
|                 }, |  | ||||||
|                 function (err, _) { |  | ||||||
|                     if (err !== null) { |  | ||||||
|                         error(err) |  | ||||||
|                     } else { |  | ||||||
|                         ok() |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             ) |  | ||||||
|         }) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public reopenNote(id: number | string, text?: string): Promise<void> { |     public reopenNote(id: number | string, text?: string): Promise<void> { | ||||||
|  | @ -327,24 +349,10 @@ export class OsmConnection { | ||||||
|         if ((text ?? "") !== "") { |         if ((text ?? "") !== "") { | ||||||
|             textSuffix = "?text=" + encodeURIComponent(text) |             textSuffix = "?text=" + encodeURIComponent(text) | ||||||
|         } |         } | ||||||
|         return new Promise((ok, error) => { |         return this.post(`notes/${id}/reopen${textSuffix}`) | ||||||
|             this.auth.xhr( |  | ||||||
|                 { |  | ||||||
|                     method: "POST", |  | ||||||
|                     path: `/api/0.6/notes/${id}/reopen${textSuffix}`, |  | ||||||
|                 }, |  | ||||||
|                 function (err, _) { |  | ||||||
|                     if (err !== null) { |  | ||||||
|                         error(err) |  | ||||||
|                     } else { |  | ||||||
|                         ok() |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             ) |  | ||||||
|         }) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public openNote(lat: number, lon: number, text: string): Promise<{ id: number }> { |     public async openNote(lat: number, lon: number, text: string): Promise<{ id: number }> { | ||||||
|         if (this._dryRun.data) { |         if (this._dryRun.data) { | ||||||
|             console.warn("Dryrun enabled - not actually opening note with text ", text) |             console.warn("Dryrun enabled - not actually opening note with text ", text) | ||||||
|             return new Promise<{ id: number }>((ok) => { |             return new Promise<{ id: number }>((ok) => { | ||||||
|  | @ -356,29 +364,13 @@ export class OsmConnection { | ||||||
|         } |         } | ||||||
|         const auth = this.auth |         const auth = this.auth | ||||||
|         const content = { lat, lon, text } |         const content = { lat, lon, text } | ||||||
|         return new Promise((ok, error) => { |         const response = await this.post("notes.json", JSON.stringify(content), { | ||||||
|             auth.xhr( |             "Content-Type": "application/json", | ||||||
|                 { |         }) | ||||||
|                     method: "POST", |  | ||||||
|                     path: `/api/0.6/notes.json`, |  | ||||||
|                     options: { |  | ||||||
|                         header: { "Content-Type": "application/json" }, |  | ||||||
|                     }, |  | ||||||
|                     content: JSON.stringify(content), |  | ||||||
|                 }, |  | ||||||
|                 function (err, response: string) { |  | ||||||
|                     console.log("RESPONSE IS", response) |  | ||||||
|                     if (err !== null) { |  | ||||||
|                         error(err) |  | ||||||
|                     } else { |  | ||||||
|         const parsed = JSON.parse(response) |         const parsed = JSON.parse(response) | ||||||
|         const id = parsed.properties.id |         const id = parsed.properties.id | ||||||
|         console.log("OPENED NOTE", id) |         console.log("OPENED NOTE", id) | ||||||
|                         ok({ id }) |         return id | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             ) |  | ||||||
|         }) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public async uploadGpxTrack( |     public async uploadGpxTrack( | ||||||
|  | @ -434,31 +426,13 @@ export class OsmConnection { | ||||||
|         } |         } | ||||||
|         body += "--" + boundary + "--\r\n" |         body += "--" + boundary + "--\r\n" | ||||||
| 
 | 
 | ||||||
|         return new Promise((ok, error) => { |         const response = await this.post("gpx/create", body, { | ||||||
|             auth.xhr( |  | ||||||
|                 { |  | ||||||
|                     method: "POST", |  | ||||||
|                     path: `/api/0.6/gpx/create`, |  | ||||||
|                     options: { |  | ||||||
|                         header: { |  | ||||||
|             "Content-Type": "multipart/form-data; boundary=" + boundary, |             "Content-Type": "multipart/form-data; boundary=" + boundary, | ||||||
|             "Content-Length": body.length, |             "Content-Length": body.length, | ||||||
|                         }, |         }) | ||||||
|                     }, |  | ||||||
|                     content: body, |  | ||||||
|                 }, |  | ||||||
|                 function (err, response: string) { |  | ||||||
|                     console.log("RESPONSE IS", response) |  | ||||||
|                     if (err !== null) { |  | ||||||
|                         error(err) |  | ||||||
|                     } else { |  | ||||||
|         const parsed = JSON.parse(response) |         const parsed = JSON.parse(response) | ||||||
|         console.log("Uploaded GPX track", parsed) |         console.log("Uploaded GPX track", parsed) | ||||||
|                         ok({ id: parsed }) |         return { id: parsed } | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             ) |  | ||||||
|         }) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public addCommentToNote(id: number | string, text: string): Promise<void> { |     public addCommentToNote(id: number | string, text: string): Promise<void> { | ||||||
|  |  | ||||||
|  | @ -1,5 +1,4 @@ | ||||||
| import { TagsFilter } from "../Tags/TagsFilter" | import { TagsFilter } from "../Tags/TagsFilter" | ||||||
| import RelationsTracker from "./RelationsTracker" |  | ||||||
| import { Utils } from "../../Utils" | import { Utils } from "../../Utils" | ||||||
| import { ImmutableStore, Store } from "../UIEventSource" | import { ImmutableStore, Store } from "../UIEventSource" | ||||||
| import { BBox } from "../BBox" | import { BBox } from "../BBox" | ||||||
|  | @ -15,14 +14,12 @@ export class Overpass { | ||||||
|     private readonly _timeout: Store<number> |     private readonly _timeout: Store<number> | ||||||
|     private readonly _extraScripts: string[] |     private readonly _extraScripts: string[] | ||||||
|     private readonly _includeMeta: boolean |     private readonly _includeMeta: boolean | ||||||
|     private _relationTracker: RelationsTracker |  | ||||||
| 
 | 
 | ||||||
|     constructor( |     constructor( | ||||||
|         filter: TagsFilter, |         filter: TagsFilter, | ||||||
|         extraScripts: string[], |         extraScripts: string[], | ||||||
|         interpreterUrl: string, |         interpreterUrl: string, | ||||||
|         timeout?: Store<number>, |         timeout?: Store<number>, | ||||||
|         relationTracker?: RelationsTracker, |  | ||||||
|         includeMeta = true |         includeMeta = true | ||||||
|     ) { |     ) { | ||||||
|         this._timeout = timeout ?? new ImmutableStore<number>(90) |         this._timeout = timeout ?? new ImmutableStore<number>(90) | ||||||
|  | @ -34,7 +31,6 @@ export class Overpass { | ||||||
|         this._filter = optimized |         this._filter = optimized | ||||||
|         this._extraScripts = extraScripts |         this._extraScripts = extraScripts | ||||||
|         this._includeMeta = includeMeta |         this._includeMeta = includeMeta | ||||||
|         this._relationTracker = relationTracker |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public async queryGeoJson(bounds: BBox): Promise<[FeatureCollection, Date]> { |     public async queryGeoJson(bounds: BBox): Promise<[FeatureCollection, Date]> { | ||||||
|  | @ -57,7 +53,6 @@ export class Overpass { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public async ExecuteQuery(query: string): Promise<[FeatureCollection, Date]> { |     public async ExecuteQuery(query: string): Promise<[FeatureCollection, Date]> { | ||||||
|         const self = this |  | ||||||
|         const json = await Utils.downloadJson(this.buildUrl(query)) |         const json = await Utils.downloadJson(this.buildUrl(query)) | ||||||
| 
 | 
 | ||||||
|         if (json.elements.length === 0 && json.remark !== undefined) { |         if (json.elements.length === 0 && json.remark !== undefined) { | ||||||
|  | @ -68,7 +63,6 @@ export class Overpass { | ||||||
|             console.warn("No features for", json) |             console.warn("No features for", json) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         self._relationTracker?.RegisterRelations(json) |  | ||||||
|         const geojson = osmtogeojson(json) |         const geojson = osmtogeojson(json) | ||||||
|         const osmTime = new Date(json.osm3s.timestamp_osm_base) |         const osmTime = new Date(json.osm3s.timestamp_osm_base) | ||||||
|         return [<any>geojson, osmTime] |         return [<any>geojson, osmTime] | ||||||
|  | @ -104,7 +98,6 @@ export class Overpass { | ||||||
|     /** |     /** | ||||||
|      * Constructs the actual script to execute on Overpass with geocoding |      * Constructs the actual script to execute on Overpass with geocoding | ||||||
|      * 'PostCall' can be used to set an extra range, see 'AsOverpassTurboLink' |      * 'PostCall' can be used to set an extra range, see 'AsOverpassTurboLink' | ||||||
|      * |  | ||||||
|      */ |      */ | ||||||
|     public buildScriptInArea( |     public buildScriptInArea( | ||||||
|         area: { osm_type: "way" | "relation"; osm_id: number }, |         area: { osm_type: "way" | "relation"; osm_id: number }, | ||||||
|  | @ -142,7 +135,7 @@ export class Overpass { | ||||||
|      * Little helper method to quickly open overpass-turbo in the browser |      * Little helper method to quickly open overpass-turbo in the browser | ||||||
|      */ |      */ | ||||||
|     public static AsOverpassTurboLink(tags: TagsFilter) { |     public static AsOverpassTurboLink(tags: TagsFilter) { | ||||||
|         const overpass = new Overpass(tags, [], "", undefined, undefined, false) |         const overpass = new Overpass(tags, [], "", undefined, false) | ||||||
|         const script = overpass.buildScript("", "({{bbox}})", true) |         const script = overpass.buildScript("", "({{bbox}})", true) | ||||||
|         const url = "http://overpass-turbo.eu/?Q=" |         const url = "http://overpass-turbo.eu/?Q=" | ||||||
|         return url + encodeURIComponent(script) |         return url + encodeURIComponent(script) | ||||||
|  |  | ||||||
|  | @ -1,76 +0,0 @@ | ||||||
| import { UIEventSource } from "../UIEventSource" |  | ||||||
| 
 |  | ||||||
| export interface Relation { |  | ||||||
|     id: number |  | ||||||
|     type: "relation" |  | ||||||
|     members: { |  | ||||||
|         type: "way" | "node" | "relation" |  | ||||||
|         ref: number |  | ||||||
|         role: string |  | ||||||
|     }[] |  | ||||||
|     tags: any |  | ||||||
|     // Alias for tags; tags == properties
 |  | ||||||
|     properties: any |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export default class RelationsTracker { |  | ||||||
|     public knownRelations = new UIEventSource<Map<string, { role: string; relation: Relation }[]>>( |  | ||||||
|         new Map(), |  | ||||||
|         "Relation memberships" |  | ||||||
|     ) |  | ||||||
| 
 |  | ||||||
|     constructor() {} |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * Gets an overview of the relations - except for multipolygons. We don't care about those |  | ||||||
|      * @param overpassJson |  | ||||||
|      * @constructor |  | ||||||
|      */ |  | ||||||
|     private static GetRelationElements(overpassJson: any): Relation[] { |  | ||||||
|         const relations = overpassJson.elements.filter( |  | ||||||
|             (element) => element.type === "relation" && element.tags.type !== "multipolygon" |  | ||||||
|         ) |  | ||||||
|         for (const relation of relations) { |  | ||||||
|             relation.properties = relation.tags |  | ||||||
|         } |  | ||||||
|         return relations |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public RegisterRelations(overpassJson: any): void { |  | ||||||
|         this.UpdateMembershipTable(RelationsTracker.GetRelationElements(overpassJson)) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * Build a mapping of {memberId --> {role in relation, id of relation} } |  | ||||||
|      * @param relations |  | ||||||
|      * @constructor |  | ||||||
|      */ |  | ||||||
|     private UpdateMembershipTable(relations: Relation[]): void { |  | ||||||
|         const memberships = this.knownRelations.data |  | ||||||
|         let changed = false |  | ||||||
|         for (const relation of relations) { |  | ||||||
|             for (const member of relation.members) { |  | ||||||
|                 const role = { |  | ||||||
|                     role: member.role, |  | ||||||
|                     relation: relation, |  | ||||||
|                 } |  | ||||||
|                 const key = member.type + "/" + member.ref |  | ||||||
|                 if (!memberships.has(key)) { |  | ||||||
|                     memberships.set(key, []) |  | ||||||
|                 } |  | ||||||
|                 const knownRelations = memberships.get(key) |  | ||||||
| 
 |  | ||||||
|                 const alreadyExists = knownRelations.some((knownRole) => { |  | ||||||
|                     return knownRole.role === role.role && knownRole.relation === role.relation |  | ||||||
|                 }) |  | ||||||
|                 if (!alreadyExists) { |  | ||||||
|                     knownRelations.push(role) |  | ||||||
|                     changed = true |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (changed) { |  | ||||||
|             this.knownRelations.ping() |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | @ -11,21 +11,21 @@ import Constants from "../Models/Constants" | ||||||
| import { TagUtils } from "./Tags/TagUtils" | import { TagUtils } from "./Tags/TagUtils" | ||||||
| import { Feature, LineString } from "geojson" | import { Feature, LineString } from "geojson" | ||||||
| import { OsmObject } from "./Osm/OsmObject" | import { OsmObject } from "./Osm/OsmObject" | ||||||
|  | import { OsmTags } from "../Models/OsmFeature" | ||||||
|  | import { UIEventSource } from "./UIEventSource" | ||||||
|  | import LayoutConfig from "../Models/ThemeConfig/LayoutConfig" | ||||||
| 
 | 
 | ||||||
| export class SimpleMetaTagger { | export abstract class SimpleMetaTagger { | ||||||
|     public readonly keys: string[] |     public readonly keys: string[] | ||||||
|     public readonly doc: string |     public readonly doc: string | ||||||
|     public readonly isLazy: boolean |     public readonly isLazy: boolean | ||||||
|     public readonly includesDates: boolean |     public readonly includesDates: boolean | ||||||
|     public readonly applyMetaTagsOnFeature: (feature: any, layer: LayerConfig, state) => boolean |  | ||||||
| 
 | 
 | ||||||
|     /*** |     /*** | ||||||
|      * A function that adds some extra data to a feature |      * A function that adds some extra data to a feature | ||||||
|      * @param docs: what does this extra data do? |      * @param docs: what does this extra data do? | ||||||
|      * @param f: apply the changes. Returns true if something changed |  | ||||||
|      */ |      */ | ||||||
|     constructor( |     protected constructor(docs: { | ||||||
|         docs: { |  | ||||||
|         keys: string[] |         keys: string[] | ||||||
|         doc: string |         doc: string | ||||||
|         /** |         /** | ||||||
|  | @ -35,13 +35,10 @@ export class SimpleMetaTagger { | ||||||
|         includesDates?: boolean |         includesDates?: boolean | ||||||
|         isLazy?: boolean |         isLazy?: boolean | ||||||
|         cleanupRetagger?: boolean |         cleanupRetagger?: boolean | ||||||
|         }, |     }) { | ||||||
|         f: (feature: any, layer: LayerConfig, state) => boolean |  | ||||||
|     ) { |  | ||||||
|         this.keys = docs.keys |         this.keys = docs.keys | ||||||
|         this.doc = docs.doc |         this.doc = docs.doc | ||||||
|         this.isLazy = docs.isLazy |         this.isLazy = docs.isLazy | ||||||
|         this.applyMetaTagsOnFeature = f |  | ||||||
|         this.includesDates = docs.includesDates ?? false |         this.includesDates = docs.includesDates ?? false | ||||||
|         if (!docs.cleanupRetagger) { |         if (!docs.cleanupRetagger) { | ||||||
|             for (const key of docs.keys) { |             for (const key of docs.keys) { | ||||||
|  | @ -51,6 +48,20 @@ export class SimpleMetaTagger { | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Applies the metatag-calculation, returns 'true' if the upstream source needs to be pinged | ||||||
|  |      * @param feature | ||||||
|  |      * @param layer | ||||||
|  |      * @param tagsStore | ||||||
|  |      * @param state | ||||||
|  |      */ | ||||||
|  |     public abstract applyMetaTagsOnFeature( | ||||||
|  |         feature: any, | ||||||
|  |         layer: LayerConfig, | ||||||
|  |         tagsStore: UIEventSource<Record<string, string>>, | ||||||
|  |         state: { layout: LayoutConfig } | ||||||
|  |     ): boolean | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class ReferencingWaysMetaTagger extends SimpleMetaTagger { | export class ReferencingWaysMetaTagger extends SimpleMetaTagger { | ||||||
|  | @ -59,14 +70,16 @@ export class ReferencingWaysMetaTagger extends SimpleMetaTagger { | ||||||
|      * This is a bit a work-around |      * This is a bit a work-around | ||||||
|      */ |      */ | ||||||
|     public static enabled = true |     public static enabled = true | ||||||
|  | 
 | ||||||
|     constructor() { |     constructor() { | ||||||
|         super( |         super({ | ||||||
|             { |  | ||||||
|             keys: ["_referencing_ways"], |             keys: ["_referencing_ways"], | ||||||
|             isLazy: true, |             isLazy: true, | ||||||
|             doc: "_referencing_ways contains - for a node - which ways use this this node as point in their geometry. ", |             doc: "_referencing_ways contains - for a node - which ways use this this node as point in their geometry. ", | ||||||
|             }, |         }) | ||||||
|             (feature, _, state) => { |     } | ||||||
|  | 
 | ||||||
|  |     public applyMetaTagsOnFeature(feature, layer, tags, state) { | ||||||
|         if (!ReferencingWaysMetaTagger.enabled) { |         if (!ReferencingWaysMetaTagger.enabled) { | ||||||
|             return false |             return false | ||||||
|         } |         } | ||||||
|  | @ -81,10 +94,7 @@ export class ReferencingWaysMetaTagger extends SimpleMetaTagger { | ||||||
|             const wayIds = referencingWays.map((w) => "way/" + w.id) |             const wayIds = referencingWays.map((w) => "way/" + w.id) | ||||||
|             wayIds.sort() |             wayIds.sort() | ||||||
|             const wayIdsStr = wayIds.join(";") |             const wayIdsStr = wayIds.join(";") | ||||||
|                     if ( |             if (wayIdsStr !== "" && currentTagsSource.data["_referencing_ways"] !== wayIdsStr) { | ||||||
|                         wayIdsStr !== "" && |  | ||||||
|                         currentTagsSource.data["_referencing_ways"] !== wayIdsStr |  | ||||||
|                     ) { |  | ||||||
|                 currentTagsSource.data["_referencing_ways"] = wayIdsStr |                 currentTagsSource.data["_referencing_ways"] = wayIdsStr | ||||||
|                 currentTagsSource.ping() |                 currentTagsSource.ping() | ||||||
|             } |             } | ||||||
|  | @ -92,8 +102,6 @@ export class ReferencingWaysMetaTagger extends SimpleMetaTagger { | ||||||
| 
 | 
 | ||||||
|         return true |         return true | ||||||
|     } |     } | ||||||
|         ) |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class CountryTagger extends SimpleMetaTagger { | export class CountryTagger extends SimpleMetaTagger { | ||||||
|  | @ -101,18 +109,19 @@ export class CountryTagger extends SimpleMetaTagger { | ||||||
|         Constants.countryCoderEndpoint, |         Constants.countryCoderEndpoint, | ||||||
|         Utils.downloadJson |         Utils.downloadJson | ||||||
|     ) |     ) | ||||||
|     public runningTasks: Set<any> |     public runningTasks: Set<any> = new Set<any>() | ||||||
| 
 | 
 | ||||||
|     constructor() { |     constructor() { | ||||||
|         const runningTasks = new Set<any>() |         super({ | ||||||
|         super( |  | ||||||
|             { |  | ||||||
|             keys: ["_country"], |             keys: ["_country"], | ||||||
|             doc: "The country code of the property (with latlon2country)", |             doc: "The country code of the property (with latlon2country)", | ||||||
|             includesDates: false, |             includesDates: false, | ||||||
|             }, |         }) | ||||||
|             (feature, _, state) => { |     } | ||||||
|  | 
 | ||||||
|  |     applyMetaTagsOnFeature(feature, _, state) { | ||||||
|         let centerPoint: any = GeoOperations.centerpoint(feature) |         let centerPoint: any = GeoOperations.centerpoint(feature) | ||||||
|  |         const runningTasks = this.runningTasks | ||||||
|         const lat = centerPoint.geometry.coordinates[1] |         const lat = centerPoint.geometry.coordinates[1] | ||||||
|         const lon = centerPoint.geometry.coordinates[0] |         const lon = centerPoint.geometry.coordinates[0] | ||||||
|         runningTasks.add(feature) |         runningTasks.add(feature) | ||||||
|  | @ -138,13 +147,41 @@ export class CountryTagger extends SimpleMetaTagger { | ||||||
|             }) |             }) | ||||||
|         return false |         return false | ||||||
|     } |     } | ||||||
|         ) |  | ||||||
|         this.runningTasks = runningTasks |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | class InlineMetaTagger extends SimpleMetaTagger { | ||||||
|  |     constructor( | ||||||
|  |         docs: { | ||||||
|  |             keys: string[] | ||||||
|  |             doc: string | ||||||
|  |             /** | ||||||
|  |              * Set this flag if the data is volatile or date-based. | ||||||
|  |              * It'll _won't_ be cached in this case | ||||||
|  |              */ | ||||||
|  |             includesDates?: boolean | ||||||
|  |             isLazy?: boolean | ||||||
|  |             cleanupRetagger?: boolean | ||||||
|  |         }, | ||||||
|  |         f: ( | ||||||
|  |             feature: any, | ||||||
|  |             layer: LayerConfig, | ||||||
|  |             tagsStore: UIEventSource<OsmTags>, | ||||||
|  |             state: { layout: LayoutConfig } | ||||||
|  |         ) => boolean | ||||||
|  |     ) { | ||||||
|  |         super(docs) | ||||||
|  |         this.applyMetaTagsOnFeature = f | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public readonly applyMetaTagsOnFeature: ( | ||||||
|  |         feature: any, | ||||||
|  |         layer: LayerConfig, | ||||||
|  |         tagsStore: UIEventSource<OsmTags>, | ||||||
|  |         state: { layout: LayoutConfig } | ||||||
|  |     ) => boolean | ||||||
|  | } | ||||||
| export default class SimpleMetaTaggers { | export default class SimpleMetaTaggers { | ||||||
|     public static readonly objectMetaInfo = new SimpleMetaTagger( |     public static readonly objectMetaInfo = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             keys: [ |             keys: [ | ||||||
|                 "_last_edit:contributor", |                 "_last_edit:contributor", | ||||||
|  | @ -180,7 +217,7 @@ export default class SimpleMetaTaggers { | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     public static country = new CountryTagger() |     public static country = new CountryTagger() | ||||||
|     public static geometryType = new SimpleMetaTagger( |     public static geometryType = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             keys: ["_geometry:type"], |             keys: ["_geometry:type"], | ||||||
|             doc: "Adds the geometry type as property. This is identical to the GoeJson geometry type and is one of `Point`,`LineString`, `Polygon` and exceptionally `MultiPolygon` or `MultiLineString`", |             doc: "Adds the geometry type as property. This is identical to the GoeJson geometry type and is one of `Point`,`LineString`, `Polygon` and exceptionally `MultiPolygon` or `MultiLineString`", | ||||||
|  | @ -191,6 +228,7 @@ export default class SimpleMetaTaggers { | ||||||
|             return changed |             return changed | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|  |     public static referencingWays = new ReferencingWaysMetaTagger() | ||||||
|     private static readonly cardinalDirections = { |     private static readonly cardinalDirections = { | ||||||
|         N: 0, |         N: 0, | ||||||
|         NNE: 22.5, |         NNE: 22.5, | ||||||
|  | @ -209,7 +247,7 @@ export default class SimpleMetaTaggers { | ||||||
|         NW: 315, |         NW: 315, | ||||||
|         NNW: 337.5, |         NNW: 337.5, | ||||||
|     } |     } | ||||||
|     private static latlon = new SimpleMetaTagger( |     private static latlon = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             keys: ["_lat", "_lon"], |             keys: ["_lat", "_lon"], | ||||||
|             doc: "The latitude and longitude of the point (or centerpoint in the case of a way/area)", |             doc: "The latitude and longitude of the point (or centerpoint in the case of a way/area)", | ||||||
|  | @ -225,13 +263,13 @@ export default class SimpleMetaTaggers { | ||||||
|             return true |             return true | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     private static layerInfo = new SimpleMetaTagger( |     private static layerInfo = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             doc: "The layer-id to which this feature belongs. Note that this might be return any applicable if `passAllFeatures` is defined.", |             doc: "The layer-id to which this feature belongs. Note that this might be return any applicable if `passAllFeatures` is defined.", | ||||||
|             keys: ["_layer"], |             keys: ["_layer"], | ||||||
|             includesDates: false, |             includesDates: false, | ||||||
|         }, |         }, | ||||||
|         (feature, _, layer) => { |         (feature, layer) => { | ||||||
|             if (feature.properties._layer === layer.id) { |             if (feature.properties._layer === layer.id) { | ||||||
|                 return false |                 return false | ||||||
|             } |             } | ||||||
|  | @ -239,7 +277,7 @@ export default class SimpleMetaTaggers { | ||||||
|             return true |             return true | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     private static noBothButLeftRight = new SimpleMetaTagger( |     private static noBothButLeftRight = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             keys: [ |             keys: [ | ||||||
|                 "sidewalk:left", |                 "sidewalk:left", | ||||||
|  | @ -251,7 +289,7 @@ export default class SimpleMetaTaggers { | ||||||
|             includesDates: false, |             includesDates: false, | ||||||
|             cleanupRetagger: true, |             cleanupRetagger: true, | ||||||
|         }, |         }, | ||||||
|         (feature, state, layer) => { |         (feature, layer) => { | ||||||
|             if (!layer.lineRendering.some((lr) => lr.leftRightSensitive)) { |             if (!layer.lineRendering.some((lr) => lr.leftRightSensitive)) { | ||||||
|                 return |                 return | ||||||
|             } |             } | ||||||
|  | @ -259,7 +297,7 @@ export default class SimpleMetaTaggers { | ||||||
|             return SimpleMetaTaggers.removeBothTagging(feature.properties) |             return SimpleMetaTaggers.removeBothTagging(feature.properties) | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     private static surfaceArea = new SimpleMetaTagger( |     private static surfaceArea = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             keys: ["_surface", "_surface:ha"], |             keys: ["_surface", "_surface:ha"], | ||||||
|             doc: "The surface area of the feature, in square meters and in hectare. Not set on points and ways", |             doc: "The surface area of the feature, in square meters and in hectare. Not set on points and ways", | ||||||
|  | @ -292,7 +330,7 @@ export default class SimpleMetaTaggers { | ||||||
|             return true |             return true | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     private static levels = new SimpleMetaTagger( |     private static levels = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             doc: "Extract the 'level'-tag into a normalized, ';'-separated value", |             doc: "Extract the 'level'-tag into a normalized, ';'-separated value", | ||||||
|             keys: ["_level"], |             keys: ["_level"], | ||||||
|  | @ -311,15 +349,14 @@ export default class SimpleMetaTaggers { | ||||||
|             return true |             return true | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
| 
 |     private static canonicalize = new InlineMetaTagger( | ||||||
|     private static canonicalize = new SimpleMetaTagger( |  | ||||||
|         { |         { | ||||||
|             doc: "If 'units' is defined in the layoutConfig, then this metatagger will rewrite the specified keys to have the canonical form (e.g. `1meter` will be rewritten to `1m`; `1` will be rewritten to `1m` as well)", |             doc: "If 'units' is defined in the layoutConfig, then this metatagger will rewrite the specified keys to have the canonical form (e.g. `1meter` will be rewritten to `1m`; `1` will be rewritten to `1m` as well)", | ||||||
|             keys: ["Theme-defined keys"], |             keys: ["Theme-defined keys"], | ||||||
|         }, |         }, | ||||||
|         (feature, _, state) => { |         (feature, _, __, state) => { | ||||||
|             const units = Utils.NoNull( |             const units = Utils.NoNull( | ||||||
|                 [].concat(...(state?.layoutToUse?.layers?.map((layer) => layer.units) ?? [])) |                 [].concat(...(state?.layout?.layers?.map((layer) => layer.units) ?? [])) | ||||||
|             ) |             ) | ||||||
|             if (units.length == 0) { |             if (units.length == 0) { | ||||||
|                 return |                 return | ||||||
|  | @ -369,7 +406,7 @@ export default class SimpleMetaTaggers { | ||||||
|             return rewritten |             return rewritten | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     private static lngth = new SimpleMetaTagger( |     private static lngth = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             keys: ["_length", "_length:km"], |             keys: ["_length", "_length:km"], | ||||||
|             doc: "The total length of a feature in meters (and in kilometers, rounded to one decimal for '_length:km'). For a surface, the length of the perimeter", |             doc: "The total length of a feature in meters (and in kilometers, rounded to one decimal for '_length:km'). For a surface, the length of the perimeter", | ||||||
|  | @ -383,14 +420,14 @@ export default class SimpleMetaTaggers { | ||||||
|             return true |             return true | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     private static isOpen = new SimpleMetaTagger( |     private static isOpen = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             keys: ["_isOpen"], |             keys: ["_isOpen"], | ||||||
|             doc: "If 'opening_hours' is present, it will add the current state of the feature (being 'yes' or 'no')", |             doc: "If 'opening_hours' is present, it will add the current state of the feature (being 'yes' or 'no')", | ||||||
|             includesDates: true, |             includesDates: true, | ||||||
|             isLazy: true, |             isLazy: true, | ||||||
|         }, |         }, | ||||||
|         (feature, _, state) => { |         (feature) => { | ||||||
|             if (Utils.runningFromConsole) { |             if (Utils.runningFromConsole) { | ||||||
|                 // We are running from console, thus probably creating a cache
 |                 // We are running from console, thus probably creating a cache
 | ||||||
|                 // isOpen is irrelevant
 |                 // isOpen is irrelevant
 | ||||||
|  | @ -438,11 +475,9 @@ export default class SimpleMetaTaggers { | ||||||
|                     } |                     } | ||||||
|                 }, |                 }, | ||||||
|             }) |             }) | ||||||
| 
 |  | ||||||
|             const tagsSource = state.allElements.getEventSourceById(feature.properties.id) |  | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     private static directionSimplified = new SimpleMetaTagger( |     private static directionSimplified = new InlineMetaTagger( | ||||||
|         { |         { | ||||||
|             keys: ["_direction:numerical", "_direction:leftright"], |             keys: ["_direction:numerical", "_direction:leftright"], | ||||||
|             doc: "_direction:numerical is a normalized, numerical direction based on 'camera:direction' or on 'direction'; it is only present if a valid direction is found (e.g. 38.5 or NE). _direction:leftright is either 'left' or 'right', which is left-looking on the map or 'right-looking' on the map", |             doc: "_direction:numerical is a normalized, numerical direction based on 'camera:direction' or on 'direction'; it is only present if a valid direction is found (e.g. 38.5 or NE). _direction:leftright is either 'left' or 'right', which is left-looking on the map or 'right-looking' on the map", | ||||||
|  | @ -466,8 +501,7 @@ export default class SimpleMetaTaggers { | ||||||
|             return true |             return true | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
| 
 |     private static directionCenterpoint = new InlineMetaTagger( | ||||||
|     private static directionCenterpoint = new SimpleMetaTagger( |  | ||||||
|         { |         { | ||||||
|             keys: ["_direction:centerpoint"], |             keys: ["_direction:centerpoint"], | ||||||
|             isLazy: true, |             isLazy: true, | ||||||
|  | @ -500,8 +534,7 @@ export default class SimpleMetaTaggers { | ||||||
|             return true |             return true | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
| 
 |     private static currentTime = new InlineMetaTagger( | ||||||
|     private static currentTime = new SimpleMetaTagger( |  | ||||||
|         { |         { | ||||||
|             keys: ["_now:date", "_now:datetime"], |             keys: ["_now:date", "_now:datetime"], | ||||||
|             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", |             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", | ||||||
|  | @ -523,9 +556,6 @@ export default class SimpleMetaTaggers { | ||||||
|             return true |             return true | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
| 
 |  | ||||||
|     public static referencingWays = new ReferencingWaysMetaTagger() |  | ||||||
| 
 |  | ||||||
|     public static metatags: SimpleMetaTagger[] = [ |     public static metatags: SimpleMetaTagger[] = [ | ||||||
|         SimpleMetaTaggers.latlon, |         SimpleMetaTaggers.latlon, | ||||||
|         SimpleMetaTaggers.layerInfo, |         SimpleMetaTaggers.layerInfo, | ||||||
|  | @ -543,9 +573,6 @@ export default class SimpleMetaTaggers { | ||||||
|         SimpleMetaTaggers.levels, |         SimpleMetaTaggers.levels, | ||||||
|         SimpleMetaTaggers.referencingWays, |         SimpleMetaTaggers.referencingWays, | ||||||
|     ] |     ] | ||||||
|     public static readonly lazyTags: string[] = [].concat( |  | ||||||
|         ...SimpleMetaTaggers.metatags.filter((tagger) => tagger.isLazy).map((tagger) => tagger.keys) |  | ||||||
|     ) |  | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Edits the given object to rewrite 'both'-tagging into a 'left-right' tagging scheme. |      * Edits the given object to rewrite 'both'-tagging into a 'left-right' tagging scheme. | ||||||
|  |  | ||||||
|  | @ -1,34 +1,21 @@ | ||||||
| import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" | import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" | ||||||
| import FeaturePipeline from "../FeatureSource/FeaturePipeline" | import FeaturePipeline from "../FeatureSource/FeaturePipeline" | ||||||
| import { Tiles } from "../../Models/TileRange" | import { Tiles } from "../../Models/TileRange" | ||||||
| import { TileHierarchyAggregator } from "../../UI/ShowDataLayer/TileHierarchyAggregator" |  | ||||||
| import { UIEventSource } from "../UIEventSource" |  | ||||||
| import MapState from "./MapState" |  | ||||||
| import SelectedFeatureHandler from "../Actors/SelectedFeatureHandler" | import SelectedFeatureHandler from "../Actors/SelectedFeatureHandler" | ||||||
| import Hash from "../Web/Hash" | import Hash from "../Web/Hash" | ||||||
| import { BBox } from "../BBox" | import { BBox } from "../BBox" | ||||||
| import FeatureInfoBox from "../../UI/Popup/FeatureInfoBox" |  | ||||||
| import { FeatureSourceForLayer, Tiled } from "../FeatureSource/FeatureSource" | import { FeatureSourceForLayer, Tiled } from "../FeatureSource/FeatureSource" | ||||||
| import MetaTagRecalculator from "../FeatureSource/Actors/MetaTagRecalculator" | import MetaTagRecalculator from "../FeatureSource/Actors/MetaTagRecalculator" | ||||||
| import ScrollableFullScreen from "../../UI/Base/ScrollableFullScreen" |  | ||||||
| import LayerConfig from "../../Models/ThemeConfig/LayerConfig" |  | ||||||
| import ShowDataLayer from "../../UI/Map/ShowDataLayer" |  | ||||||
| 
 | 
 | ||||||
| export default class FeaturePipelineState { | export default class FeaturePipelineState { | ||||||
|     /** |     /** | ||||||
|      * The piece of code which fetches data from various sources and shows it on the background map |      * The piece of code which fetches data from various sources and shows it on the background map | ||||||
|      */ |      */ | ||||||
|     public readonly featurePipeline: FeaturePipeline |     public readonly featurePipeline: FeaturePipeline | ||||||
|     private readonly featureAggregator: TileHierarchyAggregator |  | ||||||
|     private readonly metatagRecalculator: MetaTagRecalculator |     private readonly metatagRecalculator: MetaTagRecalculator | ||||||
|     private readonly popups: Map<string, ScrollableFullScreen> = new Map< |  | ||||||
|         string, |  | ||||||
|         ScrollableFullScreen |  | ||||||
|     >() |  | ||||||
| 
 | 
 | ||||||
|     constructor(layoutToUse: LayoutConfig) { |     constructor(layoutToUse: LayoutConfig) { | ||||||
|         const clustering = layoutToUse?.clustering |         const clustering = layoutToUse?.clustering | ||||||
|         this.featureAggregator = TileHierarchyAggregator.createHierarchy(this) |  | ||||||
|         const clusterCounter = this.featureAggregator |         const clusterCounter = this.featureAggregator | ||||||
|         const self = this |         const self = this | ||||||
| 
 | 
 | ||||||
|  | @ -58,7 +45,7 @@ export default class FeaturePipelineState { | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             // Do show features indicates if the respective 'showDataLayer' should be shown. It can be hidden by e.g. clustering
 |             // Do show features indicates if the respective 'showDataLayer' should be shown. It can be hidden by e.g. clustering
 | ||||||
|             const doShowFeatures = source.features.map( |             source.features.map( | ||||||
|                 (f) => { |                 (f) => { | ||||||
|                     const z = self.locationControl.data.zoom |                     const z = self.locationControl.data.zoom | ||||||
| 
 | 
 | ||||||
|  | @ -112,14 +99,6 @@ export default class FeaturePipelineState { | ||||||
|                 }, |                 }, | ||||||
|                 [self.currentBounds, source.layer.isDisplayed, sourceBBox] |                 [self.currentBounds, source.layer.isDisplayed, sourceBBox] | ||||||
|             ) |             ) | ||||||
| 
 |  | ||||||
|             new ShowDataLayer(self.maplibreMap, { |  | ||||||
|                 features: source, |  | ||||||
|                 layer: source.layer.layerDef, |  | ||||||
|                 doShowLayer: doShowFeatures, |  | ||||||
|                 selectedElement: self.selectedElement, |  | ||||||
|                 buildPopup: (tags, layer) => self.CreatePopup(tags, layer), |  | ||||||
|             }) |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.featurePipeline = new FeaturePipeline(registerSource, this, { |         this.featurePipeline = new FeaturePipeline(registerSource, this, { | ||||||
|  | @ -132,13 +111,4 @@ export default class FeaturePipelineState { | ||||||
| 
 | 
 | ||||||
|         new SelectedFeatureHandler(Hash.hash, this) |         new SelectedFeatureHandler(Hash.hash, this) | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     public CreatePopup(tags: UIEventSource<any>, layer: LayerConfig): ScrollableFullScreen { |  | ||||||
|         if (this.popups.has(tags.data.id)) { |  | ||||||
|             return this.popups.get(tags.data.id) |  | ||||||
|         } |  | ||||||
|         const popup = new FeatureInfoBox(tags, layer, this) |  | ||||||
|         this.popups.set(tags.data.id, popup) |  | ||||||
|         return popup |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,8 +7,6 @@ export interface MapProperties { | ||||||
|     readonly zoom: UIEventSource<number> |     readonly zoom: UIEventSource<number> | ||||||
|     readonly bounds: Store<BBox> |     readonly bounds: Store<BBox> | ||||||
|     readonly rasterLayer: UIEventSource<RasterLayerPolygon | undefined> |     readonly rasterLayer: UIEventSource<RasterLayerPolygon | undefined> | ||||||
| 
 |  | ||||||
|     readonly maxbounds: UIEventSource<undefined | BBox> |     readonly maxbounds: UIEventSource<undefined | BBox> | ||||||
| 
 |  | ||||||
|     readonly allowMoving: UIEventSource<true | boolean> |     readonly allowMoving: UIEventSource<true | boolean> | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -94,7 +94,6 @@ export default class DependencyCalculator { | ||||||
| 
 | 
 | ||||||
|                     return [] |                     return [] | ||||||
|                 }, |                 }, | ||||||
|                 memberships: undefined, |  | ||||||
|             } |             } | ||||||
|             // Init the extra patched functions...
 |             // Init the extra patched functions...
 | ||||||
|             ExtraFunctions.FullPatchFeature(params, obj) |             ExtraFunctions.FullPatchFeature(params, obj) | ||||||
|  |  | ||||||
|  | @ -42,7 +42,10 @@ export interface LayerConfigJson { | ||||||
|      * |      * | ||||||
|      * Note: a source must always be defined. 'special' is only allowed if this is a builtin-layer |      * Note: a source must always be defined. 'special' is only allowed if this is a builtin-layer | ||||||
|      */ |      */ | ||||||
|     source: "special" | "special:library" | ({ |     source: | ||||||
|  |         | "special" | ||||||
|  |         | "special:library" | ||||||
|  |         | ({ | ||||||
|               /** |               /** | ||||||
|                * Every source must set which tags have to be present in order to load the given layer. |                * Every source must set which tags have to be present in order to load the given layer. | ||||||
|                */ |                */ | ||||||
|  | @ -51,26 +54,7 @@ export interface LayerConfigJson { | ||||||
|                * The maximum amount of seconds that a tile is allowed to linger in the cache |                * The maximum amount of seconds that a tile is allowed to linger in the cache | ||||||
|                */ |                */ | ||||||
|               maxCacheAge?: number |               maxCacheAge?: number | ||||||
|     } & ( |           } & { | ||||||
|         | { |  | ||||||
|               /** |  | ||||||
|                * If set, this custom overpass-script will be used instead of building one by using the OSM-tags. |  | ||||||
|                * Specifying OSM-tags is still obligatory and will still hide non-matching items and they will be used for the rest of the pipeline. |  | ||||||
|                * _This should be really rare_. |  | ||||||
|                * |  | ||||||
|                * For example, when you want to fetch all grass-areas in parks and which are marked as publicly accessible: |  | ||||||
|                * ``` |  | ||||||
|                * "source": { |  | ||||||
|                *   "overpassScript": |  | ||||||
|                *      "way[\"leisure\"=\"park\"];node(w);is_in;area._[\"leisure\"=\"park\"];(way(area)[\"landuse\"=\"grass\"]; node(w); );", |  | ||||||
|                *      "osmTags": "access=yes" |  | ||||||
|                * } |  | ||||||
|                * ``` |  | ||||||
|                * |  | ||||||
|                */ |  | ||||||
|               overpassScript?: string |  | ||||||
|           } |  | ||||||
|         | { |  | ||||||
|               /** |               /** | ||||||
|                * The actual source of the data to load, if loaded via geojson. |                * The actual source of the data to load, if loaded via geojson. | ||||||
|                * |                * | ||||||
|  | @ -104,7 +88,6 @@ export interface LayerConfigJson { | ||||||
|                */ |                */ | ||||||
|               idKey?: string |               idKey?: string | ||||||
|           }) |           }) | ||||||
|     ) |  | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * |      * | ||||||
|  |  | ||||||
|  | @ -68,6 +68,8 @@ export default class LayerConfig extends WithContextLoader { | ||||||
|     public readonly forceLoad: boolean |     public readonly forceLoad: boolean | ||||||
|     public readonly syncSelection: typeof LayerConfig.syncSelectionAllowed[number] // this is a trick to conver a constant array of strings into a type union of these values
 |     public readonly syncSelection: typeof LayerConfig.syncSelectionAllowed[number] // this is a trick to conver a constant array of strings into a type union of these values
 | ||||||
| 
 | 
 | ||||||
|  |     public readonly _needsFullNodeDatabase = false | ||||||
|  | 
 | ||||||
|     constructor(json: LayerConfigJson, context?: string, official: boolean = true) { |     constructor(json: LayerConfigJson, context?: string, official: boolean = true) { | ||||||
|         context = context + "." + json.id |         context = context + "." + json.id | ||||||
|         const translationContext = "layers:" + json.id |         const translationContext = "layers:" + json.id | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ import { RegexTag } from "../../Logic/Tags/RegexTag" | ||||||
| 
 | 
 | ||||||
| export default class SourceConfig { | export default class SourceConfig { | ||||||
|     public osmTags?: TagsFilter |     public osmTags?: TagsFilter | ||||||
|     public readonly overpassScript?: string |  | ||||||
|     public geojsonSource?: string |     public geojsonSource?: string | ||||||
|     public geojsonZoomLevel?: number |     public geojsonZoomLevel?: number | ||||||
|     public isOsmCacheLayer: boolean |     public isOsmCacheLayer: boolean | ||||||
|  | @ -68,7 +67,6 @@ export default class SourceConfig { | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         this.osmTags = params.osmTags ?? new RegexTag("id", /.*/) |         this.osmTags = params.osmTags ?? new RegexTag("id", /.*/) | ||||||
|         this.overpassScript = params.overpassScript |  | ||||||
|         this.geojsonSource = params.geojsonSource |         this.geojsonSource = params.geojsonSource | ||||||
|         this.geojsonZoomLevel = params.geojsonSourceLevel |         this.geojsonZoomLevel = params.geojsonSourceLevel | ||||||
|         this.isOsmCacheLayer = params.isOsmCache ?? false |         this.isOsmCacheLayer = params.isOsmCache ?? false | ||||||
|  |  | ||||||
|  | @ -1,3 +1,5 @@ | ||||||
|  | import { BBox } from "../Logic/BBox" | ||||||
|  | 
 | ||||||
| export interface TileRange { | export interface TileRange { | ||||||
|     xstart: number |     xstart: number | ||||||
|     ystart: number |     ystart: number | ||||||
|  | @ -85,6 +87,16 @@ export class Tiles { | ||||||
|         return { x: Tiles.lon2tile(lon, z), y: Tiles.lat2tile(lat, z), z: z } |         return { x: Tiles.lon2tile(lon, z), y: Tiles.lat2tile(lat, z), z: z } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     static tileRangeFrom(bbox: BBox, zoomlevel: number) { | ||||||
|  |         return Tiles.TileRangeBetween( | ||||||
|  |             zoomlevel, | ||||||
|  |             bbox.getNorth(), | ||||||
|  |             bbox.getWest(), | ||||||
|  |             bbox.getSouth(), | ||||||
|  |             bbox.getEast() | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     static TileRangeBetween( |     static TileRangeBetween( | ||||||
|         zoomlevel: number, |         zoomlevel: number, | ||||||
|         lat0: number, |         lat0: number, | ||||||
|  |  | ||||||
|  | @ -5,28 +5,32 @@ import MoreScreen from "./BigComponents/MoreScreen" | ||||||
| import Translations from "./i18n/Translations" | import Translations from "./i18n/Translations" | ||||||
| import Constants from "../Models/Constants" | import Constants from "../Models/Constants" | ||||||
| import { Utils } from "../Utils" | import { Utils } from "../Utils" | ||||||
| import LanguagePicker1 from "./LanguagePicker" | import LanguagePicker from "./LanguagePicker" | ||||||
| import IndexText from "./BigComponents/IndexText" | import IndexText from "./BigComponents/IndexText" | ||||||
| import FeaturedMessage from "./BigComponents/FeaturedMessage" |  | ||||||
| import { ImportViewerLinks } from "./BigComponents/UserInformation" | import { ImportViewerLinks } from "./BigComponents/UserInformation" | ||||||
| import { LoginToggle } from "./Popup/LoginButton" | import { LoginToggle } from "./Popup/LoginButton" | ||||||
|  | import { ImmutableStore } from "../Logic/UIEventSource" | ||||||
|  | import { OsmConnection } from "../Logic/Osm/OsmConnection" | ||||||
| 
 | 
 | ||||||
| export default class AllThemesGui { | export default class AllThemesGui { | ||||||
|     setup() { |     setup() { | ||||||
|         try { |         try { | ||||||
|             new FixedUiElement("").AttachTo("centermessage") |             new FixedUiElement("").AttachTo("centermessage") | ||||||
|             const state = new UserRelatedState(undefined) |             const osmConnection = new OsmConnection() | ||||||
|  |             const state = new UserRelatedState(osmConnection) | ||||||
|             const intro = new Combine([ |             const intro = new Combine([ | ||||||
|                 new LanguagePicker1(Translations.t.index.title.SupportedLanguages(), "").SetClass( |                 new LanguagePicker(Translations.t.index.title.SupportedLanguages(), "").SetClass( | ||||||
|                     "flex absolute top-2 right-3" |                     "flex absolute top-2 right-3" | ||||||
|                 ), |                 ), | ||||||
|                 new IndexText(), |                 new IndexText(), | ||||||
|             ]) |             ]) | ||||||
|             new Combine([ |             new Combine([ | ||||||
|                 intro, |                 intro, | ||||||
|                 new FeaturedMessage().SetClass("mb-4 block"), |  | ||||||
|                 new MoreScreen(state, true), |                 new MoreScreen(state, true), | ||||||
|                 new LoginToggle(undefined, Translations.t.index.logIn, state), |                 new LoginToggle(undefined, Translations.t.index.logIn, { | ||||||
|  |                     osmConnection, | ||||||
|  |                     featureSwitchUserbadge: new ImmutableStore(true), | ||||||
|  |                 }), | ||||||
|                 new ImportViewerLinks(state.osmConnection), |                 new ImportViewerLinks(state.osmConnection), | ||||||
|                 Translations.t.general.aboutMapcomplete |                 Translations.t.general.aboutMapcomplete | ||||||
|                     .Subs({ osmcha_link: Utils.OsmChaLinkFor(7) }) |                     .Subs({ osmcha_link: Utils.OsmChaLinkFor(7) }) | ||||||
|  |  | ||||||
|  | @ -1,103 +0,0 @@ | ||||||
| import Combine from "../Base/Combine" |  | ||||||
| import welcome_messages from "../../assets/welcome_message.json" |  | ||||||
| import BaseUIElement from "../BaseUIElement" |  | ||||||
| import { FixedUiElement } from "../Base/FixedUiElement" |  | ||||||
| import MoreScreen from "./MoreScreen" |  | ||||||
| import themeOverview from "../../assets/generated/theme_overview.json" |  | ||||||
| import Translations from "../i18n/Translations" |  | ||||||
| import Title from "../Base/Title" |  | ||||||
| 
 |  | ||||||
| export default class FeaturedMessage extends Combine { |  | ||||||
|     constructor() { |  | ||||||
|         const now = new Date() |  | ||||||
|         let welcome_message = undefined |  | ||||||
|         for (const wm of FeaturedMessage.WelcomeMessages()) { |  | ||||||
|             if (wm.start_date >= now) { |  | ||||||
|                 continue |  | ||||||
|             } |  | ||||||
|             if (wm.end_date <= now) { |  | ||||||
|                 continue |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             if (welcome_message !== undefined) { |  | ||||||
|                 console.warn("Multiple applicable messages today:", welcome_message.featured_theme) |  | ||||||
|             } |  | ||||||
|             welcome_message = wm |  | ||||||
|         } |  | ||||||
|         welcome_message = welcome_message ?? undefined |  | ||||||
| 
 |  | ||||||
|         super([FeaturedMessage.CreateFeaturedBox(welcome_message)]) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static WelcomeMessages(): { |  | ||||||
|         start_date: Date |  | ||||||
|         end_date: Date |  | ||||||
|         message: string |  | ||||||
|         featured_theme?: string |  | ||||||
|     }[] { |  | ||||||
|         const all_messages: { |  | ||||||
|             start_date: Date |  | ||||||
|             end_date: Date |  | ||||||
|             message: string |  | ||||||
|             featured_theme?: string |  | ||||||
|         }[] = [] |  | ||||||
| 
 |  | ||||||
|         const themesById = new Map<string, { id: string; title: any; shortDescription: any }>() |  | ||||||
|         for (const theme of themeOverview) { |  | ||||||
|             themesById.set(theme.id, theme) |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         for (const i in welcome_messages) { |  | ||||||
|             if (isNaN(Number(i))) { |  | ||||||
|                 continue |  | ||||||
|             } |  | ||||||
|             const wm = welcome_messages[i] |  | ||||||
|             if (wm === null) { |  | ||||||
|                 continue |  | ||||||
|             } |  | ||||||
|             if (themesById.get(wm.featured_theme) === undefined) { |  | ||||||
|                 console.log("THEMES BY ID:", themesById) |  | ||||||
|                 console.error("Unkown featured theme for ", wm) |  | ||||||
|                 continue |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             if (!wm.message) { |  | ||||||
|                 console.error("Featured message is missing for", wm) |  | ||||||
|                 continue |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             all_messages.push({ |  | ||||||
|                 start_date: new Date(wm.start_date), |  | ||||||
|                 end_date: new Date(wm.end_date), |  | ||||||
|                 message: wm.message, |  | ||||||
|                 featured_theme: wm.featured_theme, |  | ||||||
|             }) |  | ||||||
|         } |  | ||||||
|         return all_messages |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static CreateFeaturedBox(welcome_message: { |  | ||||||
|         message: string |  | ||||||
|         featured_theme?: string |  | ||||||
|     }): BaseUIElement { |  | ||||||
|         const els: BaseUIElement[] = [] |  | ||||||
|         if (welcome_message === undefined) { |  | ||||||
|             return undefined |  | ||||||
|         } |  | ||||||
|         const title = new Title(Translations.t.index.featuredThemeTitle.Clone()) |  | ||||||
|         const msg = new FixedUiElement(welcome_message.message).SetClass("link-underline font-lg") |  | ||||||
|         els.push(new Combine([title, msg]).SetClass("m-4")) |  | ||||||
|         if (welcome_message.featured_theme !== undefined) { |  | ||||||
|             const theme = themeOverview.filter((th) => th.id === welcome_message.featured_theme)[0] |  | ||||||
| 
 |  | ||||||
|             els.push( |  | ||||||
|                 MoreScreen.createLinkButton({}, theme) |  | ||||||
|                     .SetClass("m-4 self-center md:w-160") |  | ||||||
|                     .SetStyle("height: min-content;") |  | ||||||
|             ) |  | ||||||
|         } |  | ||||||
|         return new Combine(els).SetClass( |  | ||||||
|             "border-2 border-grey-400 rounded-xl flex flex-col md:flex-row" |  | ||||||
|         ) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | @ -7,7 +7,6 @@ import CreateNoteImportLayer from "../../Models/ThemeConfig/Conversion/CreateNot | ||||||
| import FilteredLayer, { FilterState } from "../../Models/FilteredLayer" | import FilteredLayer, { FilterState } from "../../Models/FilteredLayer" | ||||||
| import GeoJsonSource from "../../Logic/FeatureSource/Sources/GeoJsonSource" | import GeoJsonSource from "../../Logic/FeatureSource/Sources/GeoJsonSource" | ||||||
| import MetaTagging from "../../Logic/MetaTagging" | import MetaTagging from "../../Logic/MetaTagging" | ||||||
| import RelationsTracker from "../../Logic/Osm/RelationsTracker" |  | ||||||
| import FilteringFeatureSource from "../../Logic/FeatureSource/Sources/FilteringFeatureSource" | import FilteringFeatureSource from "../../Logic/FeatureSource/Sources/FilteringFeatureSource" | ||||||
| import Minimap from "../Base/Minimap" | import Minimap from "../Base/Minimap" | ||||||
| import ShowDataLayer from "../ShowDataLayer/ShowDataLayer" | import ShowDataLayer from "../ShowDataLayer/ShowDataLayer" | ||||||
|  | @ -58,7 +57,6 @@ export class CompareToAlreadyExistingNotes | ||||||
|             MetaTagging.addMetatags( |             MetaTagging.addMetatags( | ||||||
|                 f, |                 f, | ||||||
|                 { |                 { | ||||||
|                     memberships: new RelationsTracker(), |  | ||||||
|                     getFeaturesWithin: () => [], |                     getFeaturesWithin: () => [], | ||||||
|                     getFeatureById: () => undefined, |                     getFeatureById: () => undefined, | ||||||
|                 }, |                 }, | ||||||
|  |  | ||||||
|  | @ -7,7 +7,6 @@ import { BBox } from "../../Logic/BBox" | ||||||
| import { MapProperties } from "../../Models/MapProperties" | import { MapProperties } from "../../Models/MapProperties" | ||||||
| import SvelteUIElement from "../Base/SvelteUIElement" | import SvelteUIElement from "../Base/SvelteUIElement" | ||||||
| import MaplibreMap from "./MaplibreMap.svelte" | import MaplibreMap from "./MaplibreMap.svelte" | ||||||
| import Constants from "../../Models/Constants" |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * The 'MapLibreAdaptor' bridges 'MapLibre' with the various properties of the `MapProperties` |  * The 'MapLibreAdaptor' bridges 'MapLibre' with the various properties of the `MapProperties` | ||||||
|  | @ -51,7 +50,7 @@ export class MapLibreAdaptor implements MapProperties { | ||||||
|         }) |         }) | ||||||
|         this.maxbounds = state?.maxbounds ?? new UIEventSource(undefined) |         this.maxbounds = state?.maxbounds ?? new UIEventSource(undefined) | ||||||
|         this.allowMoving = state?.allowMoving ?? new UIEventSource(true) |         this.allowMoving = state?.allowMoving ?? new UIEventSource(true) | ||||||
|         this._bounds = new UIEventSource(BBox.global) |         this._bounds = new UIEventSource(undefined) | ||||||
|         this.bounds = this._bounds |         this.bounds = this._bounds | ||||||
|         this.rasterLayer = |         this.rasterLayer = | ||||||
|             state?.rasterLayer ?? new UIEventSource<RasterLayerPolygon | undefined>(undefined) |             state?.rasterLayer ?? new UIEventSource<RasterLayerPolygon | undefined>(undefined) | ||||||
|  | @ -75,6 +74,12 @@ export class MapLibreAdaptor implements MapProperties { | ||||||
|                 dt.lat = map.getCenter().lat |                 dt.lat = map.getCenter().lat | ||||||
|                 this.location.ping() |                 this.location.ping() | ||||||
|                 this.zoom.setData(Math.round(map.getZoom() * 10) / 10) |                 this.zoom.setData(Math.round(map.getZoom() * 10) / 10) | ||||||
|  |                 const bounds = map.getBounds() | ||||||
|  |                 const bbox = new BBox([ | ||||||
|  |                     [bounds.getEast(), bounds.getNorth()], | ||||||
|  |                     [bounds.getWest(), bounds.getSouth()], | ||||||
|  |                 ]) | ||||||
|  |                 self._bounds.setData(bbox) | ||||||
|             }) |             }) | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { ImmutableStore, Store } from "../../Logic/UIEventSource" | import { ImmutableStore, Store } from "../../Logic/UIEventSource" | ||||||
| import type { Map as MlMap } from "maplibre-gl" | import type { Map as MlMap } from "maplibre-gl" | ||||||
| import { Marker } from "maplibre-gl" | import { GeoJSONSource, Marker } from "maplibre-gl" | ||||||
| import { ShowDataLayerOptions } from "./ShowDataLayerOptions" | import { ShowDataLayerOptions } from "./ShowDataLayerOptions" | ||||||
| import { GeoOperations } from "../../Logic/GeoOperations" | import { GeoOperations } from "../../Logic/GeoOperations" | ||||||
| import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | ||||||
|  | @ -19,7 +19,7 @@ class PointRenderingLayer { | ||||||
|     private readonly _config: PointRenderingConfig |     private readonly _config: PointRenderingConfig | ||||||
|     private readonly _fetchStore?: (id: string) => Store<OsmTags> |     private readonly _fetchStore?: (id: string) => Store<OsmTags> | ||||||
|     private readonly _map: MlMap |     private readonly _map: MlMap | ||||||
|     private readonly _onClick: (id: string) => void |     private readonly _onClick: (feature: Feature) => void | ||||||
|     private readonly _allMarkers: Map<string, Marker> = new Map<string, Marker>() |     private readonly _allMarkers: Map<string, Marker> = new Map<string, Marker>() | ||||||
| 
 | 
 | ||||||
|     constructor( |     constructor( | ||||||
|  | @ -28,7 +28,7 @@ class PointRenderingLayer { | ||||||
|         config: PointRenderingConfig, |         config: PointRenderingConfig, | ||||||
|         visibility?: Store<boolean>, |         visibility?: Store<boolean>, | ||||||
|         fetchStore?: (id: string) => Store<OsmTags>, |         fetchStore?: (id: string) => Store<OsmTags>, | ||||||
|         onClick?: (id: string) => void |         onClick?: (feature: Feature) => void | ||||||
|     ) { |     ) { | ||||||
|         this._config = config |         this._config = config | ||||||
|         this._map = map |         this._map = map | ||||||
|  | @ -109,7 +109,7 @@ class PointRenderingLayer { | ||||||
|         if (this._onClick) { |         if (this._onClick) { | ||||||
|             const self = this |             const self = this | ||||||
|             el.addEventListener("click", function () { |             el.addEventListener("click", function () { | ||||||
|                 self._onClick(feature.properties.id) |                 self._onClick(feature) | ||||||
|             }) |             }) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -144,7 +144,7 @@ class LineRenderingLayer { | ||||||
|     private readonly _config: LineRenderingConfig |     private readonly _config: LineRenderingConfig | ||||||
|     private readonly _visibility?: Store<boolean> |     private readonly _visibility?: Store<boolean> | ||||||
|     private readonly _fetchStore?: (id: string) => Store<OsmTags> |     private readonly _fetchStore?: (id: string) => Store<OsmTags> | ||||||
|     private readonly _onClick?: (id: string) => void |     private readonly _onClick?: (feature: Feature) => void | ||||||
|     private readonly _layername: string |     private readonly _layername: string | ||||||
|     private readonly _listenerInstalledOn: Set<string> = new Set<string>() |     private readonly _listenerInstalledOn: Set<string> = new Set<string>() | ||||||
| 
 | 
 | ||||||
|  | @ -155,7 +155,7 @@ class LineRenderingLayer { | ||||||
|         config: LineRenderingConfig, |         config: LineRenderingConfig, | ||||||
|         visibility?: Store<boolean>, |         visibility?: Store<boolean>, | ||||||
|         fetchStore?: (id: string) => Store<OsmTags>, |         fetchStore?: (id: string) => Store<OsmTags>, | ||||||
|         onClick?: (id: string) => void |         onClick?: (feature: Feature) => void | ||||||
|     ) { |     ) { | ||||||
|         this._layername = layername |         this._layername = layername | ||||||
|         this._map = map |         this._map = map | ||||||
|  | @ -174,20 +174,17 @@ class LineRenderingLayer { | ||||||
|         const config = this._config |         const config = this._config | ||||||
| 
 | 
 | ||||||
|         for (const key of LineRenderingLayer.lineConfigKeys) { |         for (const key of LineRenderingLayer.lineConfigKeys) { | ||||||
|             const v = config[key]?.GetRenderValue(properties)?.Subs(properties).txt |             calculatedProps[key] = config[key]?.GetRenderValue(properties)?.Subs(properties).txt | ||||||
|             calculatedProps[key] = v |  | ||||||
|         } |         } | ||||||
|         for (const key of LineRenderingLayer.lineConfigKeysColor) { |         for (const key of LineRenderingLayer.lineConfigKeysColor) { | ||||||
|             let v = config[key]?.GetRenderValue(properties)?.Subs(properties).txt |             let v = config[key]?.GetRenderValue(properties)?.Subs(properties).txt | ||||||
|             if (v === undefined) { |             if (v === undefined) { | ||||||
|                 continue |                 continue | ||||||
|             } |             } | ||||||
|             console.log("Color", v) |  | ||||||
|             if (v.length == 9 && v.startsWith("#")) { |             if (v.length == 9 && v.startsWith("#")) { | ||||||
|                 // This includes opacity
 |                 // This includes opacity
 | ||||||
|                 calculatedProps[key + "-opacity"] = parseInt(v.substring(7), 16) / 256 |                 calculatedProps[key + "-opacity"] = parseInt(v.substring(7), 16) / 256 | ||||||
|                 v = v.substring(0, 7) |                 v = v.substring(0, 7) | ||||||
|                 console.log("Color >", v, calculatedProps[key + "-opacity"]) |  | ||||||
|             } |             } | ||||||
|             calculatedProps[key] = v |             calculatedProps[key] = v | ||||||
|         } |         } | ||||||
|  | @ -196,7 +193,6 @@ class LineRenderingLayer { | ||||||
|             calculatedProps[key] = Number(v) |             calculatedProps[key] = Number(v) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         console.log("Calculated props:", calculatedProps, "for", properties.id) |  | ||||||
|         return calculatedProps |         return calculatedProps | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -205,6 +201,8 @@ class LineRenderingLayer { | ||||||
|         while (!map.isStyleLoaded()) { |         while (!map.isStyleLoaded()) { | ||||||
|             await Utils.waitFor(100) |             await Utils.waitFor(100) | ||||||
|         } |         } | ||||||
|  |         const src = <GeoJSONSource>map.getSource(this._layername) | ||||||
|  |         if (src === undefined) { | ||||||
|             map.addSource(this._layername, { |             map.addSource(this._layername, { | ||||||
|                 type: "geojson", |                 type: "geojson", | ||||||
|                 data: { |                 data: { | ||||||
|  | @ -213,7 +211,7 @@ class LineRenderingLayer { | ||||||
|                 }, |                 }, | ||||||
|                 promoteId: "id", |                 promoteId: "id", | ||||||
|             }) |             }) | ||||||
| 
 |             // @ts-ignore
 | ||||||
|             map.addLayer({ |             map.addLayer({ | ||||||
|                 source: this._layername, |                 source: this._layername, | ||||||
|                 id: this._layername + "_line", |                 id: this._layername + "_line", | ||||||
|  | @ -224,17 +222,11 @@ class LineRenderingLayer { | ||||||
|                     "line-width": ["feature-state", "width"], |                     "line-width": ["feature-state", "width"], | ||||||
|                     "line-offset": ["feature-state", "offset"], |                     "line-offset": ["feature-state", "offset"], | ||||||
|                 }, |                 }, | ||||||
|  |                 layout: { | ||||||
|  |                     "line-cap": "round", | ||||||
|  |                 }, | ||||||
|             }) |             }) | ||||||
| 
 | 
 | ||||||
|         /*[ |  | ||||||
|             "color", |  | ||||||
|             "width", |  | ||||||
|             "dashArray", |  | ||||||
|             "lineCap", |  | ||||||
|             "offset", |  | ||||||
|             "fill", |  | ||||||
|             "fillColor", |  | ||||||
|         ]*/ |  | ||||||
|             map.addLayer({ |             map.addLayer({ | ||||||
|                 source: this._layername, |                 source: this._layername, | ||||||
|                 id: this._layername + "_polygon", |                 id: this._layername + "_polygon", | ||||||
|  | @ -246,11 +238,16 @@ class LineRenderingLayer { | ||||||
|                     "fill-opacity": 0.1, |                     "fill-opacity": 0.1, | ||||||
|                 }, |                 }, | ||||||
|             }) |             }) | ||||||
|  |         } else { | ||||||
|  |             src.setData({ | ||||||
|  |                 type: "FeatureCollection", | ||||||
|  |                 features, | ||||||
|  |             }) | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         for (let i = 0; i < features.length; i++) { |         for (let i = 0; i < features.length; i++) { | ||||||
|             const feature = features[i] |             const feature = features[i] | ||||||
|             const id = feature.properties.id ?? feature.id |             const id = feature.properties.id ?? feature.id | ||||||
|             console.log("ID is", id) |  | ||||||
|             if (id === undefined) { |             if (id === undefined) { | ||||||
|                 console.trace( |                 console.trace( | ||||||
|                     "Got a feature without ID; this causes rendering bugs:", |                     "Got a feature without ID; this causes rendering bugs:", | ||||||
|  | @ -310,23 +307,6 @@ export default class ShowDataLayer { | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private openOrReusePopup(id: string): void { |  | ||||||
|         if (!this._popupCache || !this._options.fetchStore) { |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
|         if (this._popupCache.has(id)) { |  | ||||||
|             this._popupCache.get(id).Activate() |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
|         const tags = this._options.fetchStore(id) |  | ||||||
|         if (!tags) { |  | ||||||
|             return |  | ||||||
|         } |  | ||||||
|         const popup = this._options.buildPopup(tags, this._options.layer) |  | ||||||
|         this._popupCache.set(id, popup) |  | ||||||
|         popup.Activate() |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private zoomToCurrentFeatures(map: MlMap) { |     private zoomToCurrentFeatures(map: MlMap) { | ||||||
|         if (this._options.zoomToFeatures) { |         if (this._options.zoomToFeatures) { | ||||||
|             const features = this._options.features.features.data |             const features = this._options.features.features.data | ||||||
|  | @ -338,8 +318,8 @@ export default class ShowDataLayer { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private initDrawFeatures(map: MlMap) { |     private initDrawFeatures(map: MlMap) { | ||||||
|         const { features, doShowLayer, fetchStore, buildPopup } = this._options |         const { features, doShowLayer, fetchStore, selectedElement } = this._options | ||||||
|         const onClick = buildPopup === undefined ? undefined : (id) => this.openOrReusePopup(id) |         const onClick = (feature: Feature) => selectedElement?.setData(feature) | ||||||
|         for (let i = 0; i < this._options.layer.lineRendering.length; i++) { |         for (let i = 0; i < this._options.layer.lineRendering.length; i++) { | ||||||
|             const lineRenderingConfig = this._options.layer.lineRendering[i] |             const lineRenderingConfig = this._options.layer.lineRendering[i] | ||||||
|             new LineRenderingLayer( |             new LineRenderingLayer( | ||||||
|  |  | ||||||
|  | @ -1,8 +1,5 @@ | ||||||
| import FeatureSource from "../../Logic/FeatureSource/FeatureSource" | import FeatureSource from "../../Logic/FeatureSource/FeatureSource" | ||||||
| import { Store, UIEventSource } from "../../Logic/UIEventSource" | import { Store, UIEventSource } from "../../Logic/UIEventSource" | ||||||
| import { ElementStorage } from "../../Logic/ElementStorage" |  | ||||||
| import LayerConfig from "../../Models/ThemeConfig/LayerConfig" |  | ||||||
| import ScrollableFullScreen from "../Base/ScrollableFullScreen" |  | ||||||
| import { OsmTags } from "../../Models/OsmFeature" | import { OsmTags } from "../../Models/OsmFeature" | ||||||
| 
 | 
 | ||||||
| export interface ShowDataLayerOptions { | export interface ShowDataLayerOptions { | ||||||
|  | @ -11,15 +8,10 @@ export interface ShowDataLayerOptions { | ||||||
|      */ |      */ | ||||||
|     features: FeatureSource |     features: FeatureSource | ||||||
|     /** |     /** | ||||||
|      * Indication of the current selected element; overrides some filters |      * Indication of the current selected element; overrides some filters. | ||||||
|  |      * When a feature is tapped, the feature will be put in there | ||||||
|      */ |      */ | ||||||
|     selectedElement?: UIEventSource<any> |     selectedElement?: UIEventSource<any> | ||||||
|     /** |  | ||||||
|      * What popup to build when a feature is selected |  | ||||||
|      */ |  | ||||||
|     buildPopup?: |  | ||||||
|         | undefined |  | ||||||
|         | ((tags: UIEventSource<any>, layer: LayerConfig) => ScrollableFullScreen) |  | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * If set, zoom to the features when initially loaded and when they are changed |      * If set, zoom to the features when initially loaded and when they are changed | ||||||
|  | @ -31,7 +23,8 @@ export interface ShowDataLayerOptions { | ||||||
|     doShowLayer?: Store<true | boolean> |     doShowLayer?: Store<true | boolean> | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Function which fetches the relevant store |      * Function which fetches the relevant store. | ||||||
|  |      * If given, the map will update when a property is changed | ||||||
|      */ |      */ | ||||||
|     fetchStore?: (id: string) => UIEventSource<OsmTags> |     fetchStore?: (id: string) => UIEventSource<OsmTags> | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,24 +1,35 @@ | ||||||
| /** | /** | ||||||
|  * SHows geojson on the given leaflet map, but attempts to figure out the correct layer first |  * SHows geojson on the given leaflet map, but attempts to figure out the correct layer first | ||||||
|  */ |  */ | ||||||
| import { Store } from "../../Logic/UIEventSource" | import { ImmutableStore, Store } from "../../Logic/UIEventSource" | ||||||
| import ShowDataLayer from "./ShowDataLayer" | import ShowDataLayer from "./ShowDataLayer" | ||||||
| import PerLayerFeatureSourceSplitter from "../../Logic/FeatureSource/PerLayerFeatureSourceSplitter" | import PerLayerFeatureSourceSplitter from "../../Logic/FeatureSource/PerLayerFeatureSourceSplitter" | ||||||
| import FilteredLayer from "../../Models/FilteredLayer" | import FilteredLayer from "../../Models/FilteredLayer" | ||||||
| import { ShowDataLayerOptions } from "./ShowDataLayerOptions" | import { ShowDataLayerOptions } from "./ShowDataLayerOptions" | ||||||
| import { Map as MlMap } from "maplibre-gl" | import { Map as MlMap } from "maplibre-gl" | ||||||
|  | import FilteringFeatureSource from "../../Logic/FeatureSource/Sources/FilteringFeatureSource" | ||||||
|  | import { GlobalFilter } from "../../Models/GlobalFilter" | ||||||
|  | 
 | ||||||
| export default class ShowDataMultiLayer { | export default class ShowDataMultiLayer { | ||||||
|     constructor( |     constructor( | ||||||
|         map: Store<MlMap>, |         map: Store<MlMap>, | ||||||
|         options: ShowDataLayerOptions & { layers: Store<FilteredLayer[]> } |         options: ShowDataLayerOptions & { | ||||||
|  |             layers: FilteredLayer[] | ||||||
|  |             globalFilters?: Store<GlobalFilter[]> | ||||||
|  |         } | ||||||
|     ) { |     ) { | ||||||
|         new PerLayerFeatureSourceSplitter( |         new PerLayerFeatureSourceSplitter( | ||||||
|             options.layers, |             new ImmutableStore(options.layers), | ||||||
|             (perLayer) => { |             (features, layer) => { | ||||||
|                 const newOptions = { |                 const newOptions = { | ||||||
|                     ...options, |                     ...options, | ||||||
|                     layer: perLayer.layer.layerDef, |                     layer: layer.layerDef, | ||||||
|                     features: perLayer, |                     features: new FilteringFeatureSource( | ||||||
|  |                         layer, | ||||||
|  |                         features, | ||||||
|  |                         options.fetchStore, | ||||||
|  |                         options.globalFilters | ||||||
|  |                     ), | ||||||
|                 } |                 } | ||||||
|                 new ShowDataLayer(map, newOptions) |                 new ShowDataLayer(map, newOptions) | ||||||
|             }, |             }, | ||||||
|  |  | ||||||
|  | @ -1,21 +0,0 @@ | ||||||
| import TilesourceConfig from "../../Models/ThemeConfig/TilesourceConfig" |  | ||||||
| import { UIEventSource } from "../../Logic/UIEventSource" |  | ||||||
| 
 |  | ||||||
| export default class ShowOverlayLayer { |  | ||||||
|     public static implementation: ( |  | ||||||
|         config: TilesourceConfig, |  | ||||||
|         leafletMap: UIEventSource<any>, |  | ||||||
|         isShown?: UIEventSource<boolean> |  | ||||||
|     ) => void |  | ||||||
| 
 |  | ||||||
|     constructor( |  | ||||||
|         config: TilesourceConfig, |  | ||||||
|         leafletMap: UIEventSource<any>, |  | ||||||
|         isShown: UIEventSource<boolean> = undefined |  | ||||||
|     ) { |  | ||||||
|         if (ShowOverlayLayer.implementation === undefined) { |  | ||||||
|             throw "Call ShowOverlayLayerImplemenation.initialize() first before using this" |  | ||||||
|         } |  | ||||||
|         ShowOverlayLayer.implementation(config, leafletMap, isShown) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | @ -3,6 +3,7 @@ import TilesourceConfig from "../../Models/ThemeConfig/TilesourceConfig" | ||||||
| import { UIEventSource } from "../../Logic/UIEventSource" | import { UIEventSource } from "../../Logic/UIEventSource" | ||||||
| import ShowOverlayLayer from "./ShowOverlayLayer" | import ShowOverlayLayer from "./ShowOverlayLayer" | ||||||
| 
 | 
 | ||||||
|  | // TODO port this to maplibre!
 | ||||||
| export default class ShowOverlayLayerImplementation { | export default class ShowOverlayLayerImplementation { | ||||||
|     public static Implement() { |     public static Implement() { | ||||||
|         ShowOverlayLayer.implementation = ShowOverlayLayerImplementation.AddToMap |         ShowOverlayLayer.implementation = ShowOverlayLayerImplementation.AddToMap | ||||||
|  |  | ||||||
|  | @ -1,257 +0,0 @@ | ||||||
| import FeatureSource, { |  | ||||||
|     FeatureSourceForLayer, |  | ||||||
|     Tiled, |  | ||||||
| } from "../../Logic/FeatureSource/FeatureSource" |  | ||||||
| import LayerConfig from "../../Models/ThemeConfig/LayerConfig" |  | ||||||
| import { UIEventSource } from "../../Logic/UIEventSource" |  | ||||||
| import { Tiles } from "../../Models/TileRange" |  | ||||||
| import { BBox } from "../../Logic/BBox" |  | ||||||
| import FilteredLayer from "../../Models/FilteredLayer" |  | ||||||
| import { Feature } from "geojson" |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * A feature source containing but a single feature, which keeps stats about a tile |  | ||||||
|  */ |  | ||||||
| export class TileHierarchyAggregator implements FeatureSource { |  | ||||||
|     private static readonly empty = [] |  | ||||||
|     public totalValue: number = 0 |  | ||||||
|     public showCount: number = 0 |  | ||||||
|     public hiddenCount: number = 0 |  | ||||||
|     public readonly features = new UIEventSource<Feature[]>(TileHierarchyAggregator.empty) |  | ||||||
|     public readonly name |  | ||||||
|     private _parent: TileHierarchyAggregator |  | ||||||
|     private _root: TileHierarchyAggregator |  | ||||||
|     private readonly _z: number |  | ||||||
|     private readonly _x: number |  | ||||||
|     private readonly _y: number |  | ||||||
|     private readonly _tileIndex: number |  | ||||||
|     private _counter: SingleTileCounter |  | ||||||
|     private _subtiles: [ |  | ||||||
|         TileHierarchyAggregator, |  | ||||||
|         TileHierarchyAggregator, |  | ||||||
|         TileHierarchyAggregator, |  | ||||||
|         TileHierarchyAggregator |  | ||||||
|     ] = [undefined, undefined, undefined, undefined] |  | ||||||
|     private readonly featuresStatic = [] |  | ||||||
|     private readonly featureProperties: { |  | ||||||
|         count: string |  | ||||||
|         kilocount: string |  | ||||||
|         tileId: string |  | ||||||
|         id: string |  | ||||||
|         showCount: string |  | ||||||
|         totalCount: string |  | ||||||
|     } |  | ||||||
|     private readonly _state: { filteredLayers: UIEventSource<FilteredLayer[]> } |  | ||||||
|     private readonly updateSignal = new UIEventSource<any>(undefined) |  | ||||||
| 
 |  | ||||||
|     private constructor( |  | ||||||
|         parent: TileHierarchyAggregator, |  | ||||||
|         state: { |  | ||||||
|             filteredLayers: UIEventSource<FilteredLayer[]> |  | ||||||
|         }, |  | ||||||
|         z: number, |  | ||||||
|         x: number, |  | ||||||
|         y: number |  | ||||||
|     ) { |  | ||||||
|         this._parent = parent |  | ||||||
|         this._state = state |  | ||||||
|         this._root = parent?._root ?? this |  | ||||||
|         this._z = z |  | ||||||
|         this._x = x |  | ||||||
|         this._y = y |  | ||||||
|         this._tileIndex = Tiles.tile_index(z, x, y) |  | ||||||
|         this.name = "Count(" + this._tileIndex + ")" |  | ||||||
| 
 |  | ||||||
|         const totals = { |  | ||||||
|             id: "" + this._tileIndex, |  | ||||||
|             tileId: "" + this._tileIndex, |  | ||||||
|             count: `0`, |  | ||||||
|             kilocount: "0", |  | ||||||
|             showCount: "0", |  | ||||||
|             totalCount: "0", |  | ||||||
|         } |  | ||||||
|         this.featureProperties = totals |  | ||||||
| 
 |  | ||||||
|         const now = new Date() |  | ||||||
|         const feature = { |  | ||||||
|             type: "Feature", |  | ||||||
|             properties: totals, |  | ||||||
|             geometry: { |  | ||||||
|                 type: "Point", |  | ||||||
|                 coordinates: Tiles.centerPointOf(z, x, y), |  | ||||||
|             }, |  | ||||||
|         } |  | ||||||
|         this.featuresStatic.push({ feature: feature, freshness: now }) |  | ||||||
| 
 |  | ||||||
|         const bbox = BBox.fromTile(z, x, y) |  | ||||||
|         const box = { |  | ||||||
|             type: "Feature", |  | ||||||
|             properties: totals, |  | ||||||
|             geometry: { |  | ||||||
|                 type: "Polygon", |  | ||||||
|                 coordinates: [ |  | ||||||
|                     [ |  | ||||||
|                         [bbox.minLon, bbox.minLat], |  | ||||||
|                         [bbox.minLon, bbox.maxLat], |  | ||||||
|                         [bbox.maxLon, bbox.maxLat], |  | ||||||
|                         [bbox.maxLon, bbox.minLat], |  | ||||||
|                         [bbox.minLon, bbox.minLat], |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             }, |  | ||||||
|         } |  | ||||||
|         this.featuresStatic.push({ feature: box, freshness: now }) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static createHierarchy(state: { filteredLayers: UIEventSource<FilteredLayer[]> }) { |  | ||||||
|         return new TileHierarchyAggregator(undefined, state, 0, 0, 0) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public getTile(tileIndex): TileHierarchyAggregator { |  | ||||||
|         if (tileIndex === this._tileIndex) { |  | ||||||
|             return this |  | ||||||
|         } |  | ||||||
|         let [tileZ, tileX, tileY] = Tiles.tile_from_index(tileIndex) |  | ||||||
|         while (tileZ - 1 > this._z) { |  | ||||||
|             tileX = Math.floor(tileX / 2) |  | ||||||
|             tileY = Math.floor(tileY / 2) |  | ||||||
|             tileZ-- |  | ||||||
|         } |  | ||||||
|         const xDiff = tileX - 2 * this._x |  | ||||||
|         const yDiff = tileY - 2 * this._y |  | ||||||
|         const subtileIndex = yDiff * 2 + xDiff |  | ||||||
|         return this._subtiles[subtileIndex]?.getTile(tileIndex) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public addTile(source: FeatureSourceForLayer & Tiled) { |  | ||||||
|         const self = this |  | ||||||
|         if (source.tileIndex === this._tileIndex) { |  | ||||||
|             if (this._counter === undefined) { |  | ||||||
|                 this._counter = new SingleTileCounter(this._tileIndex) |  | ||||||
|                 this._counter.countsPerLayer.addCallbackAndRun((_) => self.update()) |  | ||||||
|             } |  | ||||||
|             this._counter.addTileCount(source) |  | ||||||
|         } else { |  | ||||||
|             // We have to give it to one of the subtiles
 |  | ||||||
|             let [tileZ, tileX, tileY] = Tiles.tile_from_index(source.tileIndex) |  | ||||||
|             while (tileZ - 1 > this._z) { |  | ||||||
|                 tileX = Math.floor(tileX / 2) |  | ||||||
|                 tileY = Math.floor(tileY / 2) |  | ||||||
|                 tileZ-- |  | ||||||
|             } |  | ||||||
|             const xDiff = tileX - 2 * this._x |  | ||||||
|             const yDiff = tileY - 2 * this._y |  | ||||||
| 
 |  | ||||||
|             const subtileIndex = yDiff * 2 + xDiff |  | ||||||
|             if (this._subtiles[subtileIndex] === undefined) { |  | ||||||
|                 this._subtiles[subtileIndex] = new TileHierarchyAggregator( |  | ||||||
|                     this, |  | ||||||
|                     this._state, |  | ||||||
|                     tileZ, |  | ||||||
|                     tileX, |  | ||||||
|                     tileY |  | ||||||
|                 ) |  | ||||||
|             } |  | ||||||
|             this._subtiles[subtileIndex].addTile(source) |  | ||||||
|         } |  | ||||||
|         this.updateSignal.setData(source) |  | ||||||
|     } |  | ||||||
|     private update() { |  | ||||||
|         const newMap = new Map<string, number>() |  | ||||||
|         let total = 0 |  | ||||||
|         let hiddenCount = 0 |  | ||||||
|         let showCount = 0 |  | ||||||
|         let isShown: Map<string, FilteredLayer> = new Map<string, FilteredLayer>() |  | ||||||
|         for (const filteredLayer of this._state.filteredLayers.data) { |  | ||||||
|             isShown.set(filteredLayer.layerDef.id, filteredLayer) |  | ||||||
|         } |  | ||||||
|         this?._counter?.countsPerLayer?.data?.forEach((count, layerId) => { |  | ||||||
|             newMap.set("layer:" + layerId, count) |  | ||||||
|             total += count |  | ||||||
|             this.featureProperties["direct_layer:" + layerId] = count |  | ||||||
|             const flayer = isShown.get(layerId) |  | ||||||
|             if (flayer.isDisplayed.data && this._z >= flayer.layerDef.minzoom) { |  | ||||||
|                 showCount += count |  | ||||||
|             } else { |  | ||||||
|                 hiddenCount += count |  | ||||||
|             } |  | ||||||
|         }) |  | ||||||
| 
 |  | ||||||
|         for (const tile of this._subtiles) { |  | ||||||
|             if (tile === undefined) { |  | ||||||
|                 continue |  | ||||||
|             } |  | ||||||
|             total += tile.totalValue |  | ||||||
| 
 |  | ||||||
|             showCount += tile.showCount |  | ||||||
|             hiddenCount += tile.hiddenCount |  | ||||||
| 
 |  | ||||||
|             for (const key in tile.featureProperties) { |  | ||||||
|                 if (key.startsWith("layer:")) { |  | ||||||
|                     newMap.set( |  | ||||||
|                         key, |  | ||||||
|                         (newMap.get(key) ?? 0) + Number(tile.featureProperties[key] ?? 0) |  | ||||||
|                     ) |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         this.totalValue = total |  | ||||||
|         this.showCount = showCount |  | ||||||
|         this.hiddenCount = hiddenCount |  | ||||||
|         this._parent?.update() |  | ||||||
| 
 |  | ||||||
|         if (total === 0) { |  | ||||||
|             this.features.setData(TileHierarchyAggregator.empty) |  | ||||||
|         } else { |  | ||||||
|             this.featureProperties.count = "" + total |  | ||||||
|             this.featureProperties.kilocount = "" + Math.floor(total / 1000) |  | ||||||
|             this.featureProperties.showCount = "" + showCount |  | ||||||
|             this.featureProperties.totalCount = "" + total |  | ||||||
|             newMap.forEach((value, key) => { |  | ||||||
|                 this.featureProperties[key] = "" + value |  | ||||||
|             }) |  | ||||||
| 
 |  | ||||||
|             this.features.data = this.featuresStatic |  | ||||||
|             this.features.ping() |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Keeps track of a single tile |  | ||||||
|  */ |  | ||||||
| class SingleTileCounter implements Tiled { |  | ||||||
|     public readonly bbox: BBox |  | ||||||
|     public readonly tileIndex: number |  | ||||||
|     public readonly countsPerLayer: UIEventSource<Map<string, number>> = new UIEventSource< |  | ||||||
|         Map<string, number> |  | ||||||
|     >(new Map<string, number>()) |  | ||||||
|     public readonly z: number |  | ||||||
|     public readonly x: number |  | ||||||
|     public readonly y: number |  | ||||||
|     private readonly registeredLayers: Map<string, LayerConfig> = new Map<string, LayerConfig>() |  | ||||||
| 
 |  | ||||||
|     constructor(tileIndex: number) { |  | ||||||
|         this.tileIndex = tileIndex |  | ||||||
|         this.bbox = BBox.fromTileIndex(tileIndex) |  | ||||||
|         const [z, x, y] = Tiles.tile_from_index(tileIndex) |  | ||||||
|         this.z = z |  | ||||||
|         this.x = x |  | ||||||
|         this.y = y |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public addTileCount(source: FeatureSourceForLayer) { |  | ||||||
|         const layer = source.layer.layerDef |  | ||||||
|         this.registeredLayers.set(layer.id, layer) |  | ||||||
|         const self = this |  | ||||||
|         source.features.map( |  | ||||||
|             (f) => { |  | ||||||
|                 const isDisplayed = source.layer.isDisplayed.data |  | ||||||
|                 self.countsPerLayer.data.set(layer.id, isDisplayed ? f.length : 0) |  | ||||||
|                 self.countsPerLayer.ping() |  | ||||||
|             }, |  | ||||||
|             [source.layer.isDisplayed] |  | ||||||
|         ) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | @ -11,7 +11,6 @@ | ||||||
|   import { QueryParameters } from "../Logic/Web/QueryParameters"; |   import { QueryParameters } from "../Logic/Web/QueryParameters"; | ||||||
|   import UserRelatedState from "../Logic/State/UserRelatedState"; |   import UserRelatedState from "../Logic/State/UserRelatedState"; | ||||||
|   import GeoLocationHandler from "../Logic/Actors/GeoLocationHandler"; |   import GeoLocationHandler from "../Logic/Actors/GeoLocationHandler"; | ||||||
|   import { ElementStorage } from "../Logic/ElementStorage"; |  | ||||||
|   import { Changes } from "../Logic/Osm/Changes"; |   import { Changes } from "../Logic/Osm/Changes"; | ||||||
|   import ChangeToElementsActor from "../Logic/Actors/ChangeToElementsActor"; |   import ChangeToElementsActor from "../Logic/Actors/ChangeToElementsActor"; | ||||||
|   import PendingChangesUploader from "../Logic/Actors/PendingChangesUploader"; |   import PendingChangesUploader from "../Logic/Actors/PendingChangesUploader"; | ||||||
|  | @ -28,6 +27,12 @@ | ||||||
|   import LayerState from "../Logic/State/LayerState"; |   import LayerState from "../Logic/State/LayerState"; | ||||||
|   import Constants from "../Models/Constants"; |   import Constants from "../Models/Constants"; | ||||||
|   import type { Feature } from "geojson"; |   import type { Feature } from "geojson"; | ||||||
|  |   import FeaturePropertiesStore from "../Logic/FeatureSource/Actors/FeaturePropertiesStore"; | ||||||
|  |   import ShowDataMultiLayer from "./Map/ShowDataMultiLayer"; | ||||||
|  |   import { Or } from "../Logic/Tags/Or"; | ||||||
|  |   import LayoutSource from "../Logic/FeatureSource/LayoutSource"; | ||||||
|  |   import { type OsmTags } from "../Models/OsmFeature"; | ||||||
|  | 
 | ||||||
|   export let layout: LayoutConfig; |   export let layout: LayoutConfig; | ||||||
| 
 | 
 | ||||||
|   const maplibremap: UIEventSource<MlMap> = new UIEventSource<MlMap>(undefined); |   const maplibremap: UIEventSource<MlMap> = new UIEventSource<MlMap>(undefined); | ||||||
|  | @ -49,16 +54,34 @@ | ||||||
|   }); |   }); | ||||||
|   const userRelatedState = new UserRelatedState(osmConnection, layout?.language); |   const userRelatedState = new UserRelatedState(osmConnection, layout?.language); | ||||||
|   const selectedElement = new UIEventSource<Feature | undefined>(undefined, "Selected element"); |   const selectedElement = new UIEventSource<Feature | undefined>(undefined, "Selected element"); | ||||||
|  |   selectedElement.addCallbackAndRunD(s => console.log("Selected element:", s)) | ||||||
|   const geolocation = new GeoLocationHandler(geolocationState, selectedElement, mapproperties, userRelatedState.gpsLocationHistoryRetentionTime); |   const geolocation = new GeoLocationHandler(geolocationState, selectedElement, mapproperties, userRelatedState.gpsLocationHistoryRetentionTime); | ||||||
| 
 | 
 | ||||||
|   const allElements = new ElementStorage(); |   const tags = new Or(layout.layers.filter(l => l.source !== null&& Constants.priviliged_layers.indexOf(l.id) < 0 && l.source.geojsonSource === undefined).map(l => l.source.osmTags )) | ||||||
|  |   const layerState = new LayerState(osmConnection, layout.layers, layout.id) | ||||||
|  |    | ||||||
|  |   const indexedElements = new LayoutSource(layout.layers, featureSwitches, new StaticFeatureSource([]), mapproperties, osmConnection.Backend(), | ||||||
|  |     (id) => layerState.filteredLayers.get(id).isDisplayed | ||||||
|  |   ) | ||||||
|  | 
 | ||||||
|  |   const allElements = new FeaturePropertiesStore(indexedElements) | ||||||
|   const changes = new Changes({ |   const changes = new Changes({ | ||||||
|     allElements, |     dryRun: featureSwitches.featureSwitchIsTesting, | ||||||
|  |     allElements: indexedElements, | ||||||
|  |     featurePropertiesStore: allElements, | ||||||
|     osmConnection, |     osmConnection, | ||||||
|     historicalUserLocations: geolocation.historicalUserLocations |     historicalUserLocations: geolocation.historicalUserLocations | ||||||
|   }, layout?.isLeftRightSensitive() ?? false); |   }, layout?.isLeftRightSensitive() ?? false); | ||||||
|   console.log("Setting up layerstate...") | 
 | ||||||
|   const layerState = new LayerState(osmConnection, layout.layers, layout.id) |   new ShowDataMultiLayer(maplibremap, { | ||||||
|  |     layers: Array.from(layerState.filteredLayers.values()), | ||||||
|  |     features: indexedElements, | ||||||
|  |     fetchStore: id => <UIEventSource<OsmTags>> allElements.getStore(id), | ||||||
|  |     selectedElement, | ||||||
|  |     globalFilters: layerState.globalFilters | ||||||
|  |   }) | ||||||
|  | 
 | ||||||
|  |    | ||||||
|   { |   { | ||||||
|     // Various actors that we don't need to reference  |     // Various actors that we don't need to reference  | ||||||
|     // TODO enable new TitleHandler(selectedElement,layout,allElements) |     // TODO enable new TitleHandler(selectedElement,layout,allElements) | ||||||
|  | @ -98,7 +121,7 @@ | ||||||
|       current_view: new StaticFeatureSource(mapproperties.bounds.map(bbox => bbox === undefined ? empty : <Feature[]> [bbox.asGeoJson({id:"current_view"})])), |       current_view: new StaticFeatureSource(mapproperties.bounds.map(bbox => bbox === undefined ? empty : <Feature[]> [bbox.asGeoJson({id:"current_view"})])), | ||||||
|     } |     } | ||||||
|     layerState.filteredLayers.get("range")?.isDisplayed?.syncWith(featureSwitches.featureSwitchIsTesting, true) |     layerState.filteredLayers.get("range")?.isDisplayed?.syncWith(featureSwitches.featureSwitchIsTesting, true) | ||||||
| console.log("RAnge fs", specialLayers.range) |      | ||||||
|     specialLayers.range.features.addCallbackAndRun(fs => console.log("Range.features:", JSON.stringify(fs))) |     specialLayers.range.features.addCallbackAndRun(fs => console.log("Range.features:", JSON.stringify(fs))) | ||||||
|     layerState.filteredLayers.forEach((flayer) => { |     layerState.filteredLayers.forEach((flayer) => { | ||||||
|       const features = specialLayers[flayer.layerDef.id] |       const features = specialLayers[flayer.layerDef.id] | ||||||
|  | @ -116,7 +139,8 @@ console.log("RAnge fs", specialLayers.range) | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| <div class="h-screen w-screen absolute top-0 left-0 border-3 border-red-500"> | <div class="h-screen w-screen absolute top-0 left-0 flex"> | ||||||
|  |   <div id="fullscreen" class="transition-all transition-duration-500" style="border: 2px solid red">Hello world</div> | ||||||
|   <MaplibreMap class="w-full h-full border border-black" map={maplibremap}></MaplibreMap> |   <MaplibreMap class="w-full h-full border border-black" map={maplibremap}></MaplibreMap> | ||||||
| </div> | </div> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,70 +0,0 @@ | ||||||
| { |  | ||||||
|   "id": "grass_in_parks", |  | ||||||
|   "name": { |  | ||||||
|     "nl": "Toegankelijke grasvelden in parken" |  | ||||||
|   }, |  | ||||||
|   "source": { |  | ||||||
|     "osmTags": { |  | ||||||
|       "or": [ |  | ||||||
|         "name=Park Oude God", |  | ||||||
|         { |  | ||||||
|           "and": [ |  | ||||||
|             "landuse=grass", |  | ||||||
|             { |  | ||||||
|               "or": [ |  | ||||||
|                 "access=public", |  | ||||||
|                 "access=yes" |  | ||||||
|               ] |  | ||||||
|             } |  | ||||||
|           ] |  | ||||||
|         } |  | ||||||
|       ] |  | ||||||
|     }, |  | ||||||
|     "overpassScript": "way[\"leisure\"=\"park\"];node(w);is_in;area._[\"leisure\"=\"park\"];(way(area)[\"landuse\"=\"grass\"]; node(w); );" |  | ||||||
|   }, |  | ||||||
|   "minzoom": 0, |  | ||||||
|   "title": { |  | ||||||
|     "render": { |  | ||||||
|       "nl": "Speelweide in een park" |  | ||||||
|     }, |  | ||||||
|     "mappings": [ |  | ||||||
|       { |  | ||||||
|         "if": "name~*", |  | ||||||
|         "then": { |  | ||||||
|           "nl": "{name}" |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ] |  | ||||||
|   }, |  | ||||||
|   "tagRenderings": [ |  | ||||||
|     "images", |  | ||||||
|     { |  | ||||||
|       "id": "explanation", |  | ||||||
|       "render": "Op dit grasveld in het park mag je spelen, picnicken, zitten, ..." |  | ||||||
|     }, |  | ||||||
|     { |  | ||||||
|       "id": "grass-in-parks-reviews", |  | ||||||
|       "render": "{reviews(name, landuse=grass )}" |  | ||||||
|     } |  | ||||||
|   ], |  | ||||||
|   "mapRendering": [ |  | ||||||
|     { |  | ||||||
|       "icon": "./assets/themes/playgrounds/playground.svg", |  | ||||||
|       "iconSize": "40,40,center", |  | ||||||
|       "location": [ |  | ||||||
|         "point", |  | ||||||
|         "centroid" |  | ||||||
|       ] |  | ||||||
|     }, |  | ||||||
|     { |  | ||||||
|       "color": "#0f0", |  | ||||||
|       "width": "1" |  | ||||||
|     } |  | ||||||
|   ], |  | ||||||
|   "description": { |  | ||||||
|     "en": "Searches for all accessible grass patches within public parks - these are 'groenzones'", |  | ||||||
|     "nl": "Dit zoekt naar alle toegankelijke grasvelden binnen publieke parken - dit zijn 'groenzones'", |  | ||||||
|     "de": "Sucht nach allen zugänglichen Grasflächen in öffentlichen Parks - dies sind 'Grünzonen'", |  | ||||||
|     "ca": "Cerques per a tots els camins d'herba accessibles dins dels parcs públics - aquests són «groenzones»" |  | ||||||
|   } |  | ||||||
| } |  | ||||||
|  | @ -93,22 +93,6 @@ | ||||||
|         ] |         ] | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     { |  | ||||||
|       "builtin": "grass_in_parks", |  | ||||||
|       "override": { |  | ||||||
|         "minzoom": 14, |  | ||||||
|         "source": { |  | ||||||
|           "geoJsonLocal": "http://127.0.0.1:8080/speelplekken_{layer}_{z}_{x}_{y}.geojson", |  | ||||||
|           "geoJson": "https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/speelplekken_cache/speelplekken_{layer}_{z}_{x}_{y}.geojson", |  | ||||||
|           "geoJsonZoomLevel": 14, |  | ||||||
|           "isOsmCache": true |  | ||||||
|         }, |  | ||||||
|         "calculatedTags": [ |  | ||||||
|           "_is_shadowed=feat.overlapWith('shadow').length > 0 ? 'yes': ''", |  | ||||||
|           "_video:id=feat.properties.video === undefined ? undefined : new URL(feat.properties.video).searchParams.get('v')" |  | ||||||
|         ] |  | ||||||
|       } |  | ||||||
|     }, |  | ||||||
|     { |     { | ||||||
|       "builtin": "sport_pitch", |       "builtin": "sport_pitch", | ||||||
|       "override": { |       "override": { | ||||||
|  | @ -129,7 +113,6 @@ | ||||||
|       "builtin": "slow_roads", |       "builtin": "slow_roads", | ||||||
|       "override": { |       "override": { | ||||||
|         "calculatedTags": [ |         "calculatedTags": [ | ||||||
|           "_part_of_walking_routes=Array.from(new Set(feat.memberships().map(r => \"<a href='#relation/\"+r.relation.id+\"'>\" + r.relation.tags.name + \"</a>\"))).join(', ')", |  | ||||||
|           "_is_shadowed=feat.overlapWith('shadow').length > 0 ? 'yes': ''" |           "_is_shadowed=feat.overlapWith('shadow').length > 0 ? 'yes': ''" | ||||||
|         ], |         ], | ||||||
|         "source": { |         "source": { | ||||||
|  | @ -268,11 +251,6 @@ | ||||||
|   }, |   }, | ||||||
|   "overrideAll": { |   "overrideAll": { | ||||||
|     "+tagRenderings": [ |     "+tagRenderings": [ | ||||||
|       { |  | ||||||
|         "id": "part-of-walk", |  | ||||||
|         "render": "Maakt deel uit van {_part_of_walking_routes}", |  | ||||||
|         "condition": "_part_of_walking_routes~*" |  | ||||||
|       }, |  | ||||||
|       { |       { | ||||||
|         "id": "has-video", |         "id": "has-video", | ||||||
|         "freeform": { |         "freeform": { | ||||||
|  |  | ||||||
|  | @ -1,61 +0,0 @@ | ||||||
| [ |  | ||||||
|   { |  | ||||||
|     "start_date": "2022-05-30", |  | ||||||
|     "end_date":"2022-06-05", |  | ||||||
|     "message": "The 3rd of June is <b><a href='https://en.wikipedia.org/wiki/World_Bicycle_Day'>World Bicycle Day</a></b>X. Go find a bike shop or bike pump nearby", |  | ||||||
|     "featured_theme": "cyclofix" |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "start_date": "2022-04-24", |  | ||||||
|     "end_date": "2022-05-30", |  | ||||||
|     "message": "Help translating MapComplete! If you have some free time, please translate MapComplete to your favourite language. <a href='https://www.openstreetmap.org/user/Pieter%20Vander%20Vennet/diary/398959'>Read the instructions here</a>" |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "start_date": "2022-04-18", |  | ||||||
|     "end_date": "2022-04-24", |  | ||||||
|     "message": "The 23rd of april is <b><a href=https://en.wikipedia.org/wiki/World_Book_Day' target='_blank'>World Book Day</a></b>. Go grab a book in a public bookcase (which is a piece of street furniture containing books where books can be taken and exchanged). Or alternative, search and map all of them in your neighbourhood!", |  | ||||||
|     "featured_theme": "bookcases" |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "start_date": "2022-04-11", |  | ||||||
|     "end_date": "2022-04-18", |  | ||||||
|     "message": "The 15th of april is <b><a href=https://en.wikipedia.org/wiki/World_Art_Day' target='_blank'>World Art Day</a></b> - the ideal moment to go out, enjoy some artwork and add missing artwork to the map. And of course, you can snap some pictures", |  | ||||||
|     "featured_theme": "artwork" |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "start_date": "2022-03-24", |  | ||||||
|     "end_date": "2022-03-31", |  | ||||||
|     "message": "The 22nd of March is <b><a href='https://www.un.org/en/observances/water-day' target='_blank'>World Water Day</a></b>. Time to go out and find all the public drinking water spots!", |  | ||||||
|     "featured_theme": "drinking_water" |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "start_date": "2022-01-24", |  | ||||||
|     "end_date": "2022-01-30", |  | ||||||
|     "message": "The 28th of January is <b><a href='https://en.wikipedia.org/wiki/Data_Privacy_Day' target='_blank'>International Privacy Day</a></b>. Do you want to know where all the surveillance cameras are? Go find out!", |  | ||||||
|     "featured_theme": "surveillance" |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "start_date": "2021-12-27", |  | ||||||
|     "end_date": "2021-12-30", |  | ||||||
|     "message": "In more normal circumstances, there would be a very cool gathering in Leipzig around this time with thousands of tech-minded people. However, due to some well-known circumstances, it is a virtual-only event this year as well. However, there might be a local hackerspace nearby to fill in this void", |  | ||||||
|     "featured_theme": "hackerspaces" |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "start_date": "2021-11-01", |  | ||||||
|     "end_date": "2021-11-07", |  | ||||||
|     "message": "The first days of november is, in many European traditions, a moment that we remember our deceased. That is why this week the <b>ghost bikes</b> are featured. A ghost bike is a memorial in the form of a bicycle painted white which is placed to remember a cyclist whom was killed in a traffic accident. The ghostbike-theme shows such memorials. Even though there are already too much such memorials on the map, please add missing ones if you encounter them.", |  | ||||||
|     "featured_theme": "ghostbikes" |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "start_date": "2021-10-25", |  | ||||||
|     "end_date": "2021-11-01", |  | ||||||
|     "message": "Did you know you could link OpenStreetMap with Wikidata? With <i>name:etymology:wikidata</i>, it is even possible to link to whom or what a feature is <i>named after</i>. Quite some volunteers have done this - because it is interesting or for the <a href='https://equalstreetnames.org/' target='_blank'>Equal Street Names-project</a>. For this, a new theme has been created which shows the Wikipedia page and Wikimedia-images of this tag and which makes it easy to link them both with the search box. Give it a try!", |  | ||||||
|     "featured_theme": "etymology" |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "start_date": "2021-10-17", |  | ||||||
|     "end_date": "2021-10-25", |  | ||||||
|     "message": "<p>Hi all!</p><p>Thanks for using MapComplete. It has been quite a ride since it's inception, a bit over a year ago. MapComplete has grown significantly recently, which you can read more about on <a href='https://www.openstreetmap.org/user/Pieter%20Vander%20Vennet/diary/397796' target='_blank'>in my diary entry</a>.<p>Furthermore, <a target='_blank' href='https://www.openstreetmap.org/user/Nicolelaine'>NicoleLaine</a> made a really cool new theme about postboxes, so make sure to check it out!</p>", |  | ||||||
|     "featured_theme": "postboxes" |  | ||||||
|   } |  | ||||||
| ] |  | ||||||
|  | @ -1443,11 +1443,6 @@ video { | ||||||
|   border-color: rgb(219 234 254 / var(--tw-border-opacity)); |   border-color: rgb(219 234 254 / var(--tw-border-opacity)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .border-red-500 { |  | ||||||
|   --tw-border-opacity: 1; |  | ||||||
|   border-color: rgb(239 68 68 / var(--tw-border-opacity)); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| .border-gray-300 { | .border-gray-300 { | ||||||
|   --tw-border-opacity: 1; |   --tw-border-opacity: 1; | ||||||
|   border-color: rgb(209 213 219 / var(--tw-border-opacity)); |   border-color: rgb(209 213 219 / var(--tw-border-opacity)); | ||||||
|  | @ -1873,6 +1868,12 @@ video { | ||||||
|   transition-duration: 150ms; |   transition-duration: 150ms; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | .transition-all { | ||||||
|  |   transition-property: all; | ||||||
|  |   transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); | ||||||
|  |   transition-duration: 150ms; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| .transition-\[color\2c background-color\2c box-shadow\] { | .transition-\[color\2c background-color\2c box-shadow\] { | ||||||
|   transition-property: color,background-color,box-shadow; |   transition-property: color,background-color,box-shadow; | ||||||
|   transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); |   transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); | ||||||
|  |  | ||||||
|  | @ -7,7 +7,6 @@ import { existsSync, readFileSync, writeFileSync } from "fs" | ||||||
| import { TagsFilter } from "../Logic/Tags/TagsFilter" | import { TagsFilter } from "../Logic/Tags/TagsFilter" | ||||||
| import { Or } from "../Logic/Tags/Or" | import { Or } from "../Logic/Tags/Or" | ||||||
| import { AllKnownLayouts } from "../Customizations/AllKnownLayouts" | import { AllKnownLayouts } from "../Customizations/AllKnownLayouts" | ||||||
| import RelationsTracker from "../Logic/Osm/RelationsTracker" |  | ||||||
| import * as OsmToGeoJson from "osmtogeojson" | import * as OsmToGeoJson from "osmtogeojson" | ||||||
| import MetaTagging from "../Logic/MetaTagging" | import MetaTagging from "../Logic/MetaTagging" | ||||||
| import { ImmutableStore, UIEventSource } from "../Logic/UIEventSource" | import { ImmutableStore, UIEventSource } from "../Logic/UIEventSource" | ||||||
|  | @ -26,13 +25,11 @@ import FilteringFeatureSource from "../Logic/FeatureSource/Sources/FilteringFeat | ||||||
| import Loc from "../Models/Loc" | import Loc from "../Models/Loc" | ||||||
| import { Feature } from "geojson" | import { Feature } from "geojson" | ||||||
| import { BBox } from "../Logic/BBox" | import { BBox } from "../Logic/BBox" | ||||||
| import { bboxClip } from "@turf/turf" |  | ||||||
| 
 | 
 | ||||||
| ScriptUtils.fixUtils() | ScriptUtils.fixUtils() | ||||||
| 
 | 
 | ||||||
| function createOverpassObject( | function createOverpassObject( | ||||||
|     theme: LayoutConfig, |     theme: LayoutConfig, | ||||||
|     relationTracker: RelationsTracker, |  | ||||||
|     backend: string |     backend: string | ||||||
| ) { | ) { | ||||||
|     let filters: TagsFilter[] = [] |     let filters: TagsFilter[] = [] | ||||||
|  | @ -52,13 +49,8 @@ function createOverpassObject( | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Check if data for this layer has already been loaded
 |  | ||||||
|         if (layer.source.overpassScript !== undefined) { |  | ||||||
|             extraScripts.push(layer.source.overpassScript) |  | ||||||
|         } else { |  | ||||||
|         filters.push(layer.source.osmTags) |         filters.push(layer.source.osmTags) | ||||||
|     } |     } | ||||||
|     } |  | ||||||
|     filters = Utils.NoNull(filters) |     filters = Utils.NoNull(filters) | ||||||
|     extraScripts = Utils.NoNull(extraScripts) |     extraScripts = Utils.NoNull(extraScripts) | ||||||
|     if (filters.length + extraScripts.length === 0) { |     if (filters.length + extraScripts.length === 0) { | ||||||
|  | @ -69,7 +61,6 @@ function createOverpassObject( | ||||||
|         extraScripts, |         extraScripts, | ||||||
|         backend, |         backend, | ||||||
|         new UIEventSource<number>(60), |         new UIEventSource<number>(60), | ||||||
|         relationTracker |  | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -86,7 +77,6 @@ async function downloadRaw( | ||||||
|     targetdir: string, |     targetdir: string, | ||||||
|     r: TileRange, |     r: TileRange, | ||||||
|     theme: LayoutConfig, |     theme: LayoutConfig, | ||||||
|     relationTracker: RelationsTracker |  | ||||||
| ): Promise<{ failed: number; skipped: number }> { | ): Promise<{ failed: number; skipped: number }> { | ||||||
|     let downloaded = 0 |     let downloaded = 0 | ||||||
|     let failed = 0 |     let failed = 0 | ||||||
|  | @ -130,7 +120,6 @@ async function downloadRaw( | ||||||
|             } |             } | ||||||
|             const overpass = createOverpassObject( |             const overpass = createOverpassObject( | ||||||
|                 theme, |                 theme, | ||||||
|                 relationTracker, |  | ||||||
|                 Constants.defaultOverpassUrls[failed % Constants.defaultOverpassUrls.length] |                 Constants.defaultOverpassUrls[failed % Constants.defaultOverpassUrls.length] | ||||||
|             ) |             ) | ||||||
|             const url = overpass.buildQuery( |             const url = overpass.buildQuery( | ||||||
|  | @ -233,7 +222,6 @@ function loadAllTiles( | ||||||
| function sliceToTiles( | function sliceToTiles( | ||||||
|     allFeatures: FeatureSource, |     allFeatures: FeatureSource, | ||||||
|     theme: LayoutConfig, |     theme: LayoutConfig, | ||||||
|     relationsTracker: RelationsTracker, |  | ||||||
|     targetdir: string, |     targetdir: string, | ||||||
|     pointsOnlyLayers: string[], |     pointsOnlyLayers: string[], | ||||||
|     clip: boolean |     clip: boolean | ||||||
|  | @ -244,8 +232,7 @@ function sliceToTiles( | ||||||
|     let indexisBuilt = false |     let indexisBuilt = false | ||||||
| 
 | 
 | ||||||
|     function buildIndex() { |     function buildIndex() { | ||||||
|         for (const ff of allFeatures.features.data) { |         for (const f of allFeatures.features.data) { | ||||||
|             const f = ff.feature |  | ||||||
|             indexedFeatures.set(f.properties.id, f) |             indexedFeatures.set(f.properties.id, f) | ||||||
|         } |         } | ||||||
|         indexisBuilt = true |         indexisBuilt = true | ||||||
|  | @ -281,9 +268,8 @@ function sliceToTiles( | ||||||
|         MetaTagging.addMetatags( |         MetaTagging.addMetatags( | ||||||
|             source.features.data, |             source.features.data, | ||||||
|             { |             { | ||||||
|                 memberships: relationsTracker, |  | ||||||
|                 getFeaturesWithin: (_) => { |                 getFeaturesWithin: (_) => { | ||||||
|                     return [allFeatures.features.data.map((f) => f.feature)] |                     return <any> [allFeatures.features.data] | ||||||
|                 }, |                 }, | ||||||
|                 getFeatureById: getFeatureById, |                 getFeatureById: getFeatureById, | ||||||
|             }, |             }, | ||||||
|  | @ -348,7 +334,7 @@ function sliceToTiles( | ||||||
|                 } |                 } | ||||||
|                 let strictlyCalculated = 0 |                 let strictlyCalculated = 0 | ||||||
|                 let featureCount = 0 |                 let featureCount = 0 | ||||||
|                 let features: Feature[] = filteredTile.features.data.map((f) => f.feature) |                 let features: Feature[] = filteredTile.features.data | ||||||
|                 for (const feature of features) { |                 for (const feature of features) { | ||||||
|                     // Some cleanup
 |                     // Some cleanup
 | ||||||
| 
 | 
 | ||||||
|  | @ -444,7 +430,7 @@ function sliceToTiles( | ||||||
|                 source, |                 source, | ||||||
|                 new UIEventSource<any>(undefined) |                 new UIEventSource<any>(undefined) | ||||||
|             ) |             ) | ||||||
|             const features = filtered.features.data.map((f) => f.feature) |             const features = filtered.features.data | ||||||
| 
 | 
 | ||||||
|             const points = features.map((feature) => GeoOperations.centerpoint(feature)) |             const points = features.map((feature) => GeoOperations.centerpoint(feature)) | ||||||
|             console.log("Writing points overview for ", layerId) |             console.log("Writing points overview for ", layerId) | ||||||
|  | @ -571,11 +557,9 @@ export async function main(args: string[]) { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const relationTracker = new RelationsTracker() |  | ||||||
| 
 |  | ||||||
|     let failed = 0 |     let failed = 0 | ||||||
|     do { |     do { | ||||||
|         const cachingResult = await downloadRaw(targetdir, tileRange, theme, relationTracker) |         const cachingResult = await downloadRaw(targetdir, tileRange, theme) | ||||||
|         failed = cachingResult.failed |         failed = cachingResult.failed | ||||||
|         if (failed > 0) { |         if (failed > 0) { | ||||||
|             await ScriptUtils.sleep(30000) |             await ScriptUtils.sleep(30000) | ||||||
|  | @ -584,7 +568,7 @@ export async function main(args: string[]) { | ||||||
| 
 | 
 | ||||||
|     const extraFeatures = await downloadExtraData(theme) |     const extraFeatures = await downloadExtraData(theme) | ||||||
|     const allFeaturesSource = loadAllTiles(targetdir, tileRange, theme, extraFeatures) |     const allFeaturesSource = loadAllTiles(targetdir, tileRange, theme, extraFeatures) | ||||||
|     sliceToTiles(allFeaturesSource, theme, relationTracker, targetdir, generatePointLayersFor, clip) |     sliceToTiles(allFeaturesSource, theme, targetdir, generatePointLayersFor, clip) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| let args = [...process.argv] | let args = [...process.argv] | ||||||
|  |  | ||||||
							
								
								
									
										3
									
								
								test.ts
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								test.ts
									
										
									
									
									
								
							|  | @ -2,12 +2,13 @@ import SvelteUIElement from "./UI/Base/SvelteUIElement" | ||||||
| import ThemeViewGUI from "./UI/ThemeViewGUI.svelte" | import ThemeViewGUI from "./UI/ThemeViewGUI.svelte" | ||||||
| import { FixedUiElement } from "./UI/Base/FixedUiElement" | import { FixedUiElement } from "./UI/Base/FixedUiElement" | ||||||
| import { QueryParameters } from "./Logic/Web/QueryParameters" | import { QueryParameters } from "./Logic/Web/QueryParameters" | ||||||
| import { AllKnownLayoutsLazy } from "./Customizations/AllKnownLayouts" |  | ||||||
| import LayoutConfig from "./Models/ThemeConfig/LayoutConfig" | import LayoutConfig from "./Models/ThemeConfig/LayoutConfig" | ||||||
| import * as benches from "./assets/generated/themes/benches.json" | import * as benches from "./assets/generated/themes/benches.json" | ||||||
|  | 
 | ||||||
| async function main() { | async function main() { | ||||||
|     new FixedUiElement("Determining layout...").AttachTo("maindiv") |     new FixedUiElement("Determining layout...").AttachTo("maindiv") | ||||||
|     const qp = QueryParameters.GetQueryParameter("layout", "") |     const qp = QueryParameters.GetQueryParameter("layout", "") | ||||||
|  |     new FixedUiElement("").AttachTo("extradiv") | ||||||
|     const layout = new LayoutConfig(<any>benches, true) // qp.data === "" ?  : new AllKnownLayoutsLazy().get(qp.data)
 |     const layout = new LayoutConfig(<any>benches, true) // qp.data === "" ?  : new AllKnownLayoutsLazy().get(qp.data)
 | ||||||
|     console.log("Using layout", layout.id) |     console.log("Using layout", layout.id) | ||||||
|     new SvelteUIElement(ThemeViewGUI, { layout }).AttachTo("maindiv") |     new SvelteUIElement(ThemeViewGUI, { layout }).AttachTo("maindiv") | ||||||
|  |  | ||||||
|  | @ -115,7 +115,6 @@ describe("OverlapFunc", () => { | ||||||
|         const params: ExtraFuncParams = { |         const params: ExtraFuncParams = { | ||||||
|             getFeatureById: (id) => undefined, |             getFeatureById: (id) => undefined, | ||||||
|             getFeaturesWithin: () => [[door]], |             getFeaturesWithin: () => [[door]], | ||||||
|             memberships: undefined, |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         ExtraFunctions.FullPatchFeature(params, hermanTeirlinck) |         ExtraFunctions.FullPatchFeature(params, hermanTeirlinck) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue