systemMap.js
2.49 KB
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
(function (window) {
var sysMapObj = null;
var mapApp = function (selector, lon = 113.34693, lat = 28.21849) {
return new mapApp.fn.init(selector, lon, lat);
}
mapApp.fn = mapApp.prototype = {
constructor: mapApp,
init: function (selector, lon, lat) {
this.selector = selector;
this.lon = lon;
this.lat = lat;
this.initMap = function () {
return this.initMapMethod();
}
this.createMarkerInfo = function (message, title = "标题") {
return this.markerInfoMethod(message, title)
}
},
initMapMethod() {
if (document.querySelector("#" + this.selector).length == 0) {
alert(`初始化方法元素节点${"#" + this.selector}不存在!`);
return;
}
sysMapObj = new BMapGL.Map(this.selector);
sysMapObj.centerAndZoom(this.getPoint(), 15); //设置中心点
sysMapObj.enableScrollWheelZoom(true); // //开启鼠标滚轮缩放
var scaleCtrl = new BMapGL.ScaleControl(); // 添加比例尺控件
sysMapObj.addControl(scaleCtrl);
var zoomCtrl = new BMapGL.ZoomControl(); // 添加缩放控件
sysMapObj.addControl(zoomCtrl);
var cityCtrl = new BMapGL.CityListControl(); // 添加城市列表控件
sysMapObj.addControl(cityCtrl);
return this;
},
markerInfoMethod: function (message, title) {
var point = this.getPoint()
var marker = new BMapGL.Marker(point); // 创建标注
sysMapObj.addOverlay(marker); // 将标注添加到地图中
var opts = {
width: 300, // 信息窗口宽度
height: 100, // 信息窗口高度
title: title, // 信息窗口标题
}
var infoWindow = new BMapGL.InfoWindow(message, opts); // 创建信息窗口对象
sysMapObj.openInfoWindow(infoWindow, point); //开启信息窗口
marker.addEventListener("click", function () {
sysMapObj.openInfoWindow(infoWindow, point); //开启信息窗口
});
return this;
},
getPoint () {
var point = new BMapGL.Point(this.lon, this.lat);
return point;
}
}
mapApp.fn.init.prototype = mapApp.fn;
window.mapApp = mapApp;
})(window, undefined);