沈斌
2017-12-15 f9b157566af34b8dc28ba10b34d025ac04f3168b
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
68
69
70
71
72
import { Component, ViewChild, ElementRef, NgZone, OnDestroy } from '@angular/core';
import { AqmComponent } from 'angular-qq-maps';
 
declare const qq: any;
 
@Component({
    selector: 'app-maps-qq',
    templateUrl: './qq.component.html'
})
export class MapsQQComponent implements OnDestroy {
    options: any = {};
    status = '';
    @ViewChild('map') mapComp: AqmComponent;
    satelliteOptions: any;
    private mapSatellite: any;
 
    constructor(private el: ElementRef, private zone: NgZone) { }
 
    private map: any;
    onReady(mapNative: any) {
        mapNative.setOptions({
            zoom: 12,
            center: new qq.maps.LatLng(39.916527, 116.397128)
        });
        this.map = mapNative;
        this.status = '加载完成';
        // 添加监听事件
        qq.maps.event.addListener(this.map, 'click', (event: any) => {
            // tslint:disable-next-line:no-unused-expression
            new qq.maps.Marker({
                position: event.latLng,
                map: this.map
            });
            this.zone.run(() => {
                this.status = `click ${+new Date}`;
            });
        });
    }
 
    panTo() {
        this.map.panTo(new qq.maps.LatLng(39.9, 116.4));
    }
 
    zoom() {
        this.map.zoomTo((this.map.getZoom() + 1) % 17);
    }
 
    infoWindow() {
        const infoWin = new qq.maps.InfoWindow({
            map: this.map
        });
        infoWin.open();
        infoWin.setContent('Hello world');
        infoWin.setPosition(this.map.getCenter());
    }
 
    // 卫星
    onReadySatellite(mapNative: any) {
        mapNative.setOptions({
            zoom: 14,
            center: new qq.maps.LatLng(39.916527, 116.397128),
            mapTypeId: qq.maps.MapTypeId.SATELLITE
        });
        this.mapSatellite = mapNative;
    }
 
    ngOnDestroy(): void {
        ['click'].forEach(eventName => {
            qq.maps.event.clearListeners(this.map, eventName);
        });
    }
}