forked from MapComplete/MapComplete
UX: immediately download a feature that has the ID via the hash to display it faster
This commit is contained in:
parent
ccdcb86044
commit
20f4f6b869
3 changed files with 29 additions and 18 deletions
|
@ -2,7 +2,7 @@ import { Utils } from "../../Utils"
|
||||||
import polygon_features from "../../assets/polygon-features.json"
|
import polygon_features from "../../assets/polygon-features.json"
|
||||||
import { OsmFeature, OsmId, OsmTags, WayId } from "../../Models/OsmFeature"
|
import { OsmFeature, OsmId, OsmTags, WayId } from "../../Models/OsmFeature"
|
||||||
import OsmToGeoJson from "osmtogeojson"
|
import OsmToGeoJson from "osmtogeojson"
|
||||||
import { Feature, LineString, Polygon } from "geojson"
|
import { Feature, LineString, Point, Polygon } from "geojson"
|
||||||
import Constants from "../../Models/Constants"
|
import Constants from "../../Models/Constants"
|
||||||
|
|
||||||
export abstract class OsmObject {
|
export abstract class OsmObject {
|
||||||
|
@ -131,7 +131,7 @@ export abstract class OsmObject {
|
||||||
*/
|
*/
|
||||||
public abstract centerpoint(): [number, number]
|
public abstract centerpoint(): [number, number]
|
||||||
|
|
||||||
public abstract asGeoJson(): any
|
public abstract asGeoJson(): OsmFeature
|
||||||
|
|
||||||
abstract SaveExtraData(element: any, allElements: OsmObject[] | any)
|
abstract SaveExtraData(element: any, allElements: OsmObject[] | any)
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ ${tags} </node>
|
||||||
return [this.lat, this.lon]
|
return [this.lat, this.lon]
|
||||||
}
|
}
|
||||||
|
|
||||||
asGeoJson(): OsmFeature {
|
asGeoJson(): Feature<Point, OsmTags> {
|
||||||
return {
|
return {
|
||||||
type: "Feature",
|
type: "Feature",
|
||||||
properties: this.tags,
|
properties: this.tags,
|
||||||
|
@ -305,7 +305,7 @@ ${nds}${tags} </way>
|
||||||
this.nodes = element.nodes
|
this.nodes = element.nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
public asGeoJson(): Feature<Polygon | LineString> & { properties: { id: WayId } } {
|
public asGeoJson(): Feature<Polygon | LineString, OsmTags> & { properties: { id: WayId } } {
|
||||||
const coordinates: [number, number][] | [number, number][][] = this.coordinates.map(
|
const coordinates: [number, number][] | [number, number][][] = this.coordinates.map(
|
||||||
([lat, lon]) => [lon, lat]
|
([lat, lon]) => [lon, lat]
|
||||||
)
|
)
|
||||||
|
@ -384,7 +384,7 @@ ${members}${tags} </relation>
|
||||||
this.geojson = geojson
|
this.geojson = geojson
|
||||||
}
|
}
|
||||||
|
|
||||||
asGeoJson(): any {
|
asGeoJson(): OsmFeature {
|
||||||
if (this.geojson !== undefined) {
|
if (this.geojson !== undefined) {
|
||||||
return this.geojson
|
return this.geojson
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,17 @@ import { AndroidPolyfill } from "./AndroidPolyfill"
|
||||||
import { IndexedFeatureSource } from "../FeatureSource/FeatureSource"
|
import { IndexedFeatureSource } from "../FeatureSource/FeatureSource"
|
||||||
import { Feature } from "geojson"
|
import { Feature } from "geojson"
|
||||||
import { Store, UIEventSource } from "../UIEventSource"
|
import { Store, UIEventSource } from "../UIEventSource"
|
||||||
|
import ThemeViewState from "../../Models/ThemeViewState"
|
||||||
|
import OsmObjectDownloader from "../Osm/OsmObjectDownloader"
|
||||||
|
import ThemeSource from "../FeatureSource/Sources/ThemeSource"
|
||||||
|
|
||||||
export default class ThemeViewStateHashActor {
|
export default class ThemeViewStateHashActor {
|
||||||
private readonly _state: {
|
private readonly _state: Readonly<{
|
||||||
indexedFeatures: IndexedFeatureSource
|
indexedFeatures: IndexedFeatureSource
|
||||||
selectedElement: UIEventSource<Feature>
|
selectedElement: UIEventSource<Feature>
|
||||||
guistate: MenuState
|
guistate: MenuState,
|
||||||
}
|
osmObjectDownloader: OsmObjectDownloader
|
||||||
|
}>
|
||||||
private isUpdatingHash = false
|
private isUpdatingHash = false
|
||||||
|
|
||||||
public static readonly documentation = [
|
public static readonly documentation = [
|
||||||
|
@ -35,12 +39,13 @@ export default class ThemeViewStateHashActor {
|
||||||
* As such, we use a change in the hash to close the appropriate windows
|
* As such, we use a change in the hash to close the appropriate windows
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
constructor(state: {
|
constructor(state: Readonly<{
|
||||||
featureSwitches: { featureSwitchBackToThemeOverview: Store<boolean> }
|
featureSwitches: { featureSwitchBackToThemeOverview: Store<boolean> }
|
||||||
indexedFeatures: IndexedFeatureSource
|
indexedFeatures: IndexedFeatureSource & ThemeSource
|
||||||
selectedElement: UIEventSource<Feature>
|
selectedElement: UIEventSource<Feature>
|
||||||
guistate: MenuState
|
guistate: MenuState,
|
||||||
}) {
|
osmObjectDownloader: OsmObjectDownloader
|
||||||
|
}> ) {
|
||||||
this._state = state
|
this._state = state
|
||||||
AndroidPolyfill.onBackButton(() => this.back(), {
|
AndroidPolyfill.onBackButton(() => this.back(), {
|
||||||
returnToIndex: state.featureSwitches.featureSwitchBackToThemeOverview,
|
returnToIndex: state.featureSwitches.featureSwitchBackToThemeOverview,
|
||||||
|
@ -50,6 +55,17 @@ export default class ThemeViewStateHashActor {
|
||||||
const containsMenu = this.loadStateFromHash(hashOnLoad)
|
const containsMenu = this.loadStateFromHash(hashOnLoad)
|
||||||
// First of all, try to recover the selected element
|
// First of all, try to recover the selected element
|
||||||
if (!containsMenu && hashOnLoad?.length > 0) {
|
if (!containsMenu && hashOnLoad?.length > 0) {
|
||||||
|
if (hashOnLoad.startsWith("node/") || hashOnLoad.startsWith("way/") || hashOnLoad.startsWith("relation/")) {
|
||||||
|
// This is an OSM-element. Let's download it and add it to the indexedFeatures
|
||||||
|
console.log("Directly downloading item from hash")
|
||||||
|
state.osmObjectDownloader.DownloadObjectAsync(hashOnLoad)
|
||||||
|
.then(osmObj => {
|
||||||
|
if (osmObj === "deleted") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
state.indexedFeatures.addItem(osmObj.asGeoJson())
|
||||||
|
})
|
||||||
|
}
|
||||||
state.indexedFeatures.featuresById.addCallbackAndRunD(() => {
|
state.indexedFeatures.featuresById.addCallbackAndRunD(() => {
|
||||||
// once that we have found a matching element, we can be sure the indexedFeaturesource was popuplated and that the job is done
|
// once that we have found a matching element, we can be sure the indexedFeaturesource was popuplated and that the job is done
|
||||||
return this.loadSelectedElementFromHash(hashOnLoad)
|
return this.loadSelectedElementFromHash(hashOnLoad)
|
||||||
|
|
|
@ -51,12 +51,7 @@ export class WithImageState extends WithGuiState implements SpecialVisualization
|
||||||
* Setup various services for which no reference are needed
|
* Setup various services for which no reference are needed
|
||||||
*/
|
*/
|
||||||
private initActors() {
|
private initActors() {
|
||||||
new ThemeViewStateHashActor({
|
new ThemeViewStateHashActor(this)
|
||||||
featureSwitches: this.featureSwitches,
|
|
||||||
selectedElement: this.selectedElement,
|
|
||||||
indexedFeatures: this.indexedFeatures,
|
|
||||||
guistate: this.guistate,
|
|
||||||
})
|
|
||||||
new PendingChangesUploader(this.changes, this.selectedElement, this.imageUploadManager)
|
new PendingChangesUploader(this.changes, this.selectedElement, this.imageUploadManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue