forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapVLayer.js
More file actions
260 lines (232 loc) · 7.97 KB
/
MapVLayer.js
File metadata and controls
260 lines (232 loc) · 7.97 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import L from "leaflet";
import '../core/Base';
import {MapVRenderer} from "./mapv/MapVRenderer";
import Attributions from '../core/Attributions'
/**
* @class MapVLayer
* @deprecatedclassinstance L.supermap.mapVLayer
* @classdesc MapV 图层类。MapV 是一款地理信息可视化开源库,MapV 图层可以用来展示大量地理信息数据,点、线、面的数据,每种数据也有不同的展示类型,如直接打点、热力图、网格、聚合等方式展示数据。<br>
* 展示大量的点数据:如热力图、网格、蜂窝状、点聚合、按颜色区间、按半径大小等方式。<br>
* 展示大量的线数据:如普通画线、高亮叠加、热力线数据展示等方式,适合展示大量轨迹的场景。<br>
* 展示大量的自定义面数据:按颜色区间来展示,如展示行政区划数据。
* @category Visualization MapV
* @modulecategory Overlay
* @extends {L.Layer}
* @param {Mapv.DataSet} dataSet - MapV 图层数据集。
* @param {Object} mapVOptions - MapV 图层参数。
* @param {Object} options - 参数。
* @param {string} [options.attributionPrefix] - 版权信息前缀。
* @param {string} [options.attribution='© 2018 百度 MapV'] - 版权描述信息。
* @fires MapVLayer#loaded
* @usage
*/
export var MapVLayer = L.Layer.extend({
options: {
attributionPrefix: null,
attribution: Attributions.MapV.attribution
},
initialize: function (dataSet, mapVOptions, options) {
options = options || {};
this.dataSet = dataSet || {};
this.mapVOptions = mapVOptions || {};
this.render = this.render.bind(this);
L.Util.setOptions(this, options);
if (this.options.attributionPrefix) {
this.options.attribution = this.options.attributionPrefix + this.options.attribution;
}
this.canvas = this._createCanvas();
L.stamp(this);
},
/**
* @private
* @function MapVLayer.prototype.onAdd
* @description 添加地图图层。
* @param {L.Map} map - Leaflet Map 对象。
*/
onAdd: function (map) {
this._map = map;
var overlayPane = this.getPane();
var container = this.container = L.DomUtil.create("div", "leaflet-layer leaflet-zoom-animated", overlayPane);
container.appendChild(this.canvas);
var size = map.getSize();
container.style.width = size.x + "px";
container.style.height = size.y + "px";
this.renderer = new MapVRenderer(map, this, this.dataSet, this.mapVOptions);
this.draw();
/**
* @event MapVLayer#loaded
* @description 图层添加完成之后触发。
*/
this.fire("loaded");
},
// _hide: function () {
// this.canvas.style.display = 'none';
// },
// _show: function () {
// this.canvas.style.display = 'block';
// },
/**
* @private
* @function MapVLayer.prototype.onRemove
* @description 删除地图图层。
*/
onRemove: function () {
L.DomUtil.remove(this.container);
this.renderer.destroy();
},
/**
* @function MapVLayer.prototype.addData
* @description 添加数据。
* @param {Object} data - 需要添加的数据。
* @param {Object} options - 参数。
*/
addData: function (data, options) {
this.renderer.addData(data, options);
},
/**
* @function MapVLayer.prototype.update
* @description 更新图层。
* @param {Object} opt - 待更新的数据。
* @param {Object} data - mapv 数据集。
* @param {Object} options - 参数。
*/
update: function (opt) {
this.renderer.update(opt);
},
/**
* @function MapVLayer.prototype.getData
* @description 获取数据。
* @returns {Mapv.DataSet} mapv 数据集。
*/
getData: function () {
if (this.renderer) {
this.dataSet = this.renderer.getData();
}
return this.dataSet;
},
/**
* @function MapVLayer.prototype.removeData
* @description 删除数据。
* @param {function} filter - 过滤条件。指定数据项后,返回值为 true,表示删除该元素;否则表示不删除。
* @example
* filter=function(data){
* if(data.id=="1"){
* return true
* }
* return false;
* }
*/
removeData: function (filter) {
this.renderer && this.renderer.removeData(filter);
},
/**
* @function MapVLayer.prototype.clearData
* @description 清除数据。
*/
clearData: function () {
this.renderer.clearData();
},
/**
* @function MapVLayer.prototype.draw
* @description 绘制图层。
*/
draw: function () {
return this._reset();
},
/**
* @function MapVLayer.prototype.setZIndex
* @description 设置 canvas 层级。
* @param {number} zIndex - canvas 层级。
*/
setZIndex: function (zIndex) {
this.canvas.style.zIndex = zIndex;
},
/**
* @function MapVLayer.prototype.render
* @description 渲染。
*/
render: function () {
this.renderer._canvasUpdate();
},
/**
* @function MapVLayer.prototype.getCanvas
* @description 获取 canvas。
* @returns {HTMLElement} 返回 mapV 图层包含的 canvas 对象。
*/
getCanvas: function () {
return this.canvas;
},
/**
* @function MapVLayer.prototype.getContainer
* @description 获取容器。
* @returns {HTMLElement} 返回包含 mapV 图层的 dom 对象。
*/
getContainer: function () {
return this.container;
},
/**
* @function MapVLayer.prototype.getTopLeft
* @description 获取左上角坐标。
* @returns {L.Bounds} 返回左上角坐标。
*/
getTopLeft: function () {
var map = this._map;
var topLeft;
if (map) {
var bounds = map.getBounds();
topLeft = bounds.getNorthWest();
}
return topLeft;
},
_createCanvas: function () {
var canvas = document.createElement('canvas');
canvas.style.position = 'absolute';
canvas.style.top = 0 + "px";
canvas.style.left = 0 + "px";
canvas.style.pointerEvents = "none";
canvas.style.zIndex = this.options.zIndex || 200;
var global$2 = typeof window === 'undefined' ? {} : window;
var devicePixelRatio = this.devicePixelRatio = global$2.devicePixelRatio || 1;
if (!this.mapVOptions.context || this.mapVOptions.context === '2d') {
canvas.getContext('2d').scale(devicePixelRatio, devicePixelRatio);
}
return canvas;
},
_resize: function () {
var canvas = this.canvas;
if (!canvas) {
return;
}
var map = this._map;
var size = map.getSize();
if (this.mapVOptions.draw === 'heatmap') {
canvas.width = parseInt(size.x) * this.devicePixelRatio;
canvas.height = parseInt(size.y) * this.devicePixelRatio;
} else {
canvas.width = parseInt(size.x);
canvas.height = parseInt(size.y);
}
canvas.style.width = size.x + 'px';
canvas.style.height = size.y + 'px';
var bounds = map.getBounds();
var topLeft = map.latLngToLayerPoint(bounds.getNorthWest());
L.DomUtil.setPosition(canvas, topLeft);
},
_reset: function () {
this._resize();
this._render()
},
redraw: function () {
this._resize();
this._render()
},
_render: function () {
this.render();
}
});
export var mapVLayer = function (dataSet, mapVOptions, options) {
return new MapVLayer(dataSet, mapVOptions, options);
};