forked from MapComplete/MapComplete
Refactoring: remove selectedLayer where unneeded
This commit is contained in:
parent
3e0a42ef46
commit
5d09b31c50
8 changed files with 14 additions and 77 deletions
|
@ -25,7 +25,7 @@ export default class MetaTagging {
|
||||||
>()
|
>()
|
||||||
|
|
||||||
constructor(state: {
|
constructor(state: {
|
||||||
readonly selectedElementAndLayer: Store<{ feature: Feature; layer: LayerConfig }>
|
readonly selectedElement: Store<Feature>
|
||||||
readonly layout: LayoutConfig
|
readonly layout: LayoutConfig
|
||||||
readonly osmObjectDownloader: OsmObjectDownloader
|
readonly osmObjectDownloader: OsmObjectDownloader
|
||||||
readonly perLayer: ReadonlyMap<string, GeoIndexedStoreForLayer>
|
readonly perLayer: ReadonlyMap<string, GeoIndexedStoreForLayer>
|
||||||
|
@ -61,7 +61,8 @@ export default class MetaTagging {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
state.selectedElementAndLayer.addCallbackAndRunD(({ feature, layer }) => {
|
state.selectedElement.addCallbackAndRunD((feature) => {
|
||||||
|
const layer = state.layout.getMatchingLayer(feature.properties)
|
||||||
// Force update the tags of the currently selected element
|
// Force update the tags of the currently selected element
|
||||||
MetaTagging.addMetatags(
|
MetaTagging.addMetatags(
|
||||||
[feature],
|
[feature],
|
||||||
|
|
|
@ -1,42 +1,14 @@
|
||||||
import { Utils } from "../../Utils"
|
import { Utils } from "../../Utils"
|
||||||
/** This code is autogenerated - do not edit. Edit ./assets/layers/usersettings/usersettings.json instead */
|
/** This code is autogenerated - do not edit. Edit ./assets/layers/usersettings/usersettings.json instead */
|
||||||
export class ThemeMetaTagging {
|
export class ThemeMetaTagging {
|
||||||
public static readonly themeName = "usersettings"
|
public static readonly themeName = "usersettings"
|
||||||
|
|
||||||
public metaTaggging_for_usersettings(feat: { properties: Record<string, string> }) {
|
public metaTaggging_for_usersettings(feat: {properties: Record<string, string>}) {
|
||||||
Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_md", () =>
|
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_md', () => feat.properties._description.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)?.at(1) )
|
||||||
feat.properties._description
|
Utils.AddLazyProperty(feat.properties, '_d', () => feat.properties._description?.replace(/</g,'<')?.replace(/>/g,'>') ?? '' )
|
||||||
.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)
|
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_a', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.href.match(/mastodon|en.osm.town/) !== null)[0]?.href }) (feat) )
|
||||||
?.at(1)
|
Utils.AddLazyProperty(feat.properties, '_mastodon_link', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.getAttribute("rel")?.indexOf('me') >= 0)[0]?.href})(feat) )
|
||||||
)
|
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate', () => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a )
|
||||||
Utils.AddLazyProperty(
|
feat.properties['__current_backgroun'] = 'initial_value'
|
||||||
feat.properties,
|
}
|
||||||
"_d",
|
}
|
||||||
() => feat.properties._description?.replace(/</g, "<")?.replace(/>/g, ">") ?? ""
|
|
||||||
)
|
|
||||||
Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_a", () =>
|
|
||||||
((feat) => {
|
|
||||||
const e = document.createElement("div")
|
|
||||||
e.innerHTML = feat.properties._d
|
|
||||||
return Array.from(e.getElementsByTagName("a")).filter(
|
|
||||||
(a) => a.href.match(/mastodon|en.osm.town/) !== null
|
|
||||||
)[0]?.href
|
|
||||||
})(feat)
|
|
||||||
)
|
|
||||||
Utils.AddLazyProperty(feat.properties, "_mastodon_link", () =>
|
|
||||||
((feat) => {
|
|
||||||
const e = document.createElement("div")
|
|
||||||
e.innerHTML = feat.properties._d
|
|
||||||
return Array.from(e.getElementsByTagName("a")).filter(
|
|
||||||
(a) => a.getAttribute("rel")?.indexOf("me") >= 0
|
|
||||||
)[0]?.href
|
|
||||||
})(feat)
|
|
||||||
)
|
|
||||||
Utils.AddLazyProperty(
|
|
||||||
feat.properties,
|
|
||||||
"_mastodon_candidate",
|
|
||||||
() => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a
|
|
||||||
)
|
|
||||||
feat.properties["__current_backgroun"] = "initial_value"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -115,7 +115,6 @@ export default class ThemeViewStateHashActor {
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
selectedElement.setData(found)
|
selectedElement.setData(found)
|
||||||
state.selectedLayer.setData(layer)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,6 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
|
|
||||||
readonly osmConnection: OsmConnection
|
readonly osmConnection: OsmConnection
|
||||||
readonly selectedElement: UIEventSource<Feature>
|
readonly selectedElement: UIEventSource<Feature>
|
||||||
readonly selectedElementAndLayer: Store<{ feature: Feature; layer: LayerConfig }>
|
|
||||||
readonly mapProperties: MapLibreAdaptor & MapProperties & ExportableMap
|
readonly mapProperties: MapLibreAdaptor & MapProperties & ExportableMap
|
||||||
readonly osmObjectDownloader: OsmObjectDownloader
|
readonly osmObjectDownloader: OsmObjectDownloader
|
||||||
|
|
||||||
|
@ -179,18 +178,6 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
this.mapProperties.allowRotating.setData(fixated !== "yes")
|
this.mapProperties.allowRotating.setData(fixated !== "yes")
|
||||||
})
|
})
|
||||||
this.selectedElement = new UIEventSource<Feature | undefined>(undefined, "Selected element")
|
this.selectedElement = new UIEventSource<Feature | undefined>(undefined, "Selected element")
|
||||||
this.selectedLayer = new UIEventSource<LayerConfig>(undefined, "Selected layer")
|
|
||||||
|
|
||||||
this.selectedElementAndLayer = this.selectedElement.mapD(
|
|
||||||
(feature) => {
|
|
||||||
const layer = this.selectedLayer.data
|
|
||||||
if (!layer) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
return { layer, feature }
|
|
||||||
},
|
|
||||||
[this.selectedLayer]
|
|
||||||
)
|
|
||||||
|
|
||||||
this.geolocation = new GeoLocationHandler(
|
this.geolocation = new GeoLocationHandler(
|
||||||
geolocationState,
|
geolocationState,
|
||||||
|
@ -434,7 +421,6 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
doShowLayer,
|
doShowLayer,
|
||||||
metaTags: this.userRelatedState.preferencesAsTags,
|
metaTags: this.userRelatedState.preferencesAsTags,
|
||||||
selectedElement: this.selectedElement,
|
selectedElement: this.selectedElement,
|
||||||
selectedLayer: this.selectedLayer,
|
|
||||||
fetchStore: (id) => this.featureProperties.getStore(id),
|
fetchStore: (id) => this.featureProperties.getStore(id),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -442,14 +428,12 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
}
|
}
|
||||||
|
|
||||||
public openNewDialog() {
|
public openNewDialog() {
|
||||||
this.selectedLayer.setData(undefined)
|
|
||||||
this.selectedElement.setData(undefined)
|
this.selectedElement.setData(undefined)
|
||||||
|
|
||||||
const { lon, lat } = this.mapProperties.location.data
|
const { lon, lat } = this.mapProperties.location.data
|
||||||
const feature = this.lastClickObject.createFeature(lon, lat)
|
const feature = this.lastClickObject.createFeature(lon, lat)
|
||||||
this.featureProperties.trackFeature(feature)
|
this.featureProperties.trackFeature(feature)
|
||||||
this.selectedElement.setData(feature)
|
this.selectedElement.setData(feature)
|
||||||
this.selectedLayer.setData(this.newPointDialog.layerDef)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -514,14 +498,12 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
}
|
}
|
||||||
const layer = this.layout.getMatchingLayer(toSelect.properties)
|
const layer = this.layout.getMatchingLayer(toSelect.properties)
|
||||||
this.selectedElement.setData(undefined)
|
this.selectedElement.setData(undefined)
|
||||||
this.selectedLayer.setData(layer)
|
|
||||||
this.selectedElement.setData(toSelect)
|
this.selectedElement.setData(toSelect)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const layer = this.layout.getMatchingLayer(toSelect.properties)
|
const layer = this.layout.getMatchingLayer(toSelect.properties)
|
||||||
this.selectedElement.setData(undefined)
|
this.selectedElement.setData(undefined)
|
||||||
this.selectedLayer.setData(layer)
|
|
||||||
this.selectedElement.setData(toSelect)
|
this.selectedElement.setData(toSelect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,8 +732,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
doShowLayer: flayer.isDisplayed,
|
doShowLayer: flayer.isDisplayed,
|
||||||
layer: flayer.layerDef,
|
layer: flayer.layerDef,
|
||||||
metaTags: this.userRelatedState.preferencesAsTags,
|
metaTags: this.userRelatedState.preferencesAsTags,
|
||||||
selectedElement: this.selectedElement,
|
selectedElement: this.selectedElement
|
||||||
selectedLayer: this.selectedLayer,
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -765,7 +746,6 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
console.trace("Unselected")
|
console.trace("Unselected")
|
||||||
// We did _unselect_ an item - we always remove the lastclick-object
|
// We did _unselect_ an item - we always remove the lastclick-object
|
||||||
this.lastClickObject.features.setData([])
|
this.lastClickObject.features.setData([])
|
||||||
this.selectedLayer.setData(undefined)
|
|
||||||
this.focusOnMap()
|
this.focusOnMap()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,11 +14,6 @@ export interface ShowDataLayerOptions {
|
||||||
*/
|
*/
|
||||||
selectedElement?: UIEventSource<Feature>
|
selectedElement?: UIEventSource<Feature>
|
||||||
|
|
||||||
/**
|
|
||||||
* When a feature of this layer is tapped, the layer will be marked
|
|
||||||
*/
|
|
||||||
selectedLayer?: UIEventSource<LayerConfig>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -53,7 +53,6 @@ export default class ConflateImportFlowState extends ImportFlow<ConflateFlowArgu
|
||||||
const action = this.action
|
const action = this.action
|
||||||
await this.state.changes.applyAction(action)
|
await this.state.changes.applyAction(action)
|
||||||
const newId = action.newElementId ?? action.mainObjectId
|
const newId = action.newElementId ?? action.mainObjectId
|
||||||
this.state.selectedLayer.setData(this.targetLayer.layerDef)
|
|
||||||
this.state.selectedElement.setData(this.state.indexedFeatures.featuresById.data.get(newId))
|
this.state.selectedElement.setData(this.state.indexedFeatures.featuresById.data.get(newId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,6 @@ export default class WayImportFlowState extends ImportFlow<WayImportFlowArgument
|
||||||
const action = this.action
|
const action = this.action
|
||||||
await this.state.changes.applyAction(action)
|
await this.state.changes.applyAction(action)
|
||||||
const newId = action.newElementId ?? action.mainObjectId
|
const newId = action.newElementId ?? action.mainObjectId
|
||||||
this.state.selectedLayer.setData(this.targetLayer.layerDef)
|
|
||||||
this.state.selectedElement.setData(this.state.indexedFeatures.featuresById.data.get(newId))
|
this.state.selectedElement.setData(this.state.indexedFeatures.featuresById.data.get(newId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,14 +55,6 @@ export interface SpecialVisualizationState {
|
||||||
readonly mapProperties: MapProperties & ExportableMap
|
readonly mapProperties: MapProperties & ExportableMap
|
||||||
|
|
||||||
readonly selectedElement: UIEventSource<Feature>
|
readonly selectedElement: UIEventSource<Feature>
|
||||||
/**
|
|
||||||
* Works together with 'selectedElement' to indicate what properties should be displayed
|
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* No need to set this anymore
|
|
||||||
*/
|
|
||||||
readonly selectedLayer: UIEventSource<LayerConfig>
|
|
||||||
readonly selectedElementAndLayer: Store<{ feature: Feature; layer: LayerConfig }>
|
|
||||||
|
|
||||||
readonly favourites: FavouritesFeatureSource
|
readonly favourites: FavouritesFeatureSource
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue