@supermapgis/iclient-ol 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/control/ChangeTileVersion.js +438 -0
- package/control/Logo.js +97 -0
- package/control/ScaleLine.js +164 -0
- package/control/index.js +6 -0
- package/core/MapExtend.js +49 -0
- package/core/StyleUtils.js +1253 -0
- package/core/Util.js +500 -0
- package/core/index.js +6 -0
- package/css/ChangeTileVersion.css +347 -0
- package/css/index.js +5 -0
- package/dist/iclient-openlayers-es6.js +124963 -0
- package/dist/iclient-openlayers-es6.min.js +8 -0
- package/dist/iclient-openlayers.css +668 -0
- package/dist/iclient-openlayers.js +142946 -0
- package/dist/iclient-openlayers.min.css +8 -0
- package/dist/iclient-openlayers.min.js +8 -0
- package/index.js +9 -0
- package/mapping/BaiduMap.js +121 -0
- package/mapping/ImageSuperMapRest.js +252 -0
- package/mapping/ImageTileSuperMapRest.js +99 -0
- package/mapping/InitMap.js +150 -0
- package/mapping/SuperMapCloud.js +56 -0
- package/mapping/Tianditu.js +152 -0
- package/mapping/TileSuperMapRest.js +374 -0
- package/mapping/WebMap.js +5485 -0
- package/mapping/index.js +11 -0
- package/mapping/webmap/Util.js +176 -0
- package/mapping/webmap/config/MunicipalCenter.json +1 -0
- package/mapping/webmap/config/ProvinceCenter.json +1 -0
- package/mapping/webmap/config/SampleDataInfo.json +55 -0
- package/namespace.js +150 -0
- package/overlay/DataFlow.js +114 -0
- package/overlay/FGB.js +100 -0
- package/overlay/Graph.js +439 -0
- package/overlay/GraphMap.js +140 -0
- package/overlay/Graphic.js +588 -0
- package/overlay/HeatMap.js +450 -0
- package/overlay/Label.js +966 -0
- package/overlay/Mapv.js +149 -0
- package/overlay/Range.js +129 -0
- package/overlay/RankSymbol.js +94 -0
- package/overlay/Turf.js +299 -0
- package/overlay/Unique.js +124 -0
- package/overlay/VectorTileSuperMapRest.js +501 -0
- package/overlay/graphic/CanvasRenderer.js +177 -0
- package/overlay/graphic/CloverShape.js +133 -0
- package/overlay/graphic/Graphic.js +174 -0
- package/overlay/graphic/HitCloverShape.js +64 -0
- package/overlay/graphic/WebGLRenderer.js +356 -0
- package/overlay/graphic/index.js +9 -0
- package/overlay/index.js +21 -0
- package/overlay/mapv/MapvCanvasLayer.js +104 -0
- package/overlay/mapv/MapvLayer.js +413 -0
- package/overlay/mapv/index.js +5 -0
- package/overlay/theme/GeoFeature.js +275 -0
- package/overlay/theme/Theme.js +587 -0
- package/overlay/theme/ThemeFeature.js +46 -0
- package/overlay/theme/index.js +6 -0
- package/overlay/vectortile/DeafultCanvasStyle.js +125 -0
- package/overlay/vectortile/MapboxStyles.js +377 -0
- package/overlay/vectortile/StyleMap.js +252 -0
- package/overlay/vectortile/VectorTileStyles.js +554 -0
- package/overlay/vectortile/index.js +7 -0
- package/overlay/vectortile/olExtends.js +382 -0
- package/package.json +30 -0
- package/services/AddressMatchService.js +60 -0
- package/services/ChartService.js +97 -0
- package/services/DataFlowService.js +119 -0
- package/services/DatasetService.js +104 -0
- package/services/DatasourceService.js +76 -0
- package/services/FeatureService.js +260 -0
- package/services/FieldService.js +53 -0
- package/services/GeoprocessingService.js +157 -0
- package/services/GridCellInfosService.js +53 -0
- package/services/ImageCollectionService.js +93 -0
- package/services/ImageService.js +70 -0
- package/services/KnowledgeGraphService.js +96 -0
- package/services/LayerInfoService.js +85 -0
- package/services/MapService.js +85 -0
- package/services/MeasureService.js +77 -0
- package/services/NetworkAnalyst3DService.js +93 -0
- package/services/NetworkAnalystService.js +268 -0
- package/services/ProcessingService.js +507 -0
- package/services/QueryService.js +116 -0
- package/services/ServiceBase.js +26 -0
- package/services/SpatialAnalystService.js +466 -0
- package/services/ThemeService.js +50 -0
- package/services/TrafficTransferAnalystService.js +93 -0
- package/services/WebPrintingJobService.js +112 -0
- package/services/index.js +27 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
|
|
2
|
+
* This program are made available under the terms of the Apache License, Version 2.0
|
|
3
|
+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
|
|
4
|
+
import {
|
|
5
|
+
MapvCanvasLayer
|
|
6
|
+
} from './MapvCanvasLayer';
|
|
7
|
+
import {
|
|
8
|
+
baiduMapLayer
|
|
9
|
+
} from "mapv";
|
|
10
|
+
import PointerInteraction from 'ol/interaction/Pointer';
|
|
11
|
+
|
|
12
|
+
var BaiduMapLayer = baiduMapLayer ? baiduMapLayer.__proto__ : Function;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @class MapvLayer
|
|
16
|
+
* @classdesc MapV 图层类。MapV 是一款地理信息可视化开源库,MapV 图层可以用来展示大量地理信息数据,点、线、面的数据,每种数据有不同的展示类型,如直接打点、热力图、网格、聚合等方式展示数据。<br>
|
|
17
|
+
* 展示大量的点数据:如热力图、网格、蜂窝状、点聚合、按颜色区间、按半径大小等方式。<br>
|
|
18
|
+
* 展示大量的线数据:如普通画线、高亮叠加、热力线数据展示等方式,适合展示大量轨迹的场景。<br>
|
|
19
|
+
* 展示大量的自定义面数据:按颜色区间来展示,如展示行政区划数据。
|
|
20
|
+
* @private
|
|
21
|
+
* @param {Object} map - 地图。
|
|
22
|
+
* @param {Mapv.DataSet} [dataSet] - 数据集。
|
|
23
|
+
* @param {Object} options - 参数。
|
|
24
|
+
* @param {number} mapWidth - 地图宽度。
|
|
25
|
+
* @param {number} mapHeight - 地图高度。
|
|
26
|
+
* @param {Object} source - 资源。
|
|
27
|
+
* @param {number} options.width - 画布宽度。
|
|
28
|
+
* @param {number} options.height - 画布高度。
|
|
29
|
+
* @param {string} [options.paneName='mapPane'] - 窗口名。
|
|
30
|
+
* @param {string} [options.context] - 内容。
|
|
31
|
+
* @param {number} [options.zIndex] - 层级。
|
|
32
|
+
* @param {string} [options.mixBlendMode] - 最小混合模式。
|
|
33
|
+
|
|
34
|
+
* @extends {Mapv.BaiduMapLayer}
|
|
35
|
+
*/
|
|
36
|
+
export class MapvLayer extends BaiduMapLayer {
|
|
37
|
+
|
|
38
|
+
constructor(map, dataSet, options, mapWidth, mapHeight, source) {
|
|
39
|
+
super(map, dataSet, options);
|
|
40
|
+
this.dataSet = dataSet;
|
|
41
|
+
this.mapWidth = mapWidth;
|
|
42
|
+
this.mapHeight = mapHeight;
|
|
43
|
+
var self = this;
|
|
44
|
+
options = options || {};
|
|
45
|
+
this.source = source;
|
|
46
|
+
self.animator = null;
|
|
47
|
+
self.map = map;
|
|
48
|
+
self.init(options);
|
|
49
|
+
self.argCheck(options);
|
|
50
|
+
this.canvasLayer = new MapvCanvasLayer({
|
|
51
|
+
map: map,
|
|
52
|
+
context: this.context,
|
|
53
|
+
paneName: options.paneName,
|
|
54
|
+
mixBlendMode: options.mixBlendMode,
|
|
55
|
+
enableMassClear: options.enableMassClear,
|
|
56
|
+
zIndex: options.zIndex,
|
|
57
|
+
width: mapWidth,
|
|
58
|
+
height: mapHeight,
|
|
59
|
+
update: function update() {
|
|
60
|
+
self._canvasUpdate();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
this.clickEvent = this.clickEvent.bind(this);
|
|
64
|
+
this.mousemoveEvent = this.mousemoveEvent.bind(this);
|
|
65
|
+
map.on('movestart', this.moveStartEvent.bind(this));
|
|
66
|
+
map.on('moveend', this.moveEndEvent.bind(this));
|
|
67
|
+
map.getView().on('change:center', this.zoomEvent.bind(this));
|
|
68
|
+
map.getView().on('change:size', this.sizeEvent.bind(this));
|
|
69
|
+
map.on('pointerdrag', this.dragEvent.bind(this));
|
|
70
|
+
this.bindEvent();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @function MapvLayer.prototype.init
|
|
75
|
+
* @param {Object} options - 参数。
|
|
76
|
+
* @description 初始化参数。
|
|
77
|
+
*/
|
|
78
|
+
init(options) {
|
|
79
|
+
var self = this;
|
|
80
|
+
self.options = options;
|
|
81
|
+
this.initDataRange(options);
|
|
82
|
+
this.context = self.options.context || '2d';
|
|
83
|
+
if (self.options.zIndex) {
|
|
84
|
+
this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
|
|
85
|
+
}
|
|
86
|
+
this.initAnimator();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @function MapvLayer.prototype.clickEvent
|
|
91
|
+
* @param {Object} e - 事件参数。
|
|
92
|
+
* @description 点击事件。
|
|
93
|
+
*/
|
|
94
|
+
clickEvent(e) {
|
|
95
|
+
var pixel = e.pixel;
|
|
96
|
+
super.clickEvent({
|
|
97
|
+
x: pixel[0] + this.offset[0],
|
|
98
|
+
y: pixel[1] + this.offset[1]
|
|
99
|
+
}, e);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @function MapvLayer.prototype.mousemoveEvent
|
|
104
|
+
* @param {Object} e - 事件参数。
|
|
105
|
+
* @description 鼠标移动事件。
|
|
106
|
+
*/
|
|
107
|
+
mousemoveEvent(e) {
|
|
108
|
+
var pixel = e.pixel;
|
|
109
|
+
super.mousemoveEvent({
|
|
110
|
+
x: pixel[0],
|
|
111
|
+
y: pixel[1]
|
|
112
|
+
}, e);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @function MapvLayer.prototype.dragEvent
|
|
117
|
+
* @description 鼠标拖动事件。
|
|
118
|
+
*/
|
|
119
|
+
dragEvent() {
|
|
120
|
+
this.clear(this.getContext());
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @function MapvLayer.prototype.zoomEvent
|
|
125
|
+
* @description 缩放事件。
|
|
126
|
+
*/
|
|
127
|
+
zoomEvent() {
|
|
128
|
+
this.clear(this.getContext());
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @function MapvLayer.prototype.sizeEvent
|
|
132
|
+
* @description 地图窗口大小发生变化时触发。
|
|
133
|
+
*/
|
|
134
|
+
sizeEvent() {
|
|
135
|
+
this.canvasLayer.resize();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @function MapvLayer.prototype.moveStartEvent
|
|
141
|
+
* @description 开始移动事件。
|
|
142
|
+
*/
|
|
143
|
+
moveStartEvent() {
|
|
144
|
+
var animationOptions = this.options.animation;
|
|
145
|
+
if (this.isEnabledTime() && this.animator) {
|
|
146
|
+
this.steps.step = animationOptions.stepsRange.start;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @function MapvLayer.prototype.moveEndEvent
|
|
152
|
+
* @description 结束移动事件。
|
|
153
|
+
*/
|
|
154
|
+
moveEndEvent() {
|
|
155
|
+
this.canvasLayer.draw();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @function MapvLayer.prototype.bindEvent
|
|
160
|
+
* @description 绑定事件。
|
|
161
|
+
*/
|
|
162
|
+
bindEvent() {
|
|
163
|
+
var me = this;
|
|
164
|
+
var map = me.map;
|
|
165
|
+
if (me.options.methods) {
|
|
166
|
+
if (me.options.methods.click) {
|
|
167
|
+
map.on('click', me.clickEvent);
|
|
168
|
+
}
|
|
169
|
+
if (me.options.methods.mousemove) {
|
|
170
|
+
me.pointerInteraction = new PointerInteraction();
|
|
171
|
+
me.pointerInteraction.handleMoveEvent_ = function (event) {
|
|
172
|
+
me.mousemoveEvent(event);
|
|
173
|
+
};
|
|
174
|
+
map.addInteraction(me.pointerInteraction);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @function MapvLayer.prototype.unbindEvent
|
|
181
|
+
* @description 解除绑定事件。
|
|
182
|
+
*/
|
|
183
|
+
unbindEvent() {
|
|
184
|
+
var map = this.map;
|
|
185
|
+
if (this.options.methods) {
|
|
186
|
+
if (this.options.methods.click) {
|
|
187
|
+
map.un('click', this.clickEvent);
|
|
188
|
+
}
|
|
189
|
+
if (this.options.methods.mousemove) {
|
|
190
|
+
map.removeInteraction(this.pointerInteraction)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @function MapvLayer.prototype.addData
|
|
197
|
+
* @description 添加数据。
|
|
198
|
+
* @param {Object} data - 待添加的数据。
|
|
199
|
+
* @param {Object} options - 待添加的数据信息。
|
|
200
|
+
*/
|
|
201
|
+
addData(data, options) {
|
|
202
|
+
var _data = data;
|
|
203
|
+
if (data && data.get) {
|
|
204
|
+
_data = data.get();
|
|
205
|
+
}
|
|
206
|
+
this.dataSet.add(_data);
|
|
207
|
+
this.update({
|
|
208
|
+
options: options
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @function MapvLayer.prototype.update
|
|
214
|
+
* @description 更新图层。
|
|
215
|
+
* @param {Object} opt - 待更新的数据。
|
|
216
|
+
* @param {Object} opt.data - mapv 数据集。
|
|
217
|
+
*/
|
|
218
|
+
update(opt) {
|
|
219
|
+
var update = opt || {};
|
|
220
|
+
var _data = update.data;
|
|
221
|
+
if (_data && _data.get) {
|
|
222
|
+
_data = _data.get();
|
|
223
|
+
}
|
|
224
|
+
if (_data != undefined) {
|
|
225
|
+
this.dataSet.set(_data);
|
|
226
|
+
}
|
|
227
|
+
super.update({
|
|
228
|
+
options: update.options
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
draw() {
|
|
233
|
+
this.canvasLayer.draw();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @function MapvLayer.prototype.getData
|
|
238
|
+
* @description 获取数据。
|
|
239
|
+
*/
|
|
240
|
+
getData() {
|
|
241
|
+
return this.dataSet;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @function MapvLayer.prototype.removeData
|
|
246
|
+
* @description 删除符合过滤条件的数据。
|
|
247
|
+
* @param {function} filter - 过滤条件。条件参数为数据项,返回值为 true,表示删除该元素;否则表示不删除。
|
|
248
|
+
*/
|
|
249
|
+
removeData(filter) {
|
|
250
|
+
if (!this.dataSet) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
var newData = this.dataSet.get({
|
|
254
|
+
filter: function (data) {
|
|
255
|
+
return (filter != null && typeof filter === "function") ? !filter(data) : true;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
this.dataSet.set(newData);
|
|
259
|
+
this.update({
|
|
260
|
+
options: null
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @function MapvLayer.prototype.clearData
|
|
266
|
+
* @description 清除数据。
|
|
267
|
+
*/
|
|
268
|
+
clearData() {
|
|
269
|
+
this.dataSet && this.dataSet.clear();
|
|
270
|
+
this.update({
|
|
271
|
+
options: null
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
_canvasUpdate(time) {
|
|
276
|
+
if (!this.canvasLayer) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
var self = this;
|
|
280
|
+
var animationOptions = self.options.animation;
|
|
281
|
+
var map = self.map;
|
|
282
|
+
var context = self.canvasLayer.canvas.getContext(self.context);
|
|
283
|
+
if (self.isEnabledTime()) {
|
|
284
|
+
if (time === undefined) {
|
|
285
|
+
self.clear(context);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (!self.context || self.context === '2d') {
|
|
289
|
+
context.save();
|
|
290
|
+
context.globalCompositeOperation = 'destination-out';
|
|
291
|
+
context.fillStyle = 'rgba(0, 0, 0, .1)';
|
|
292
|
+
context.fillRect(0, 0, context.canvas.width, context.canvas.height);
|
|
293
|
+
context.restore();
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
this.clear(context);
|
|
297
|
+
}
|
|
298
|
+
if (!self.context || self.context === '2d') {
|
|
299
|
+
for (var key in self.options) {
|
|
300
|
+
context[key] = self.options[key];
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
context.clear(context.COLOR_BUFFER_BIT);
|
|
304
|
+
}
|
|
305
|
+
var ext = map.getView().calculateExtent();
|
|
306
|
+
var topLeftPx = map.getPixelFromCoordinate([ext[0], ext[3]]);
|
|
307
|
+
|
|
308
|
+
self._mapCenter = map.getView().getCenter();
|
|
309
|
+
self._mapCenterPx = map.getPixelFromCoordinate(self._mapCenter);
|
|
310
|
+
self._reselutions = map.getView().getResolution();
|
|
311
|
+
self._rotation = -map.getView().getRotation();
|
|
312
|
+
var zoomUnit = self._reselutions;
|
|
313
|
+
var scaleRatio = 1;
|
|
314
|
+
if (this.context != '2d') {
|
|
315
|
+
var global$2 = typeof window === 'undefined' ? {} : window;
|
|
316
|
+
var devicePixelRatio = global$2.devicePixelRatio || 1;
|
|
317
|
+
scaleRatio = devicePixelRatio;
|
|
318
|
+
}
|
|
319
|
+
var dataGetOptions = {
|
|
320
|
+
transferCoordinate: function (coordinate) {
|
|
321
|
+
var x = (coordinate[0] - self._mapCenter[0]) / self._reselutions,
|
|
322
|
+
y = (self._mapCenter[1] - coordinate[1]) / self._reselutions;
|
|
323
|
+
var scaledP = [x + self._mapCenterPx[0], y + self._mapCenterPx[1]];
|
|
324
|
+
scaledP = scale(scaledP, self._mapCenterPx, 1);
|
|
325
|
+
/*//有旋转量的时候处理旋转
|
|
326
|
+
if (self._rotation !== 0) {
|
|
327
|
+
var rotatedP = rotate(scaledP, self._rotation, self._mapCenterPx);
|
|
328
|
+
return [rotatedP[0] + self.offset[0], rotatedP[1] + self.offset[1]];
|
|
329
|
+
}
|
|
330
|
+
//处理放大或缩小级别*/
|
|
331
|
+
return [(scaledP[0] + self.offset[0]) * scaleRatio, (scaledP[1] + self.offset[1]) * scaleRatio];
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// //获取某像素坐标点pixelP绕中心center逆时针旋转rotation弧度后的像素点坐标。
|
|
336
|
+
// function rotate(pixelP, rotation, center) {
|
|
337
|
+
// var x = Math.cos(rotation) * (pixelP[0] - center[0]) - Math.sin(rotation) * (pixelP[1] - center[1]) + center[0];
|
|
338
|
+
// var y = Math.sin(rotation) * (pixelP[0] - center[0]) + Math.cos(rotation) * (pixelP[1] - center[1]) + center[1];
|
|
339
|
+
// return [x, y];
|
|
340
|
+
// }
|
|
341
|
+
|
|
342
|
+
//获取某像素坐标点pixelP相对于中心center进行缩放scaleRatio倍后的像素点坐标。
|
|
343
|
+
function scale(pixelP, center, scaleRatio) {
|
|
344
|
+
var x = (pixelP[0] - center[0]) * scaleRatio + center[0];
|
|
345
|
+
var y = (pixelP[1] - center[1]) * scaleRatio + center[1];
|
|
346
|
+
return [x, y];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (time !== undefined) {
|
|
350
|
+
dataGetOptions.filter = function (item) {
|
|
351
|
+
var trails = animationOptions.trails || 10;
|
|
352
|
+
return (time && item.time > (time - trails) && item.time < time);
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
if (self.isEnabledTime() && !self.notFirst) {
|
|
356
|
+
self.canvasLayer.resize(self.mapWidth, self.mapHeight);
|
|
357
|
+
self.notFirst = true;
|
|
358
|
+
}
|
|
359
|
+
var data = self.dataSet.get(dataGetOptions);
|
|
360
|
+
self.processData(data);
|
|
361
|
+
// 兼容unit为'm'的情况
|
|
362
|
+
if (self.options.unit === 'm') {
|
|
363
|
+
if (self.options.size) {
|
|
364
|
+
self.options._size = self.options.size / zoomUnit;
|
|
365
|
+
}
|
|
366
|
+
if (self.options.width) {
|
|
367
|
+
self.options._width = self.options.width / zoomUnit;
|
|
368
|
+
}
|
|
369
|
+
if (self.options.height) {
|
|
370
|
+
self.options._height = self.options.height / zoomUnit;
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
self.options._size = self.options.size;
|
|
374
|
+
self.options._height = self.options.height;
|
|
375
|
+
self.options._width = self.options.width;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
var pixel = map.getPixelFromCoordinate([0, 0]);
|
|
379
|
+
pixel = [pixel[0] - topLeftPx[0], pixel[1] - topLeftPx[1]];
|
|
380
|
+
this.drawContext(context, data, self.options, {
|
|
381
|
+
x: pixel[0],
|
|
382
|
+
y: pixel[1]
|
|
383
|
+
});
|
|
384
|
+
if (self.isEnabledTime()) {
|
|
385
|
+
this.source.changed();
|
|
386
|
+
}
|
|
387
|
+
self.options.updateCallback && self.options.updateCallback(time);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
isEnabledTime() {
|
|
392
|
+
var animationOptions = this.options.animation;
|
|
393
|
+
return animationOptions && !(animationOptions.enabled === false);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
argCheck(options) {
|
|
398
|
+
if (options.draw === 'heatmap') {
|
|
399
|
+
if (options.strokeStyle) {
|
|
400
|
+
console.warn('[heatmap] options.strokeStyle is discard, pleause use options.strength [eg: options.strength = 0.1]');
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
getContext() {
|
|
406
|
+
return this.canvasLayer.canvas.getContext(this.context);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
clear(context) {
|
|
411
|
+
context && context.clearRect && context.clearRect(0, 0, context.canvas.width, context.canvas.height);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
|
|
2
|
+
* This program are made available under the terms of the Apache License, Version 2.0
|
|
3
|
+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
|
|
4
|
+
export {MapvCanvasLayer} from './MapvCanvasLayer';
|
|
5
|
+
export {MapvLayer} from './MapvLayer';
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
|
|
2
|
+
* This program are made available under the terms of the Apache License, Version 2.0
|
|
3
|
+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
|
|
4
|
+
import { Bounds } from '@supermapgis/iclient-common/commontypes/Bounds';
|
|
5
|
+
import { ShapeFactory } from '@supermapgis/iclient-common/overlay/feature/ShapeFactory';
|
|
6
|
+
import { ThemeVector as Vector} from '@supermapgis/iclient-common/overlay/ThemeVector';
|
|
7
|
+
import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
|
|
8
|
+
import {Theme} from './Theme';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @class GeoFeature
|
|
12
|
+
* @browsernamespace ol.source
|
|
13
|
+
* @category Visualization Theme
|
|
14
|
+
* @classdesc 地理几何专题要素型专题图层基类。此类型专题图的专题要素形状就是由 feature.geometry 决定。不建议直接实例化调用此类。
|
|
15
|
+
* @param {string} name - 图层名称。
|
|
16
|
+
* @param {Object} opt_options - 参数。
|
|
17
|
+
* @param {ol.Map} opt_options.map - 当前 OpenLayers Map 对象。
|
|
18
|
+
* @param {string} [opt_options.id] - 专题图层 ID。默认使用 CommonUtil.createUniqueID("themeLayer_") 创建专题图层 ID。
|
|
19
|
+
* @param {number} [opt_options.opacity=1] - 图层不透明度。
|
|
20
|
+
* @param {string} [opt_options.logo] - Logo(OpenLayers 5.0.0 及更高版本不再支持此参数)。
|
|
21
|
+
* @param {ol.proj.Projection} [opt_options.projection] - 投影信息。
|
|
22
|
+
* @param {number} [opt_options.ratio=1.5] - 视图比,1 表示画布是地图视口的大小,2 表示地图视口的宽度和高度的两倍,依此类推。必须是 1 或更高。
|
|
23
|
+
* @param {Array} [opt_options.resolutions] - 分辨率数组。
|
|
24
|
+
* @param {ol.source.State} [opt_options.state] - 资源状态。
|
|
25
|
+
* @param {Object} [opt_options.style] - 专题图样式。
|
|
26
|
+
* @param {Object} [opt_options.styleGroups] - 各专题类型样式组。
|
|
27
|
+
* @param {boolean} [opt_options.isHoverAble=false] - 是否开启 hover 事件。
|
|
28
|
+
* @param {Object} [opt_options.highlightStyle] - 开启 hover 事件后,触发的样式风格。
|
|
29
|
+
* @param {(string|Object)} [opt_options.attributions='Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>'] - 版权描述信息。
|
|
30
|
+
* @extends {Theme}
|
|
31
|
+
* @usage
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export class GeoFeature extends Theme {
|
|
35
|
+
|
|
36
|
+
constructor(name, opt_options) {
|
|
37
|
+
super(name, opt_options);
|
|
38
|
+
this.cache = opt_options.cache || {};
|
|
39
|
+
this.cacheFields = opt_options.cacheFields || [];
|
|
40
|
+
this.style = opt_options.style || {};
|
|
41
|
+
this.maxCacheCount = opt_options.maxCacheCount || 0;
|
|
42
|
+
this.isCustomSetMaxCacheCount = opt_options.isCustomSetMaxCacheCount === undefined ? false : opt_options.isCustomSetMaxCacheCount;
|
|
43
|
+
this.nodesClipPixel = opt_options.nodesClipPixel || 2;
|
|
44
|
+
this.isHoverAble = opt_options.isHoverAble === undefined ? false : opt_options.isHoverAble;
|
|
45
|
+
this.isMultiHover = opt_options.isMultiHover === undefined ? false : opt_options.isMultiHover;
|
|
46
|
+
this.isClickAble = opt_options.isClickAble === undefined ? true : opt_options.isClickAble;
|
|
47
|
+
this.highlightStyle = opt_options.highlightStyle || null;
|
|
48
|
+
this.isAllowFeatureStyle = opt_options.isAllowFeatureStyle === undefined ? false : opt_options.isAllowFeatureStyle;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @function GeoFeature.prototype.destroy
|
|
53
|
+
* @description 释放资源,将引用资源的属性置空。
|
|
54
|
+
*/
|
|
55
|
+
destroy() {
|
|
56
|
+
this.maxCacheCount = null;
|
|
57
|
+
this.isCustomSetMaxCacheCount = null;
|
|
58
|
+
this.nodesClipPixel = null;
|
|
59
|
+
this.isHoverAble = null;
|
|
60
|
+
this.isMultiHover = null;
|
|
61
|
+
this.isClickAble = null;
|
|
62
|
+
this.cache = null;
|
|
63
|
+
this.cacheFields = null;
|
|
64
|
+
this.style = null;
|
|
65
|
+
this.highlightStyle = null;
|
|
66
|
+
this.isAllowFeatureStyle = null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @function GeoFeature.prototype.addFeatures
|
|
71
|
+
* @description 添加要素。
|
|
72
|
+
* @param {(Array.<ThemeFeature>|Array.<GeoJSONObject>|Array.<ol.Feature>|ThemeFeature|GeoJSONObject|ol.Feature)} features - 要素对象。
|
|
73
|
+
*/
|
|
74
|
+
addFeatures(features) {
|
|
75
|
+
this.dispatchEvent({type: 'beforefeaturesadded', value: {features: features}});
|
|
76
|
+
//转换 features 形式
|
|
77
|
+
this.features = this.toiClientFeature(features);
|
|
78
|
+
if (!this.isCustomSetMaxCacheCount) {
|
|
79
|
+
this.maxCacheCount = this.features.length * 5;
|
|
80
|
+
}
|
|
81
|
+
//绘制专题要素
|
|
82
|
+
if (this.renderer) {
|
|
83
|
+
this.changed();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @function GeoFeature.prototype.removeFeatures
|
|
89
|
+
* @description 从专题图中删除要素。这个函数删除所有传递进来的矢量要素。
|
|
90
|
+
* @param {(Array.<FeatureVector>|FeatureVector|Function)} features - 待删除的要素对象或用于过滤的回调函数。
|
|
91
|
+
*/
|
|
92
|
+
removeFeatures(features) { // eslint-disable-line no-unused-vars
|
|
93
|
+
this.clearCache();
|
|
94
|
+
Theme.prototype.removeFeatures.call(this, features);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @function GeoFeature.prototype.removeAllFeatures
|
|
99
|
+
* @description 清除当前图层所有的矢量要素。
|
|
100
|
+
*/
|
|
101
|
+
removeAllFeatures() {
|
|
102
|
+
this.clearCache();
|
|
103
|
+
Theme.prototype.removeAllFeatures.apply(this, arguments);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @function GeoFeature.prototype.redrawThematicFeatures
|
|
108
|
+
* @description 重绘所有专题要素。
|
|
109
|
+
* @param {Object} extent - 视图范围数据。
|
|
110
|
+
*/
|
|
111
|
+
redrawThematicFeatures(extent) {
|
|
112
|
+
//获取高亮专题要素对应的用户 id
|
|
113
|
+
var hoverone = this.renderer.getHoverOne();
|
|
114
|
+
var hoverFid = null;
|
|
115
|
+
if (hoverone && hoverone.refDataID) {
|
|
116
|
+
hoverFid = hoverone.refDataID;
|
|
117
|
+
}
|
|
118
|
+
//清除当前所有可视元素
|
|
119
|
+
this.renderer.clearAll();
|
|
120
|
+
|
|
121
|
+
var features = this.features;
|
|
122
|
+
var cache = this.cache;
|
|
123
|
+
var cacheFields = this.cacheFields;
|
|
124
|
+
var cmZoom = this.map.getView().getZoom();
|
|
125
|
+
|
|
126
|
+
var maxCC = this.maxCacheCount;
|
|
127
|
+
|
|
128
|
+
for (var i = 0, len = features.length; i < len; i++) {
|
|
129
|
+
var feature = features[i];
|
|
130
|
+
if (!feature.geometry) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
var feaBounds = feature.geometry.getBounds();
|
|
134
|
+
|
|
135
|
+
//剔除当前视图(地理)范围以外的数据
|
|
136
|
+
if (extent) {
|
|
137
|
+
var bounds = new Bounds(extent[0], extent[1], extent[2], extent[3]);
|
|
138
|
+
if (!bounds.intersectsBounds(feaBounds)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//缓存字段
|
|
144
|
+
var fields = feature.id + "_zoom_" + cmZoom.toString();
|
|
145
|
+
|
|
146
|
+
var thematicFeature;
|
|
147
|
+
|
|
148
|
+
//判断专题要素缓存是否存在
|
|
149
|
+
if (cache[fields]) {
|
|
150
|
+
cache[fields].updateAndAddShapes();
|
|
151
|
+
} else {
|
|
152
|
+
//如果专题要素缓存不存在,创建专题要素
|
|
153
|
+
thematicFeature = this.createThematicFeature(features[i]);
|
|
154
|
+
|
|
155
|
+
//检查 thematicFeature 是否有可视化图形
|
|
156
|
+
if (thematicFeature.getShapesCount() < 1) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//加入缓存
|
|
161
|
+
cache[fields] = thematicFeature;
|
|
162
|
+
cacheFields.push(fields);
|
|
163
|
+
|
|
164
|
+
//缓存数量限制
|
|
165
|
+
if (cacheFields.length > maxCC) {
|
|
166
|
+
var fieldsTemp = cacheFields[0];
|
|
167
|
+
cacheFields.splice(0, 1);
|
|
168
|
+
delete cache[fieldsTemp];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
this.renderer.render();
|
|
174
|
+
|
|
175
|
+
//地图漫游后,重新高亮图形
|
|
176
|
+
if (hoverFid && this.isHoverAble && this.isMultiHover) {
|
|
177
|
+
var hShapes = this.getShapesByFeatureID(hoverFid);
|
|
178
|
+
this.renderer.updateHoverShapes(hShapes);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @function GeoFeature.prototype.createThematicFeature
|
|
184
|
+
* @description 创建专题要素。
|
|
185
|
+
* @param {Object} feature - 要素对象。
|
|
186
|
+
* @returns {Array.<FeatureVector>} 返回矢量要素。
|
|
187
|
+
*/
|
|
188
|
+
createThematicFeature(feature) {
|
|
189
|
+
var style = CommonUtil.copyAttributesWithClip(this.style);
|
|
190
|
+
if (feature.style && this.isAllowFeatureStyle === true) {
|
|
191
|
+
style = CommonUtil.copyAttributesWithClip(feature.style);
|
|
192
|
+
}
|
|
193
|
+
//创建专题要素时的可选参数
|
|
194
|
+
var options = {};
|
|
195
|
+
options.nodesClipPixel = this.nodesClipPixel;
|
|
196
|
+
options.isHoverAble = this.isHoverAble;
|
|
197
|
+
options.isMultiHover = this.isMultiHover;
|
|
198
|
+
options.isClickAble = this.isClickAble;
|
|
199
|
+
options.highlightStyle = ShapeFactory.transformStyle(this.highlightStyle);
|
|
200
|
+
//将数据转为专题要素(Vector)
|
|
201
|
+
var thematicFeature = new Vector(feature, this, ShapeFactory.transformStyle(style), options);
|
|
202
|
+
//直接添加图形到渲染器
|
|
203
|
+
for (var m = 0; m < thematicFeature.shapes.length; m++) {
|
|
204
|
+
this.renderer.addShape(thematicFeature.shapes[m]);
|
|
205
|
+
}
|
|
206
|
+
return thematicFeature;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
canvasFunctionInternal_(extent, resolution, pixelRatio, size, projection) { // eslint-disable-line no-unused-vars
|
|
210
|
+
return Theme.prototype.canvasFunctionInternal_.apply(this, arguments);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @function GeoFeature.prototype.clearCache
|
|
215
|
+
* @description 清除缓存。
|
|
216
|
+
*/
|
|
217
|
+
clearCache() {
|
|
218
|
+
this.cache = {};
|
|
219
|
+
this.cacheFields = [];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* @function GeoFeature.prototype.clear
|
|
224
|
+
* @description 清除的内容包括数据(features)、专题要素、缓存。
|
|
225
|
+
*/
|
|
226
|
+
clear() {
|
|
227
|
+
this.renderer.clearAll();
|
|
228
|
+
this.renderer.refresh();
|
|
229
|
+
this.removeAllFeatures();
|
|
230
|
+
this.clearCache();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @function GeoFeature.prototype.getCacheCount
|
|
235
|
+
* @description 获取当前缓存数量。
|
|
236
|
+
* @returns {number} 返回当前缓存数量。
|
|
237
|
+
*/
|
|
238
|
+
getCacheCount() {
|
|
239
|
+
return this.cacheFields.length;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @function GeoFeature.prototype.setMaxCacheCount
|
|
244
|
+
* @param {number} cacheCount - 缓存总数。
|
|
245
|
+
* @description 设置最大缓存条数。
|
|
246
|
+
*/
|
|
247
|
+
setMaxCacheCount(cacheCount) {
|
|
248
|
+
if (!isNaN(cacheCount)) {
|
|
249
|
+
this.maxCacheCount = cacheCount;
|
|
250
|
+
this.isCustomSetMaxCacheCount = true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @function GeoFeature.prototype.getShapesByFeatureID
|
|
256
|
+
* @param {number} featureID - 要素 ID。
|
|
257
|
+
* @description 通过要素 ID 获取要素关联的所有图形。如果不传入此参数,函数将返回所有图形。
|
|
258
|
+
* @returns {Array} 返回图形数组。
|
|
259
|
+
*/
|
|
260
|
+
getShapesByFeatureID(featureID) {
|
|
261
|
+
var list = [];
|
|
262
|
+
var shapeList = this.renderer.getAllShapes();
|
|
263
|
+
if (!featureID) {
|
|
264
|
+
return shapeList
|
|
265
|
+
}
|
|
266
|
+
for (var i = 0, len = shapeList.length; i < len; i++) {
|
|
267
|
+
var si = shapeList[i];
|
|
268
|
+
if (si.refDataID && featureID === si.refDataID) {
|
|
269
|
+
list.push(si);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return list;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
}
|