Last active
November 3, 2019 16:37
-
-
Save timdeschryver/482d985a6c3a20a33b719cadbdda653e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, ViewChild } from '@angular/core' | |
import { MapInfoWindow, MapMarker, GoogleMap } from '@angular/google-maps' | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'], | |
}) | |
export class AppComponent implements OnInit { | |
@ViewChild(GoogleMap, { static: false }) map: GoogleMap | |
@ViewChild(MapInfoWindow, { static: false }) info: MapInfoWindow | |
zoom = 12 | |
center: google.maps.LatLngLiteral | |
options: google.maps.MapOptions = { | |
zoomControl: false, | |
scrollwheel: false, | |
disableDoubleClickZoom: true, | |
mapTypeId: 'hybrid', | |
maxZoom: 15, | |
minZoom: 8, | |
} | |
markers = [] | |
infoContent = '' | |
ngOnInit() { | |
navigator.geolocation.getCurrentPosition(position => { | |
this.center = { | |
lat: position.coords.latitude, | |
lng: position.coords.longitude, | |
} | |
}) | |
} | |
zoomIn() { | |
if (this.zoom < this.options.maxZoom) this.zoom++ | |
} | |
zoomOut() { | |
if (this.zoom > this.options.minZoom) this.zoom-- | |
} | |
click(event: google.maps.MouseEvent) { | |
console.log(event) | |
} | |
logCenter() { | |
console.log(JSON.stringify(this.map.getCenter())) | |
} | |
addMarker() { | |
this.markers.push({ | |
position: { | |
lat: this.center.lat + ((Math.random() - 0.5) * 2) / 10, | |
lng: this.center.lng + ((Math.random() - 0.5) * 2) / 10, | |
}, | |
label: { | |
color: 'red', | |
text: 'Marker label ' + (this.markers.length + 1), | |
}, | |
title: 'Marker title ' + (this.markers.length + 1), | |
info: 'Marker info ' + (this.markers.length + 1), | |
options: { | |
animation: google.maps.Animation.BOUNCE, | |
}, | |
}) | |
} | |
openInfo(marker: MapMarker, content) { | |
this.infoContent = content | |
this.info.open(marker) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment