forked from MapComplete/MapComplete
		
	Fix: rotation of the GPS-marker
This commit is contained in:
		
							parent
							
								
									c19317bd04
								
							
						
					
					
						commit
						bbc7698b12
					
				
					 2 changed files with 30 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
import {QueryParameters} from "../Web/QueryParameters"
 | 
			
		||||
import {BBox} from "../BBox"
 | 
			
		||||
import Constants from "../../Models/Constants"
 | 
			
		||||
import { GeoLocationPointProperties, GeoLocationState } from "../State/GeoLocationState"
 | 
			
		||||
import {GeoLocationState} from "../State/GeoLocationState"
 | 
			
		||||
import {UIEventSource} from "../UIEventSource"
 | 
			
		||||
import {Feature, LineString, Point} from "geojson"
 | 
			
		||||
import {FeatureSource, WritableFeatureSource} from "../FeatureSource/FeatureSource"
 | 
			
		||||
| 
						 | 
				
			
			@ -147,32 +147,36 @@ export default class GeoLocationHandler {
 | 
			
		|||
    private CopyGeolocationIntoMapstate() {
 | 
			
		||||
        const features: UIEventSource<Feature[]> = new UIEventSource<Feature[]>([])
 | 
			
		||||
        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"]
 | 
			
		||||
        let i = 0
 | 
			
		||||
        this.geolocationState.currentGPSLocation.addCallbackAndRun((location) => {
 | 
			
		||||
            if (location === undefined) {
 | 
			
		||||
                return
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            const feature = <Feature>{
 | 
			
		||||
                type: "Feature",
 | 
			
		||||
                properties: <GeoLocationPointProperties>{
 | 
			
		||||
                    id: "gps",
 | 
			
		||||
            const properties =  {
 | 
			
		||||
                id: "gps-"+i,
 | 
			
		||||
                "user:location": "yes",
 | 
			
		||||
                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: {
 | 
			
		||||
                    type: "Point",
 | 
			
		||||
                    coordinates: [location.longitude, location.latitude],
 | 
			
		||||
                },
 | 
			
		||||
            }
 | 
			
		||||
            for (const key of keysToCopy) {
 | 
			
		||||
                if (location[key] !== null) {
 | 
			
		||||
                    feature.properties[key] = location[key]
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            features.setData([feature])
 | 
			
		||||
        })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,6 +32,9 @@ export class GeoLocationState {
 | 
			
		|||
     */
 | 
			
		||||
    public readonly allowMoving: UIEventSource<boolean> = new UIEventSource<boolean>(true)
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The latest GeoLocationCoordinates, as given by the WebAPI
 | 
			
		||||
     */
 | 
			
		||||
    public readonly currentGPSLocation: UIEventSource<GeolocationCoordinates | undefined> =
 | 
			
		||||
        new UIEventSource<GeolocationCoordinates | undefined>(undefined)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue