Added draw color picker

This commit is contained in:
ztimson 2019-07-22 12:39:45 -04:00
parent ba84322719
commit 105d1bb27d
7 changed files with 115 additions and 10 deletions

67
src/app/animations.ts Normal file
View File

@ -0,0 +1,67 @@
import {animate, state, style, transition, trigger} from "@angular/animations";
const defaultTiming = '500ms';
export const collapse = (timings: string = defaultTiming) => trigger('collapse', [
transition(':leave', [
style({height: '*'}),
animate(timings, style({height: '0'}))
])
]);
export const expand = (timings: string = defaultTiming) => trigger('expand', [
transition(':enter', [
style({height: '0'}),
animate(timings, style({height: '*'}))
])
]);
export const fadeIn = (timings: string = defaultTiming) => trigger('fadeIn', [
transition(':enter', [
style({ opacity: 0 }),
animate(timings, style({ opacity: 1 }))
])
]);
export const fadeOut = (timings: string = defaultTiming) => trigger('fadeOut', [
transition(':leave', [
style({ opacity: 1 }),
animate(timings, style({ opacity: 0 }))
])
]);
export const flyInRight = (timings: string = defaultTiming) => trigger('flyInRight', [
transition(':enter', [
style({transform: 'translateX(100%)'}),
animate(timings, style({transform: 'translateX(0%)'}))
])
]);
export const flyOutRight = (timings: string = defaultTiming) => trigger('flyOutRight', [
transition(':leave', [
style({transform: 'translateX(0%)'}),
animate(timings, style({transform: 'translateX(100%)'}))
])
]);
export const flyInTop = (timings: string = defaultTiming) => trigger('flyInTop', [
transition(':enter', [
style({transform: 'translateY(-100%)'}),
animate(timings, style({transform: 'translateY(0%)'}))
])
]);
export const flyOutTop = (timings: string = defaultTiming) => trigger('flyOutTop', [
transition(':leave', [
style({transform: 'translateY(0%)'}),
animate(timings, style({transform: 'translateY(-100%)'}))
])
]);
export const rotate = (timings: string = defaultTiming) => trigger('rotate', [
state('up', style({transform: 'rotate(0deg)'})),
state('right', style({transform: 'rotate(90deg)'})),
state('down', style({transform: 'rotate(180deg)'})),
state('left', style({transform: 'rotate(270deg)'})),
transition('* => *', [animate(timings)])
]);

View File

@ -1,3 +1,3 @@
<div class="bg-white p-3"> <div class="py-1">
<div *ngFor="let c of colors" class="rounded-circle" [style.backgroundColor]="c" style="height: 30px; width: 30px"></div> <div *ngFor="let c of colors" class="m-3 color-palette" [ngClass]="{'selected': selected == c}" [style.backgroundColor]="c" (click)="selected = c"></div>
</div> </div>

View File

@ -0,0 +1,9 @@
.color-palette {
border-radius: 50% 50%;
width: 30px;
height: 30px;
&.selected {
border: 4px solid #3b5998;
}
}

View File

@ -1,9 +1,25 @@
import {Component} from "@angular/core"; import {Component, EventEmitter, Input, OnInit, Output} from "@angular/core";
@Component({ @Component({
selector: 'palette', selector: 'palette',
templateUrl: 'palette.component.html' templateUrl: 'palette.component.html',
styleUrls: ['palette.component.scss']
}) })
export class PaletteComponent { export class PaletteComponent implements OnInit {
colors = ['#393936', '#ffffff', '#008dd5', '#1a891d', '#d82b00'] @Input() colors = ['#393936', '#ffffff', '#008dd5', '#1a891d', '#d82b00'];
@Output() selectedChange = new EventEmitter<string>();
private _selected;
get selected() { return this._selected; }
@Input() set selected(color: string) {
this._selected = color;
this.selectedChange.emit(this._selected);
};
constructor() { }
ngOnInit() {
if(!this.selected) this.selected = this.colors[0];
}
} }

View File

@ -6,8 +6,8 @@
<agm-circle [latitude]="position.latitude" [longitude]="position.longitude" [radius]="position.accuracy" fillColor="#5C95F2" [clickable]="false"></agm-circle> <agm-circle [latitude]="position.latitude" [longitude]="position.longitude" [radius]="position.accuracy" fillColor="#5C95F2" [clickable]="false"></agm-circle>
</ng-container> </ng-container>
</agm-map> </agm-map>
<div class="palette"> <div *ngIf="showPalette" [@flyInRight] [@flyOutRight] class="palette">
<palette></palette> <palette [(selected)]="drawColor"></palette>
</div> </div>
<div class="info p-2"> <div class="info p-2">
<span *ngIf="!position" class="text-danger">No GPS</span> <span *ngIf="!position" class="text-danger">No GPS</span>

View File

@ -2,6 +2,13 @@
height: calc(100vh - 40px); height: calc(100vh - 40px);
} }
.palette {
position: fixed;
z-index: 100;
top: 50px;
right: 15px;
}
.info { .info {
background-color: #00000050; background-color: #00000050;
position: fixed; position: fixed;

View File

@ -6,19 +6,23 @@ import {CalibrateComponent} from "../../components/calibrate/calibrate.component
import {ToolbarItem} from "../../components/toolbar/toolbarItem"; import {ToolbarItem} from "../../components/toolbar/toolbarItem";
import {BehaviorSubject} from "rxjs"; import {BehaviorSubject} from "rxjs";
import {LatLngLiteral} from "@agm/core"; import {LatLngLiteral} from "@agm/core";
import {flyInRight, flyOutRight} from "../../animations";
declare const google; declare const google;
@Component({ @Component({
selector: 'map', selector: 'map',
templateUrl: 'map.component.html', templateUrl: 'map.component.html',
styleUrls: ['map.component.scss'] styleUrls: ['map.component.scss'],
animations: [flyInRight('150ms'), flyOutRight('150ms')]
}) })
export class MapComponent { export class MapComponent {
drawColor: string;
drawListener = []; drawListener = [];
mapApi: any; mapApi: any;
mapClick = new BehaviorSubject<LatLngLiteral>(null); mapClick = new BehaviorSubject<LatLngLiteral>(null);
position: any; position: any;
showPalette = false;
style = 'terrain'; style = 'terrain';
isNaN = isNaN; isNaN = isNaN;
@ -146,10 +150,11 @@ export class MapComponent {
} }
startDraw() { startDraw() {
this.showPalette = true;
this.mapApi.setOptions({draggable: false}); this.mapApi.setOptions({draggable: false});
let drawHander = () => { let drawHander = () => {
let poly = new google.maps.Polyline({map: this.mapApi, clickable: true}); let poly = new google.maps.Polyline({map: this.mapApi, clickable: true, strokeColor: this.drawColor});
google.maps.event.addListener(poly, 'click', () => { google.maps.event.addListener(poly, 'click', () => {
if(this.menu[1][3].enabled) poly.setMap(null); if(this.menu[1][3].enabled) poly.setMap(null);
}); });
@ -170,6 +175,7 @@ export class MapComponent {
} }
endDraw() { endDraw() {
this.showPalette = false;
this.mapApi.setOptions({draggable: true}); this.mapApi.setOptions({draggable: true});
this.drawListener.forEach(listener => google.maps.event.removeListener(listener)); this.drawListener.forEach(listener => google.maps.event.removeListener(listener));
this.drawListener = []; this.drawListener = [];