diff --git a/src/app/map/map.component.html b/src/app/map/map.component.html index 52b8399..a2f1176 100644 --- a/src/app/map/map.component.html +++ b/src/app/map/map.component.html @@ -4,11 +4,12 @@ {{version}}
- - - - - + + + + + + @@ -18,7 +19,7 @@
- + diff --git a/src/app/map/map.component.ts b/src/app/map/map.component.ts index 059a86d..dc69453 100644 --- a/src/app/map/map.component.ts +++ b/src/app/map/map.component.ts @@ -3,16 +3,20 @@ import {GeolocationService} from "../geolocation/geolocation.service"; import {filter} from "rxjs/operators"; import {version} from "../../../package.json"; +declare const google; + @Component({ selector: 'map', templateUrl: 'map.component.html', styleUrls: ['map.component.scss'] }) export class MapComponent { + drawListener; mapApi: any; markers = []; - mode: 'marker'; + mode: 'marker' | 'circle' | 'square' | 'draw'; position: any; + remove = false; style: 'satellite' | 'terrain' | 'roadmap' | 'hybrid' = 'terrain'; version = version; @@ -41,4 +45,28 @@ export class MapComponent { this.mode = null; } } + + draw() { + if(!this.drawListener) { + this.drawListener = google.maps.event.addDomListener(this.mapApi.getDiv(), 'mousedown', () => { + let poly = new google.maps.Polyline({map: this.mapApi, clickable: true}); + google.maps.event.addListener(poly, 'click', () => { + if(this.remove) poly.setMap(null); + }); + let moveListener = google.maps.event.addListener(this.mapApi, 'mousemove', e => poly.getPath().push(e.latLng)); + google.maps.event.addListener(this.mapApi, 'mouseup', () => google.maps.event.removeListener(moveListener)); + google.maps.event.addListener(poly, 'mouseup', () => google.maps.event.removeListener(moveListener)); + }); + + this.mapApi.setOptions({ + draggable: false + }); + } else { + google.maps.event.removeListener(this.drawListener); + this.drawListener = null; + this.mapApi.setOptions({ + draggable: true + }); + } + } }