Added relative marker placement

This commit is contained in:
Zakary Timson 2019-08-31 14:50:09 -04:00
parent 382d045f32
commit da9aa17cc7
2 changed files with 14 additions and 4 deletions

View File

@ -41,7 +41,8 @@ export function relativeLatLng(latLng: LatLng, meters: number, deg: number) {
let lat = deg2rad(latLng.lat);
let lng = deg2rad(latLng.lng);
let latOut = Math.asin(Math.sign(lat) * Math.cos(d / R) + Math.cos(lat) * Math.sin(d / R) * Math.cos(brng));
// lat2 = math.asin( math.sin(lat1)*math.cos(d/R) + math.cos(lat1)*math.sin(d/R)*math.cos(brng))
let latOut = Math.asin(Math.sin(lat) * Math.cos(d / R) + Math.cos(lat) * Math.sin(d / R) * Math.cos(brng));
let lngOut = lng + Math.atan2(Math.sin(brng) * Math.sin(d / R) * Math.cos(lat), Math.cos(d / R) - Math.sin(lat) * Math.sin(latOut));
latOut = rad2deg(latOut);
lngOut = rad2deg(lngOut);

View File

@ -1,13 +1,13 @@
import {Component, isDevMode, OnInit} from "@angular/core";
import {PhysicsService} from "../../services/physics.service";
import {filter, finalize, skip, take} from "rxjs/operators";
import {filter, finalize, flatMap, skip, take} from "rxjs/operators";
import {MatBottomSheet, MatSnackBar} from "@angular/material";
import {CalibrateComponent} from "../../components/calibrate/calibrate.component";
import {ToolbarItem} from "../../models/toolbarItem";
import {flyInRight, flyOutRight} from "../../animations";
import {MapLayers, MapService, WeatherLayers} from "../../services/map.service";
import {Subscription} from "rxjs";
import {copyToClipboard} from "../../utils";
import {copyToClipboard, relativeLatLng} from "../../utils";
import {ActivatedRoute} from "@angular/router";
import {DimensionsDialogComponent} from "../../components/dimensionsDialog/dimensionsDialog.component";
import {MatDialog} from "@angular/material/dialog";
@ -34,6 +34,14 @@ export class MapComponent implements OnInit {
showPalette = false;
sub: Subscription;
placeRelative = () => {
this.dialog.open(DimensionsDialogComponent, {data: ['Distance (m)', 'Baring']}).afterClosed().subscribe(dimensions => {
let latlng = relativeLatLng({lat: this.position.latitude, lng: this.position.longitude}, dimensions[0], dimensions[1]);
let marker: Marker = {latlng: latlng, color: '#ff4141'};
this.syncService.addMarker(marker);
})
};
startCalibrating = () => {
let calibration = this.bottomSheet.open(CalibrateComponent, {hasBackdrop: false, disableClose: true});
this.sub = calibration.afterDismissed().pipe(finalize(() => calibration.dismiss())).subscribe();
@ -162,7 +170,8 @@ export class MapComponent implements OnInit {
{name: 'Circle', icon: 'panorama_fish_eye', toggle: true, onEnabled: this.startCircle, onDisabled: this.unsub},
{name: 'Square', icon: 'crop_square', toggle: true, onEnabled: this.startRectangle, onDisabled: this.unsub},
{name: 'Polygon', icon: 'details', toggle: true, onEnabled: this.startPolygon, onDisabled: this.stopPolygon},
{name: 'Measure', icon: 'straighten', toggle: true, onEnabled: this.startMeasuring, onDisabled: () => this.unsub},
{name: 'Measure', icon: 'straighten', toggle: true, onEnabled: this.startMeasuring, onDisabled: this.unsub},
{name: 'Place Relative', icon: 'control_camera', click: this.placeRelative},
{name: 'Delete', icon: 'delete', toggle: true, onEnabled: this.startDelete, onDisabled: this.unsub},
{name: 'Map Style', icon: 'terrain', subMenu: [
{name: 'ESRI:Topographic', toggle: true, click: () => this.map.setMapLayer(MapLayers.ESRI_TOPOGRAPHIC)},