沈斌
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
import { Component, OnInit, ViewEncapsulation, AfterViewInit, ViewChild, ElementRef, NgZone, OnDestroy } from '@angular/core';
import { AbmComponent } from 'angular-baidu-maps';
 
declare const BMap: any;
declare const BMAP_SATELLITE_MAP: any;
 
@Component({
    selector: 'app-maps-baidu',
    templateUrl: './baidu.component.html'
})
export class MapsBaiduComponent implements OnDestroy {
 
    options: any = {};
    status = '';
    @ViewChild('map') mapComp: AbmComponent;
    satelliteOptions: any;
    private mapSatellite: any;
 
    constructor(private el: ElementRef, private zone: NgZone) { }
 
    private _map: any;
    onReady(map: any) {
        this._map = map;
        map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
        map.addControl(new BMap.MapTypeControl());
        map.setCurrentCity('北京');
        map.enableScrollWheelZoom(true);
        this.status = '加载完成';
        // 添加监听事件
        map.addEventListener('tilesloaded', () => {
            this.status = '地图加载完毕';
        });
        map.addEventListener('click', this._click.bind(this));
    }
 
    _click(e: any) {
        this.status = `${e.point.lng}, ${e.point.lat}, ${+new Date}`;
    }
 
    panTo() {
        this._map.panTo(new BMap.Point(116.404, 39.715));
    }
 
    zoom() {
        this._map.setZoom((this._map.getZoom() + 1) % 17);
    }
 
    infoWindow() {
        const infoWin = new BMap.InfoWindow('地址:北京市东城区王府井大街88号乐天银泰百货八层', {
            width: 200,     // 信息窗口宽度
            height: 100,     // 信息窗口高度
            title: '海底捞王府井店', // 信息窗口标题
            enableMessage: true, // 设置允许信息窗发送短息
            message: '亲耐滴,晚上一起吃个饭吧?戳下面的链接看下地址喔~'
        });
        this._map.openInfoWindow(infoWin, this._map.getCenter());
    }
 
    // 卫星
    onReadySatellite(map: any) {
        map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
        map.setMapType(BMAP_SATELLITE_MAP);
        this.mapSatellite = map;
    }
 
    ngOnDestroy(): void {
        this._map.removeEventListener('click', this._click.bind(this));
    }
 
}