Implement copassheading
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good

This commit is contained in:
Willem Dantuma 2020-01-03 16:40:14 +01:00
parent 41d55110ea
commit 50d1d9645a
5 changed files with 51 additions and 17 deletions

View File

@ -60,6 +60,7 @@ import { LegendComponent } from './components/legend/legend.component';
import { LayerVectorImageComponent } from './components/aol/layer-vector-image/layer-vector-image.component'; import { LayerVectorImageComponent } from './components/aol/layer-vector-image/layer-vector-image.component';
import { StateSerializerService } from './services/state-serializer.service'; import { StateSerializerService } from './services/state-serializer.service';
import { GeolocationService } from './services/geolocation.service'; import { GeolocationService } from './services/geolocation.service';
import {DeviceOrientationService} from './services/device-orientation.service';
import { localStorageSync } from 'ngrx-store-localstorage'; import { localStorageSync } from 'ngrx-store-localstorage';
import { WidgetStatusComponent } from './components/widget-status/widget-status.component'; import { WidgetStatusComponent } from './components/widget-status/widget-status.component';
import { ForChild} from './components/for-item/for-child.decorator'; import { ForChild} from './components/for-item/for-child.decorator';
@ -114,6 +115,7 @@ export {
AbstractItemListComponent, AbstractItemListComponent,
StateSerializerService, StateSerializerService,
GeolocationService, GeolocationService,
DeviceOrientationService,
IMapState, IMapState,
ISelectedFeatures, ISelectedFeatures,
IItemLayer, IItemLayer,
@ -232,6 +234,7 @@ export class AppCommonMapModule {
providers: [ providers: [
StateSerializerService, StateSerializerService,
GeolocationService, GeolocationService,
DeviceOrientationService,
{ provide: AbstractFeatureListComponent, useClass: FeatureListCroppingschemeComponent, multi: true }, { provide: AbstractFeatureListComponent, useClass: FeatureListCroppingschemeComponent, multi: true },
{ provide: AbstractFeatureListComponent, useClass: FeatureListCropfieldComponent, multi: true }, { provide: AbstractFeatureListComponent, useClass: FeatureListCropfieldComponent, multi: true },
{ provide: AbstractFeatureListFeatureComponent, useClass: FeatureListFeatureComponent, multi: true }, { provide: AbstractFeatureListFeatureComponent, useClass: FeatureListFeatureComponent, multi: true },

View File

@ -62,7 +62,9 @@ export class GpsLocation implements OnInit,OnChanges{
this.instance.setPosition(fromLonLat([p.coords.longitude, p.coords.latitude])); this.instance.setPosition(fromLonLat([p.coords.longitude, p.coords.latitude]));
this.locationTolerance = p.coords.accuracy; this.locationTolerance = p.coords.accuracy;
this.recalcLocationTolerance(); this.recalcLocationTolerance();
this.heading = p.coords.heading; }
if(changes.heading && this.instance) {
this.rotate = "rotate(" + Math.round(changes.heading.currentValue) + " 500 500)";
} }
} }
} }

View File

@ -16,7 +16,8 @@
menuVisible:menuVisible$|async, menuVisible:menuVisible$|async,
searchCollapsed:searchCollapsed$|async, searchCollapsed:searchCollapsed$|async,
clearEnabled:clearEnabled$|async, clearEnabled:clearEnabled$|async,
period:period$|async period:period$|async,
compassHeading:compassHeading$|async
} as state"> } as state">
<aol-map #map (moveEnd)="handleOnMoveEnd($event)" (click)="handleOnMouseDown($event)" [ngClass]="{'panel-visible':state.panelVisible}" class="map"> <aol-map #map (moveEnd)="handleOnMoveEnd($event)" (click)="handleOnMouseDown($event)" [ngClass]="{'panel-visible':state.panelVisible}" class="map">
<div> <div>
@ -34,7 +35,7 @@
<aol-layer-vector> <aol-layer-vector>
<fm-map-item-source-vector [features]="state.features" (onFeaturesSelected)="handleFeaturesSelected($event)" [selectedFeature]="state.selectedFeature" [selectedItem]="state.selectedItem"></fm-map-item-source-vector> <fm-map-item-source-vector [features]="state.features" (onFeaturesSelected)="handleFeaturesSelected($event)" [selectedFeature]="state.selectedFeature" [selectedItem]="state.selectedItem"></fm-map-item-source-vector>
</aol-layer-vector> </aol-layer-vector>
<fm-map-gps-location [position]="state.position" [headingTolerance]="20" [showHeading]="true"></fm-map-gps-location> <fm-map-gps-location [position]="state.position" [headingTolerance]="20" [showHeading]="true" [heading]="state.compassHeading"></fm-map-gps-location>
<div class="control-container"> <div class="control-container">
<!-- <switch2d3d></switch2d3d>--> <!-- <switch2d3d></switch2d3d>-->
<fm-map-pan-to-location [position]="state.position" [mapState]="state.mapState" [animate]="true"></fm-map-pan-to-location> <fm-map-pan-to-location [position]="state.position" [mapState]="state.mapState" [animate]="true"></fm-map-pan-to-location>

View File

@ -18,6 +18,7 @@ import { IDroppedFile } from '../aol/file-drop-target/file-drop-target.component
import { IMetaData } from '../meta-data-modal/meta-data-modal.component'; import { IMetaData } from '../meta-data-modal/meta-data-modal.component';
import { StateSerializerService } from '../../services/state-serializer.service'; import { StateSerializerService } from '../../services/state-serializer.service';
import { GeolocationService} from '../../services/geolocation.service'; import { GeolocationService} from '../../services/geolocation.service';
import {DeviceOrientationService} from '../../services/device-orientation.service';
// AppCommon // AppCommon
import { ResumableFileUploadService, ItemTypeService } from '@farmmaps/common'; import { ResumableFileUploadService, ItemTypeService } from '@farmmaps/common';
@ -69,6 +70,7 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
public menuVisible$: Observable<boolean>; public menuVisible$: Observable<boolean>;
public query$: Observable<IQueryState>; public query$: Observable<IQueryState>;
public position$: Observable<Position>; public position$: Observable<Position>;
public compassHeading$: Observable<number>;
public baseLayersCollapsed:boolean = true; public baseLayersCollapsed:boolean = true;
public overlayLayersCollapsed: boolean = true; public overlayLayersCollapsed: boolean = true;
public extent$: Observable<Extent>; public extent$: Observable<Extent>;
@ -82,7 +84,8 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
public itemTypeService: ItemTypeService, public itemTypeService: ItemTypeService,
private location: Location, private location: Location,
private geolocationService: GeolocationService, private geolocationService: GeolocationService,
private zone: NgZone) { private zone: NgZone,
private deviceorientationService:DeviceOrientationService) {
} }
@HostListener('document:keyup', ['$event']) @HostListener('document:keyup', ['$event'])
@ -143,6 +146,7 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
this.selectedItemLayer$ = this.store.select(mapReducers.selectGetSelectedItemLayer); this.selectedItemLayer$ = this.store.select(mapReducers.selectGetSelectedItemLayer);
this.period$ = this.store.select(mapReducers.selectGetPeriod); this.period$ = this.store.select(mapReducers.selectGetPeriod);
this.position$ = this.geolocationService.getCurrentPosition(); this.position$ = this.geolocationService.getCurrentPosition();
this.compassHeading$ = this.deviceorientationService.getCurrentCompassHeading();
this.mapState$.pipe(withLatestFrom(this.queryState$)).subscribe((state) => { this.mapState$.pipe(withLatestFrom(this.queryState$)).subscribe((state) => {
this.replaceUrl(state[0], state[1], true); this.replaceUrl(state[0], state[1], true);

View File

@ -5,19 +5,43 @@ import { Observer, Observable } from 'rxjs';
@Injectable() @Injectable()
export class DeviceOrientationService { export class DeviceOrientationService {
/** compassHeading(alpha, beta, gamma):number {
* Tries HTML5 geolocation.
* // Convert degrees to radians
* Wraps the Geolocation API into an observable. var alphaRad = alpha * (Math.PI / 180);
* var betaRad = beta * (Math.PI / 180);
* @return An observable of Bearing var gammaRad = gamma * (Math.PI / 180);
*/
getCurrentBearing(): Observable<number> { // Calculate equation components
return Observable.create((observer: Observer<number>) => { var cA = Math.cos(alphaRad);
let sensor = new Magnetometer(); var sA = Math.sin(alphaRad);
sensor.onreading= (ev:Event) => { var cB = Math.cos(betaRad);
observer.next(Math.atan2(sensor.y, sensor.x) * (180 / Math.PI)); var sB = Math.sin(betaRad);
}; var cG = Math.cos(gammaRad);
var sG = Math.sin(gammaRad);
// Calculate A, B, C rotation components
var rA = - cA * sG - sA * sB * cG;
var rB = - sA * sG + cA * sB * cG;
var rC = - cB * cG;
// Calculate compass heading
var compassHeading = Math.atan(rA / rB);
// Convert from half unit circle to whole unit circle
if(rB < 0) {
compassHeading += Math.PI;
}else if(rA < 0) {
compassHeading += 2 * Math.PI;
}
return compassHeading * (180/Math.PI);
}
getCurrentCompassHeading(): Observable<number> {
return Observable.create((observer: Observer<number>) => {
window.addEventListener("deviceorientation", (event:DeviceOrientationEvent)=>{
observer.next(this.compassHeading(event.alpha,event.beta,event.gamma));
} );
}); });
} }