Add gps track line, add documentation
This commit is contained in:
parent
7b7076168f
commit
d3d51af667
18 changed files with 278 additions and 145 deletions
|
@ -184,13 +184,19 @@ export default class GeoLocationHandler extends VariableUiElement {
|
|||
this.currentLocation = state.currentUserLocation
|
||||
this._currentGPSLocation.addCallback((location) => {
|
||||
self._previousLocationGrant.setData("granted");
|
||||
|
||||
console.log("Location is", location,)
|
||||
const feature = {
|
||||
"type": "Feature",
|
||||
properties: {
|
||||
id: "gps",
|
||||
"user:location": "yes",
|
||||
...location
|
||||
"date": new Date().toISOString(),
|
||||
"latitude": location.latitude,
|
||||
"longitude": location.longitude,
|
||||
"speed": location.speed,
|
||||
"accuracy": location.accuracy,
|
||||
"heading": location.heading,
|
||||
"altitude": location.altitude
|
||||
},
|
||||
geometry: {
|
||||
type: "Point",
|
||||
|
|
|
@ -28,7 +28,7 @@ export default class TitleHandler {
|
|||
continue;
|
||||
}
|
||||
if (layer.source.osmTags.matchesProperties(tags)) {
|
||||
const tagsSource = state.allElements.getEventSourceById(tags.id)
|
||||
const tagsSource = state.allElements.getEventSourceById(tags.id) ?? new UIEventSource<any>(tags)
|
||||
const title = new TagRenderingAnswer(tagsSource, layer.title)
|
||||
return new Combine([defaultTitle, " | ", title]).ConstructElement()?.innerText ?? defaultTitle;
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ export default class FeaturePipeline {
|
|||
constructor(
|
||||
handleFeatureSource: (source: FeatureSourceForLayer & Tiled) => void,
|
||||
state: {
|
||||
readonly historicalUserLocations: FeatureSourceForLayer & Tiled;
|
||||
readonly homeLocation: FeatureSourceForLayer & Tiled;
|
||||
readonly currentUserLocation: FeatureSourceForLayer & Tiled;
|
||||
readonly filteredLayers: UIEventSource<FilteredLayer[]>,
|
||||
|
@ -127,7 +128,7 @@ export default class FeaturePipeline {
|
|||
const perLayerHierarchy = new Map<string, TileHierarchyMerger>()
|
||||
this.perLayerHierarchy = perLayerHierarchy
|
||||
|
||||
const patchedHandleFeatureSource = function (src: FeatureSourceForLayer & IndexedFeatureSource & Tiled) {
|
||||
function patchedHandleFeatureSource (src: FeatureSourceForLayer & IndexedFeatureSource & Tiled) {
|
||||
// This will already contain the merged features for this tile. In other words, this will only be triggered once for every tile
|
||||
const srcFiltered =
|
||||
new FilteringFeatureSource(state, src.tileIndex,
|
||||
|
@ -139,6 +140,14 @@ export default class FeaturePipeline {
|
|||
// We do not mark as visited here, this is the responsability of the code near the actual loader (e.g. overpassLoader and OSMApiFeatureLoader)
|
||||
};
|
||||
|
||||
function handlePriviligedFeatureSource(src: FeatureSourceForLayer & Tiled){
|
||||
// Passthrough to passed function, except that it registers as well
|
||||
handleFeatureSource(src)
|
||||
src.features.addCallbackAndRunD(fs => {
|
||||
fs.forEach(ff => state.allElements.addOrGetElement(ff.feature))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
for (const filteredLayer of state.filteredLayers.data) {
|
||||
const id = filteredLayer.layerDef.id
|
||||
|
@ -155,12 +164,17 @@ export default class FeaturePipeline {
|
|||
}
|
||||
|
||||
if (id === "gps_location") {
|
||||
hierarchy.registerTile(state.currentUserLocation)
|
||||
handlePriviligedFeatureSource(state.currentUserLocation)
|
||||
continue
|
||||
}
|
||||
|
||||
if (id === "gps_track") {
|
||||
handlePriviligedFeatureSource(state.historicalUserLocations)
|
||||
continue
|
||||
}
|
||||
|
||||
if (id === "home_location") {
|
||||
hierarchy.registerTile(state.homeLocation)
|
||||
handlePriviligedFeatureSource(state.homeLocation)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ export default class PerLayerFeatureSourceSplitter {
|
|||
const knownLayers = new Map<string, FeatureSourceForLayer & Tiled>()
|
||||
|
||||
function update() {
|
||||
const features = upstream.features.data;
|
||||
const features = upstream.features?.data;
|
||||
if (features === undefined) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -135,6 +135,7 @@ export default class MapState extends UserRelatedState {
|
|||
|
||||
this.initHomeLocation()
|
||||
this.initGpsLocation()
|
||||
this.initUserLocationTrail()
|
||||
}
|
||||
|
||||
public AddAllOverlaysToMap(leafletMap: UIEventSource<any>) {
|
||||
|
@ -185,6 +186,46 @@ export default class MapState extends UserRelatedState {
|
|||
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 initUserLocationTrail(){
|
||||
const histCoordinates = []
|
||||
let lineFeature = {
|
||||
type:"Feature",
|
||||
geometry:{
|
||||
type: "LineString",
|
||||
coordinates: histCoordinates
|
||||
},
|
||||
properties:{
|
||||
"user:location":"yes",
|
||||
"id":"gps_track"
|
||||
}
|
||||
}
|
||||
const features = new UIEventSource<{feature: any, freshness: Date}[]>([], "gps_track")
|
||||
let i = 0
|
||||
this.currentUserLocation.features.addCallbackAndRunD(([location]) => {
|
||||
if(location === undefined){
|
||||
return;
|
||||
}
|
||||
const feature = JSON.parse(JSON.stringify(location.feature))
|
||||
feature.properties.id = "gps/"+i
|
||||
i++
|
||||
console.log("New location: ", feature)
|
||||
features.data.push({feature, freshness: new Date()})
|
||||
histCoordinates.push(feature.geometry.coordinates)
|
||||
|
||||
if(lineFeature !== undefined && lineFeature.geometry.coordinates.length >= 2){
|
||||
features.data.push({feature: lineFeature, freshness: new Date()})
|
||||
lineFeature = undefined
|
||||
}
|
||||
|
||||
features.ping()
|
||||
})
|
||||
|
||||
|
||||
let gpsLayerDef: FilteredLayer = this.filteredLayers.data.filter(l => l.layerDef.id === "gps_track")[0]
|
||||
this.historicalUserLocations = new SimpleFeatureSource(gpsLayerDef, Tiles.tile_index(0, 0, 0), features);
|
||||
|
||||
}
|
||||
|
||||
private initHomeLocation() {
|
||||
const empty = []
|
||||
|
@ -225,7 +266,6 @@ export default class MapState extends UserRelatedState {
|
|||
}
|
||||
|
||||
private InitializeFilteredLayers() {
|
||||
// Initialize the filtered layers state
|
||||
|
||||
const layoutToUse = this.layoutToUse;
|
||||
const empty = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue