Added some circle drawing tool

This commit is contained in:
Zakary Timson 2019-08-25 12:04:15 -04:00
parent b8bb4aed2b
commit 30b74dd91c
4 changed files with 20 additions and 10 deletions

View File

@ -25,17 +25,17 @@
<ng-template #menuItem let-item let-menu="menu" let-mode="mode"> <ng-template #menuItem let-item let-menu="menu" let-mode="mode">
<ng-container *ngIf="mode == 'icon' && !item.subMenu"> <ng-container *ngIf="mode == 'icon' && !item.subMenu">
<button mat-icon-button class="d-inline mr-1" [ngClass]="{'selected': item?.enabled}" (click)="clickWrapper(item, menu)" [matTooltip]="item.name"> <button mat-icon-button class="d-inline mr-1" [ngClass]="{'selected': item?.enabled}" (click)="clickWrapper(item, menu)" [matTooltip]="item.name">
<mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon> <mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon><span *ngIf="item.faicon" [class]="item.faicon" style="height: 18px; width: 18px; font-size: 18px"></span>
</button> </button>
</ng-container> </ng-container>
<ng-container *ngIf="mode == 'menu' && !item.subMenu"> <ng-container *ngIf="mode == 'menu' && !item.subMenu">
<button mat-menu-item [ngClass]="{'selected': item?.enabled}" (click)="clickWrapper(item, menu)"> <button mat-menu-item [ngClass]="{'selected': item?.enabled}" (click)="clickWrapper(item, menu)">
<mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon> {{item?.name}} <mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon><span *ngIf="item.faicon" [class]="item.faicon" style="height: 18px; width: 18px; font-size: 18px; margin-left: 4px; margin-right: 16px"></span> {{item?.name}}
</button> </button>
</ng-container> </ng-container>
<ng-container *ngIf="mode == 'icon' && item.subMenu"> <ng-container *ngIf="mode == 'icon' && item.subMenu">
<button mat-icon-button class="d-inline mr-1" [ngClass]="{'selected': item?.enabled}" (click)="clickWrapper(item, menu)" [matTooltip]="item.name" [matMenuTriggerFor]="subMenu"> <button mat-icon-button class="d-inline mr-1" [ngClass]="{'selected': item?.enabled}" (click)="clickWrapper(item, menu)" [matTooltip]="item.name" [matMenuTriggerFor]="subMenu">
<mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon> <mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon><span *ngIf="item.faicon" [class]="item.faicon" style="height: 18px; width: 18px; font-size: 18px"></span>
</button> </button>
<mat-menu #subMenu="matMenu"> <mat-menu #subMenu="matMenu">
<ng-container *ngFor="let child of item.subMenu"> <ng-container *ngFor="let child of item.subMenu">
@ -45,7 +45,7 @@
</ng-container> </ng-container>
<ng-container *ngIf="mode == 'menu' && item.subMenu"> <ng-container *ngIf="mode == 'menu' && item.subMenu">
<button mat-menu-item [ngClass]="{'selected': item?.enabled}" (click)="clickWrapper(item, menu)" [matMenuTriggerFor]="subMenu"> <button mat-menu-item [ngClass]="{'selected': item?.enabled}" (click)="clickWrapper(item, menu)" [matMenuTriggerFor]="subMenu">
<mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon> {{item?.name}} <mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon><span *ngIf="item.faicon" [class]="item.faicon" style="height: 18px; width: 18px; font-size: 18px; margin-left: 4px; margin-right: 16px"></span> {{item?.name}}
</button> </button>
<mat-menu #subMenu="matMenu"> <mat-menu #subMenu="matMenu">
<ng-container *ngFor="let child of item.subMenu"> <ng-container *ngFor="let child of item.subMenu">

View File

@ -1,5 +1,6 @@
export interface ToolbarItem { export interface ToolbarItem {
name: string; name: string;
faicon?: string;
icon?: string; icon?: string;
hidden?: boolean; hidden?: boolean;
toggle?: boolean; toggle?: boolean;

View File

@ -115,7 +115,8 @@ export class MapService {
if(this.weatherLayer) this.weatherLayer.layer.addTo(this.map); if(this.weatherLayer) this.weatherLayer.layer.addTo(this.map);
} }
newCircle(latlng: LatLng, radius: number, opts: any={}) { newCircle(latlng: LatLng, radius?: number, opts: any={}) {
if(!radius) radius = 100_000 / this.map.getZoom();
opts.radius = radius; opts.radius = radius;
let circle = L.circle(latlng, opts).addTo(this.map); let circle = L.circle(latlng, opts).addTo(this.map);
circle.on('click', e => this.click.next({event: e, symbol: circle})); circle.on('click', e => this.click.next({event: e, symbol: circle}));

View File

@ -26,7 +26,6 @@ export class MapComponent implements OnInit {
drawColor = '#ff4141'; drawColor = '#ff4141';
isNaN = isNaN; isNaN = isNaN;
map: MapService; map: MapService;
markers = [];
position; position;
positionMarker = {arrow: null, circle: null}; positionMarker = {arrow: null, circle: null};
shareDialog = false; shareDialog = false;
@ -37,6 +36,9 @@ export class MapComponent implements OnInit {
menu: ToolbarItem[] = [ menu: ToolbarItem[] = [
{name: 'Marker', icon: 'room', toggle: true, click: () => { this.addMarker(); }}, {name: 'Marker', icon: 'room', toggle: true, click: () => { this.addMarker(); }},
{name: 'Draw', icon: 'create', toggle: true, onEnabled: () => this.startDrawing(), onDisabled: () => this.stopDrawing()}, {name: 'Draw', icon: 'create', toggle: true, onEnabled: () => this.startDrawing(), onDisabled: () => this.stopDrawing()},
{name: 'Circle', faicon: 'far fa-circle', toggle: true, click: () => { this.addCircle(); }},
{name: 'Square', faicon: 'far fa-square', toggle: true},
{name: 'Polygon', faicon: 'fas fa-draw-polygon', toggle: true},
{name: 'Measure', icon: 'straighten', toggle: true, onEnabled: () => this.startMeasuring(), onDisabled: () => this.stopMeasuring()}, {name: 'Measure', icon: 'straighten', toggle: true, onEnabled: () => this.startMeasuring(), onDisabled: () => this.stopMeasuring()},
{name: 'Delete', icon: 'delete', toggle: true}, {name: 'Delete', icon: 'delete', toggle: true},
{name: 'Map Style', icon: 'terrain', subMenu: [ {name: 'Map Style', icon: 'terrain', subMenu: [
@ -69,7 +71,7 @@ export class MapComponent implements OnInit {
// Handle click actions // Handle click actions
this.map.click.pipe(filter(e => !!e)).subscribe(e => { this.map.click.pipe(filter(e => !!e)).subscribe(e => {
if(!!e.symbol && this.menu[3].enabled) return this.map.delete(e.symbol); if(!!e.symbol && this.menu[6].enabled) return this.map.delete(e.symbol);
if(e.symbol instanceof L.Marker) this.bottomSheet.open(MarkerComponent, {data: e.symbol}); if(e.symbol instanceof L.Marker) this.bottomSheet.open(MarkerComponent, {data: e.symbol});
}); });
@ -90,10 +92,16 @@ export class MapComponent implements OnInit {
}); });
} }
addCircle() {
this.map.click.pipe(skip(1), take(1), filter(() => this.menu[2].enabled)).subscribe(e => {
this.menu[2].enabled = false;
this.map.newCircle(e.event.latlng);
});
}
addMarker() { addMarker() {
this.map.click.pipe(skip(1), take(1), filter(() => this.menu[0].enabled)).subscribe(e => { this.map.click.pipe(skip(1), take(1), filter(() => this.menu[0].enabled)).subscribe(e => {
this.menu[0].enabled = false; this.menu[0].enabled = false;
this.markers.push(e.event.latlng);
this.map.newMarker(e.event.latlng); this.map.newMarker(e.event.latlng);
}); });
} }
@ -120,13 +128,13 @@ export class MapComponent implements OnInit {
} }
startCalibrating() { startCalibrating() {
this.menu[6].enabled = true; this.menu[9].enabled = true;
this.calibration = this.bottomSheet.open(CalibrateComponent, { this.calibration = this.bottomSheet.open(CalibrateComponent, {
hasBackdrop: false, hasBackdrop: false,
disableClose: true disableClose: true
}); });
this.calibration.afterDismissed().subscribe(() => { this.calibration.afterDismissed().subscribe(() => {
this.menu[6].enabled = false; this.menu[9].enabled = false;
this.calibration = null; this.calibration = null;
}); });
} }