Documentation updates

This commit is contained in:
Pieter Vander Vennet 2021-11-08 02:36:01 +01:00
parent 78c689b7e8
commit 09eee08fbc
32 changed files with 600 additions and 87 deletions

View file

@ -5,11 +5,10 @@ import {VariableUiElement} from "../../UI/Base/VariableUIElement";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import {QueryParameters} from "../Web/QueryParameters";
import FeatureSource from "../FeatureSource/FeatureSource";
import StaticFeatureSource from "../FeatureSource/Sources/StaticFeatureSource";
export default class GeoLocationHandler extends VariableUiElement {
public readonly currentLocation: FeatureSource
private readonly currentLocation: FeatureSource
/**
* Wether or not the geolocation is active, aka the user requested the current location
@ -59,13 +58,13 @@ export default class GeoLocationHandler extends VariableUiElement {
constructor(
state: {
currentGPSLocation: UIEventSource<Coordinates>,
currentUserLocation: FeatureSource,
leafletMap: UIEventSource<any>,
layoutToUse: LayoutConfig,
featureSwitchGeolocation: UIEventSource<boolean>
}
) {
const currentGPSLocation = state.currentGPSLocation
const currentGPSLocation = new UIEventSource<Coordinates>(undefined, "GPS-coordinate")
const leafletMap = state.leafletMap
const hasLocation = currentGPSLocation.map(
(location) => location !== undefined
@ -182,16 +181,16 @@ export default class GeoLocationHandler extends VariableUiElement {
}
})
this.currentLocation = new StaticFeatureSource([], false)
this.currentLocation = state.currentUserLocation
this._currentGPSLocation.addCallback((location) => {
self._previousLocationGrant.setData("granted");
const feature = {
"type": "Feature",
properties: {
id: "gps",
"user:location": "yes",
"accuracy": location.accuracy,
"speed": location.speed,
...location
},
geometry: {
type: "Point",

View file

@ -75,6 +75,8 @@ export default class FeaturePipeline {
constructor(
handleFeatureSource: (source: FeatureSourceForLayer & Tiled) => void,
state: {
readonly homeLocation: FeatureSourceForLayer & Tiled;
readonly currentUserLocation: FeatureSourceForLayer & Tiled;
readonly filteredLayers: UIEventSource<FilteredLayer[]>,
readonly locationControl: UIEventSource<Loc>,
readonly selectedElement: UIEventSource<any>,
@ -152,6 +154,16 @@ export default class FeaturePipeline {
continue;
}
if (id === "gps_location") {
hierarchy.registerTile(state.currentUserLocation)
continue
}
if (id === "home_location") {
hierarchy.registerTile(state.homeLocation)
continue
}
if (source.geojsonSource === undefined) {
// This is an OSM layer
// We load the cached values and register them

View file

@ -4,17 +4,18 @@ import {FeatureSourceForLayer, Tiled} from "../FeatureSource";
import {BBox} from "../../BBox";
export default class SimpleFeatureSource implements FeatureSourceForLayer, Tiled {
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{ feature: any; freshness: Date }[]>([]);
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>;
public readonly name: string = "SimpleFeatureSource";
public readonly layer: FilteredLayer;
public readonly bbox: BBox = BBox.global;
public readonly tileIndex: number;
constructor(layer: FilteredLayer, tileIndex: number) {
constructor(layer: FilteredLayer, tileIndex: number, featureSource?: UIEventSource<{ feature:any; freshness: Date }[]>) {
this.name = "SimpleFeatureSource(" + layer.layerDef.id + ")"
this.layer = layer
this.tileIndex = tileIndex ?? 0;
this.bbox = BBox.fromTileIndex(this.tileIndex)
this.features = featureSource ?? new UIEventSource<{ feature: any; freshness: Date }[]>([]);
}
}

View file

@ -286,7 +286,7 @@ export class ChangesetHandler {
["language", Locale.language.data],
["host", window.location.host],
["path", path],
["source", State.state.currentGPSLocation.data !== undefined ? "survey" : undefined],
["source", State.state.currentUserLocation.features.data.length > 0 ? "survey" : undefined],
["imagery", State.state.backgroundLayer.data.id],
...changesetTags.map(cstag => [cstag.key, cstag.value])
]

View file

@ -14,6 +14,8 @@ import {QueryParameters} from "../Web/QueryParameters";
import * as personal from "../../assets/themes/personal/personal.json";
import FilterConfig from "../../Models/ThemeConfig/FilterConfig";
import ShowOverlayLayer from "../../UI/ShowDataLayer/ShowOverlayLayer";
import FeatureSource, {FeatureSourceForLayer, Tiled} from "../FeatureSource/FeatureSource";
import SimpleFeatureSource from "../FeatureSource/Sources/SimpleFeatureSource";
/**
* Contains all the leaflet-map related state
@ -44,7 +46,17 @@ export default class MapState extends UserRelatedState {
/**
* The location as delivered by the GPS
*/
public currentGPSLocation: UIEventSource<Coordinates> = new UIEventSource<Coordinates>(undefined);
public currentUserLocation: FeatureSourceForLayer & Tiled;
/**
* All previously visited points
*/
public historicalUserLocations: FeatureSourceForLayer & Tiled;
/**
* A feature source containing the current home location of the user
*/
public homeLocation: FeatureSourceForLayer & Tiled
public readonly mainMapObject: BaseUIElement & MinimapObj;
@ -120,6 +132,9 @@ export default class MapState extends UserRelatedState {
this.lockBounds()
this.AddAllOverlaysToMap(this.leafletMap)
this.initHomeLocation()
this.initGpsLocation()
}
public AddAllOverlaysToMap(leafletMap: UIEventSource<any>) {
@ -164,6 +179,50 @@ export default class MapState extends UserRelatedState {
})
}
}
private initGpsLocation(){
// Initialize the gps layer data. This is emtpy for now, the actual writing happens in the Geolocationhandler
let gpsLayerDef: FilteredLayer = this.filteredLayers.data.filter(l => l.layerDef.id === "gps_location")[0]
this.currentUserLocation = new SimpleFeatureSource(gpsLayerDef, Tiles.tile_index(0, 0, 0));
}
private initHomeLocation() {
const empty = []
const feature = UIEventSource.ListStabilized(this.osmConnection.userDetails.map(userDetails => {
if (userDetails === undefined) {
return undefined;
}
const home = userDetails.home;
if (home === undefined) {
return undefined;
}
return [home.lon, home.lat]
})).map(homeLonLat => {
if (homeLonLat === undefined) {
return empty
}
return [{
feature: {
"type": "Feature",
"properties": {
"id":"home",
"user:home": "yes",
"_lon": homeLonLat[0],
"_lat": homeLonLat[1]
},
"geometry": {
"type": "Point",
"coordinates": homeLonLat
}
}, freshness: new Date()
}]
})
const flayer = this.filteredLayers.data.filter(l => l.layerDef.id === "home_location")[0]
this.homeLocation = new SimpleFeatureSource(flayer, Tiles.tile_index(0, 0, 0), feature)
}
private InitializeFilteredLayers() {
// Initialize the filtered layers state

View file

@ -36,10 +36,7 @@ export default class UserRelatedState extends ElementsState {
* WHich other themes the user previously visited
*/
public installedThemes: UIEventSource<{ layout: LayoutConfig; definition: string }[]>;
/**
* A feature source containing the current home location of the user
*/
public homeLocation: FeatureSource
constructor(layoutToUse: LayoutConfig) {
super(layoutToUse);
@ -88,7 +85,6 @@ export default class UserRelatedState extends ElementsState {
this.InitializeLanguage();
this.initHomeLocation()
new SelectedElementTagsUpdater(this)
}
@ -116,37 +112,4 @@ export default class UserRelatedState extends ElementsState {
.ping();
}
private initHomeLocation() {
const empty = []
const feature = UIEventSource.ListStabilized(this.osmConnection.userDetails.map(userDetails => {
if (userDetails === undefined) {
return undefined;
}
const home = userDetails.home;
if (home === undefined) {
return undefined;
}
return [home.lon, home.lat]
})).map(homeLonLat => {
if (homeLonLat === undefined) {
return empty
}
return [{
"type": "Feature",
"properties": {
"user:home": "yes",
"_lon": homeLonLat[0],
"_lat": homeLonLat[1]
},
"geometry": {
"type": "Point",
"coordinates": homeLonLat
}
}]
})
this.homeLocation = new StaticFeatureSource(feature, false)
}
}