Refactoring(maplibre): remove 'freshness' and 'name' from FeatureSource to simplify the code

This commit is contained in:
Pieter Vander Vennet 2023-03-23 01:42:47 +01:00
parent 1b3609b13f
commit 231d67361e
30 changed files with 161 additions and 269 deletions

View file

@ -106,7 +106,7 @@ export class CompareToAlreadyExistingNotes
state,
zoomToFeatures: true,
leafletMap: comparisonMap.leafletMap,
features: StaticFeatureSource.fromGeojsonStore(
features: new StaticFeatureSource(
partitionedImportPoints.map((p) => <Feature[]>p.hasNearby)
),
popup: (tags, layer) => new FeatureInfoBox(tags, layer, state),

View file

@ -166,7 +166,7 @@ export default class ConflationChecker
[osmLiveData.bounds, zoomLevel.GetValue()]
)
const preview = StaticFeatureSource.fromGeojsonStore(geojsonFeatures)
const preview = new StaticFeatureSource(geojsonFeatures)
new ShowDataLayer({
layerToShow: new LayerConfig(currentview),
@ -225,7 +225,7 @@ export default class ConflationChecker
},
[nearbyCutoff.GetValue().stabilized(500)]
)
const nearbyFeatures = StaticFeatureSource.fromGeojsonStore(geojsonMapped)
const nearbyFeatures = new StaticFeatureSource(geojsonMapped)
const paritionedImport = ImportUtils.partitionFeaturesIfNearby(
toImport,
geojson,
@ -233,7 +233,7 @@ export default class ConflationChecker
)
// Featuresource showing OSM-features which are nearby a toImport-feature
const toImportWithNearby = StaticFeatureSource.fromGeojsonStore(
const toImportWithNearby = new StaticFeatureSource(
paritionedImport.map((els) => <Feature[]>els?.hasNearby ?? [])
)
toImportWithNearby.features.addCallback((nearby) =>

View file

@ -8,8 +8,6 @@ import Constants from "../../Models/Constants"
import { DropDown } from "../Input/DropDown"
import { Utils } from "../../Utils"
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
import BaseLayer from "../../Models/BaseLayer"
import AvailableBaseLayers from "../../Logic/Actors/AvailableBaseLayers"
import Loc from "../../Models/Loc"
import Minimap from "../Base/Minimap"
import Attribution from "../BigComponents/Attribution"
@ -140,9 +138,7 @@ export class MapPreview
new ShowDataLayer({
layerToShow,
zoomToFeatures: true,
features: StaticFeatureSource.fromDateless(
matching.map((features) => features.map((feature) => ({ feature })))
),
features: new StaticFeatureSource(matching),
leafletMap: map.leafletMap,
popup: (tag) => new PreviewPanel(tag),
})

View file

@ -53,7 +53,7 @@ export default class LocationInput
* Used for rendering
* @private
*/
private readonly _snapToRaw: Store<{ feature: Feature }[]>
private readonly _snapToRaw: Store<Feature[]>
private readonly _value: Store<Loc>
private readonly _snappedPoint: Store<any>
private readonly _maxSnapDistance: number
@ -112,7 +112,7 @@ export default class LocationInput
constructor(options?: {
minZoom?: number
mapBackground?: UIEventSource<BaseLayer>
snapTo?: UIEventSource<{ feature: Feature }[]>
snapTo?: UIEventSource<Feature[]>
renderLayerForSnappedPoint?: LayerConfig
maxSnapDistance?: number
snappedPointTags?: any
@ -276,7 +276,7 @@ export default class LocationInput
if (this._snapToRaw !== undefined) {
// Show the lines to snap to
new ShowDataMultiLayer({
features: StaticFeatureSource.fromDateless(this._snapToRaw),
features: new StaticFeatureSource(this._snapToRaw),
zoomToFeatures: false,
leafletMap: this.map.leafletMap,
layers: this._state.filteredLayers,
@ -286,12 +286,12 @@ export default class LocationInput
if (loc === undefined) {
return []
}
return [{ feature: loc }]
return [loc]
})
// The 'matchlayer' is the layer which shows the target location
new ShowDataLayer({
features: StaticFeatureSource.fromDateless(matchPoint),
features: new StaticFeatureSource(matchPoint),
zoomToFeatures: false,
leafletMap: this.map.leafletMap,
layerToShow: this._matching_layer,

View file

@ -3,7 +3,6 @@ import { OsmConnection } from "../../Logic/Osm/OsmConnection"
import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline"
import BaseUIElement from "../BaseUIElement"
import LocationInput from "../Input/LocationInput"
import AvailableBaseLayers from "../../Logic/Actors/AvailableBaseLayers"
import { BBox } from "../../Logic/BBox"
import { TagUtils } from "../../Logic/Tags/TagUtils"
import { SubtleButton } from "../Base/SubtleButton"
@ -12,7 +11,6 @@ import Translations from "../i18n/Translations"
import Svg from "../../Svg"
import Toggle from "../Input/Toggle"
import SimpleAddUI, { PresetInfo } from "../BigComponents/SimpleAddUI"
import BaseLayer from "../../Models/BaseLayer"
import Img from "../Base/Img"
import Title from "../Base/Title"
import { GlobalFilter } from "../../Logic/State/MapState"
@ -20,6 +18,8 @@ import { VariableUiElement } from "../Base/VariableUIElement"
import { Tag } from "../../Logic/Tags/Tag"
import { WayId } from "../../Models/OsmFeature"
import { Translation } from "../i18n/Translation"
import { Feature } from "geojson";
import { AvailableRasterLayers, RasterLayerPolygon } from "../../Models/RasterLayers";
export default class ConfirmLocationOfPoint extends Combine {
constructor(
@ -28,7 +28,7 @@ export default class ConfirmLocationOfPoint extends Combine {
featureSwitchIsTesting: UIEventSource<boolean>
osmConnection: OsmConnection
featurePipeline: FeaturePipeline
backgroundLayer?: UIEventSource<BaseLayer>
backgroundLayer?: UIEventSource<RasterLayerPolygon | undefined>
},
filterViewIsOpened: UIEventSource<boolean>,
preset: PresetInfo,
@ -55,10 +55,10 @@ export default class ConfirmLocationOfPoint extends Combine {
const locationSrc = new UIEventSource(zloc)
let backgroundLayer = new UIEventSource(
state?.backgroundLayer?.data ?? AvailableBaseLayers.osmCarto
state?.backgroundLayer?.data ?? AvailableRasterLayers.osmCarto
)
if (preset.preciseInput.preferredBackground) {
const defaultBackground = AvailableBaseLayers.SelectBestLayerAccordingTo(
const defaultBackground = AvailableRasterLayers.SelectBestLayerAccordingTo(
locationSrc,
new UIEventSource<string | string[]>(preset.preciseInput.preferredBackground)
)
@ -66,10 +66,10 @@ export default class ConfirmLocationOfPoint extends Combine {
backgroundLayer.setData(defaultBackground.data)
}
let snapToFeatures: UIEventSource<{ feature: any }[]> = undefined
let snapToFeatures: UIEventSource<Feature[]> = undefined
let mapBounds: UIEventSource<BBox> = undefined
if (preset.preciseInput.snapToLayers && preset.preciseInput.snapToLayers.length > 0) {
snapToFeatures = new UIEventSource<{ feature: any }[]>([])
snapToFeatures = new UIEventSource< Feature[]>([])
mapBounds = new UIEventSource<BBox>(undefined)
}
@ -105,13 +105,13 @@ export default class ConfirmLocationOfPoint extends Combine {
Math.max(preset.boundsFactor ?? 0.25, 2)
)
loadedBbox = bbox
const allFeatures: { feature: any }[] = []
const allFeatures: Feature[] = []
preset.preciseInput.snapToLayers.forEach((layerId) => {
console.log("Snapping to", layerId)
state.featurePipeline
.GetFeaturesWithin(layerId, bbox)
?.forEach((feats) =>
allFeatures.push(...feats.map((f) => ({ feature: f })))
allFeatures.push(...<any[]>feats)
)
})
console.log("Snapping to", allFeatures)