Fix: rotation of the GPS-marker

This commit is contained in:
Pieter Vander Vennet 2023-06-07 23:55:02 +02:00
parent c19317bd04
commit bbc7698b12
2 changed files with 30 additions and 23 deletions

View file

@ -1,15 +1,15 @@
import { QueryParameters } from "../Web/QueryParameters" import {QueryParameters} from "../Web/QueryParameters"
import { BBox } from "../BBox" import {BBox} from "../BBox"
import Constants from "../../Models/Constants" import Constants from "../../Models/Constants"
import { GeoLocationPointProperties, GeoLocationState } from "../State/GeoLocationState" import {GeoLocationState} from "../State/GeoLocationState"
import { UIEventSource } from "../UIEventSource" import {UIEventSource} from "../UIEventSource"
import { Feature, LineString, Point } from "geojson" import {Feature, LineString, Point} from "geojson"
import { FeatureSource, WritableFeatureSource } from "../FeatureSource/FeatureSource" import {FeatureSource, WritableFeatureSource} from "../FeatureSource/FeatureSource"
import { LocalStorageSource } from "../Web/LocalStorageSource" import {LocalStorageSource} from "../Web/LocalStorageSource"
import { GeoOperations } from "../GeoOperations" import {GeoOperations} from "../GeoOperations"
import { OsmTags } from "../../Models/OsmFeature" import {OsmTags} from "../../Models/OsmFeature"
import StaticFeatureSource from "../FeatureSource/Sources/StaticFeatureSource" import StaticFeatureSource from "../FeatureSource/Sources/StaticFeatureSource"
import { MapProperties } from "../../Models/MapProperties" import {MapProperties} from "../../Models/MapProperties"
/** /**
* The geolocation-handler takes a map-location and a geolocation state. * The geolocation-handler takes a map-location and a geolocation state.
@ -147,32 +147,36 @@ export default class GeoLocationHandler {
private CopyGeolocationIntoMapstate() { private CopyGeolocationIntoMapstate() {
const features: UIEventSource<Feature[]> = new UIEventSource<Feature[]>([]) const features: UIEventSource<Feature[]> = new UIEventSource<Feature[]>([])
this.currentUserLocation = new StaticFeatureSource(features) this.currentUserLocation = new StaticFeatureSource(features)
// For some weird reason, the 'Object.keys' method doesn't work for the 'location: GeolocationCoordinates'-object and will thus not copy all the properties when using {...location}
// As such, they are copied here
const keysToCopy = ["speed", "accuracy", "altitude", "altitudeAccuracy", "heading"] const keysToCopy = ["speed", "accuracy", "altitude", "altitudeAccuracy", "heading"]
let i = 0
this.geolocationState.currentGPSLocation.addCallbackAndRun((location) => { this.geolocationState.currentGPSLocation.addCallbackAndRun((location) => {
if (location === undefined) { if (location === undefined) {
return return
} }
const feature = <Feature>{ const properties = {
type: "Feature", id: "gps-"+i,
properties: <GeoLocationPointProperties>{
id: "gps",
"user:location": "yes", "user:location": "yes",
date: new Date().toISOString(), date: new Date().toISOString(),
...location, }
}, i++
for (const k in keysToCopy) {
// For some weird reason, the 'Object.keys' method doesn't work for the 'location: GeolocationCoordinates'-object and will thus not copy all the properties when using {...location}
// As such, they are copied here
if(location[k]){
properties[k] = location[k]
}
}
const feature = <Feature>{
type: "Feature",
properties,
geometry: { geometry: {
type: "Point", type: "Point",
coordinates: [location.longitude, location.latitude], coordinates: [location.longitude, location.latitude],
}, },
} }
for (const key of keysToCopy) {
if (location[key] !== null) {
feature.properties[key] = location[key]
}
}
features.setData([feature]) features.setData([feature])
}) })

View file

@ -32,6 +32,9 @@ export class GeoLocationState {
*/ */
public readonly allowMoving: UIEventSource<boolean> = new UIEventSource<boolean>(true) public readonly allowMoving: UIEventSource<boolean> = new UIEventSource<boolean>(true)
/**
* The latest GeoLocationCoordinates, as given by the WebAPI
*/
public readonly currentGPSLocation: UIEventSource<GeolocationCoordinates | undefined> = public readonly currentGPSLocation: UIEventSource<GeolocationCoordinates | undefined> =
new UIEventSource<GeolocationCoordinates | undefined>(undefined) new UIEventSource<GeolocationCoordinates | undefined>(undefined)