/
map.component.ts
executable file
·67 lines (52 loc) · 1.81 KB
/
map.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {Component, ViewChild} from '@angular/core';
import { registerElement } from 'nativescript-angular/element-registry';
import { MapView, Marker, Position } from 'nativescript-google-maps-sdk';
// Important - must register MapView plugin in order to use in Angular templates
registerElement('MapView', () => MapView);
@Component({
moduleId: module.id,
selector: 'map',
templateUrl: 'map.html',
styleUrls: ['map.css'],
})
export class MapComponent {
latitude = -33.86;
longitude = 151.20;
zoom = 8;
minZoom = 0;
maxZoom = 22;
bearing = 0;
tilt = 0;
padding = [40, 40, 40, 40];
mapView: MapView;
lastCamera: String;
constructor() {
}
//Map events
onMapReady(event) {
console.log('Map Ready');
this.mapView = event.object;
console.log("Setting a marker...");
var marker = new Marker();
marker.position = Position.positionFromLatLng(-33.86, 151.20);
marker.title = "Sydney";
marker.snippet = "Australia";
marker.userData = {index: 1};
this.mapView.addMarker(marker);
}
onCoordinateTapped(args) {
console.log("Coordinate Tapped, Lat: " + args.position.latitude + ", Lon: " + args.position.longitude, args);
}
onMarkerEvent(args) {
console.log("Marker Event: '" + args.eventName
+ "' triggered on: " + args.marker.title
+ ", Lat: " + args.marker.position.latitude + ", Lon: " + args.marker.position.longitude, args);
}
onCameraChanged(args) {
console.log("Camera changed: " + JSON.stringify(args.camera), JSON.stringify(args.camera) === this.lastCamera);
this.lastCamera = JSON.stringify(args.camera);
}
onCameraMove(args) {
console.log("Camera moving: " + JSON.stringify(args.camera));
}
}