@vtx/map 1.1.0 → 1.1.4

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.
@@ -0,0 +1,3255 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
+
9
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
10
+
11
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
12
+
13
+ var _react = require('react');
14
+
15
+ var _react2 = _interopRequireDefault(_react);
16
+
17
+ require('./Map.css');
18
+
19
+ var _default = require('../../default');
20
+
21
+ var _default2 = _interopRequireDefault(_default);
22
+
23
+ var _MapToolFunction = require('../MapToolFunction');
24
+
25
+ var _immutable = require('immutable');
26
+
27
+ var _immutable2 = _interopRequireDefault(_immutable);
28
+
29
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
+
31
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
32
+
33
+ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
34
+
35
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
36
+
37
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
38
+
39
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
40
+
41
+ //公共地址配置
42
+
43
+
44
+ var Set = _immutable2.default.Set;
45
+
46
+ var OlMap = function (_React$Component) {
47
+ _inherits(OlMap, _React$Component);
48
+
49
+ function OlMap(props) {
50
+ _classCallCheck(this, OlMap);
51
+
52
+ var _this = _possibleConstructorReturn(this, (OlMap.__proto__ || Object.getPrototypeOf(OlMap)).call(this, props));
53
+
54
+ _this.zIndexGraphics = []; //需要放在最后的图元,zoom和pan时刷新dom到最后
55
+ _this.htmlPointsId = 'vtx_gmap_html_points'; //html点位容器id class管理
56
+ _this.pointCollectionId = 'vtx_gmap_html_pointCollection'; //海量点canvas点位容器id class管理
57
+ _this.Label = {}; //所有label 集合
58
+ _this.labelLayer = { x: 0, y: 0 }; //label图层 位置管理
59
+ _this.viewer = null;
60
+ _this.GM = new _MapToolFunction.graphicManage(); //初始化 图元管理方法
61
+ _this.getPolygonArea = _MapToolFunction.getPolygonArea;
62
+ _this.layer = null; //保存地图图层数据
63
+ _this.loadTimer = null; //初始化地图 load时延缓数据处理
64
+ _this.animTimer = {}; //点位跳动动画 定时集合
65
+ _this.animCount = {}; //点位跳动动画 定时计数
66
+ _this.moveToTimer = null; //moveTo时间对象
67
+ _this.drawToolbar = null; //地图绘制对象即interaction
68
+ _this.drawParam = {}; //缓存 绘制的数据
69
+ _this.editToolbar = null; //编辑对象
70
+ _this.editId = ''; //当前编辑的图元id
71
+ _this.drawSource = null;
72
+ _this.drawVector = null;
73
+ // 图元绘制保存
74
+ _this.drawInfo = {
75
+ sketch: null,
76
+ listener: null
77
+ };
78
+ _this.mouseNowPosition = { x: 0, y: 0, px: 0, py: 0, isCount: false };
79
+ _this.heatmap = null; //热力图对象
80
+ _this.clusterMarkers = []; //聚合点位id数组
81
+ _this.clusterPs = []; //聚合集合点
82
+ _this.clusterPt = []; //地图中聚合点集合
83
+ _this.morepoints = []; //海量点集合
84
+ _this.areaRestriction = null; //区域限制数据
85
+ _this.movePoints = [];
86
+ //是否绘制测距
87
+ _this.rangingTool = {
88
+ isRanging: false, //是否开启状态
89
+ line: {}, //线
90
+ points: [], //点
91
+ distance: 0, //测距长度
92
+ mapRangingTool: null //测距回调
93
+ };
94
+ _this.rangingTools = {}; //测距点线缓存
95
+ _this.rangingInfo = {
96
+ sketch: null,
97
+ helpTooltipElement: null,
98
+ helpTooltip: null,
99
+ deleteContent: null,
100
+ measureTooltipElement: null,
101
+ measureTooltip: null,
102
+ deleteToolTip: null,
103
+ continuePolygonMsg: '点击继续绘制图形',
104
+ continueLineMsg: '点击继续绘制线',
105
+ listener: null
106
+ };
107
+ _this.state = {
108
+ gis: null, //地图对象
109
+ mapId: props.mapId,
110
+ mapCreated: false,
111
+ pointIds: [], //地图上点的ids
112
+ lineIds: [], //地图上线的ids
113
+ polygonIds: [], //地图上面的ids
114
+ circleIds: [], //地图上圆的ids
115
+ editGraphic: '', //当前编辑完后图元所有数据
116
+ boundaryInfo: [], //当前画出的边界线的id和区域名
117
+ drawIds: {
118
+ //绘制工具id集合
119
+ point: [],
120
+ polyline: [],
121
+ polygon: [],
122
+ circle: [],
123
+ rectangle: []
124
+ }
125
+ };
126
+ _this.loadMapJs();
127
+ return _this;
128
+ }
129
+ // 引入ol样式
130
+
131
+
132
+ _createClass(OlMap, [{
133
+ key: 'loadMapJs',
134
+ value: function loadMapJs() {
135
+ this.loadMapComplete = new Promise(function (resolve, reject) {
136
+ if (window.OlMap) {
137
+ resolve(window.OlMap);
138
+ } else {
139
+ $.getScript(_default2.default.openlayerServerURL + '/ol.js', function () {
140
+ var PointCollection = new Promise(function (resolve, reject) {
141
+ $.getScript(_default2.default.mapServerURL + '/GPointCollection.js', function () {
142
+ resolve();
143
+ });
144
+ });
145
+ Promise.all([PointCollection]).then(function () {
146
+ resolve(window.OlMap);
147
+ });
148
+ });
149
+ $.getScript(_default2.default.openlayerServerURL + '/bd09.js');
150
+ $.getScript(_default2.default.openlayerServerURL + '/olScreen.js');
151
+ $('<link>').attr({
152
+ rel: 'stylesheet',
153
+ type: 'text/css',
154
+ href: _default2.default.openlayerServerURL + '/ol.css'
155
+ }).appendTo('head');
156
+ }
157
+ });
158
+ }
159
+ // 初始化地圖
160
+
161
+ }, {
162
+ key: 'init',
163
+ value: function init() {
164
+ var t = this;
165
+ // 创建地图
166
+ t.createMap();
167
+ t.drawSource = new ol.source.Vector({ wrapX: false });
168
+ t.drawVector = new ol.layer.Vector({ source: t.drawSource });
169
+ var initData = function initData() {
170
+ var _t$props = t.props,
171
+ mapPoints = _t$props.mapPoints,
172
+ mapLines = _t$props.mapLines,
173
+ mapPolygons = _t$props.mapPolygons,
174
+ mapCircles = _t$props.mapCircles,
175
+ mapVisiblePoints = _t$props.mapVisiblePoints,
176
+ mapCluster = _t$props.mapCluster,
177
+ mapPointCollection = _t$props.mapPointCollection,
178
+ areaRestriction = _t$props.areaRestriction,
179
+ heatMapData = _t$props.heatMapData;
180
+ // 初始化中心点
181
+
182
+ t.setCenter();
183
+ // 添加点
184
+ if (mapPoints instanceof Array) {
185
+ t.addPoint(mapPoints);
186
+ }
187
+ //添加线
188
+ if (mapLines instanceof Array) {
189
+ t.addLine(mapLines);
190
+ }
191
+ //添加面
192
+ if (mapPolygons instanceof Array) {
193
+ t.addPolygon(mapPolygons);
194
+ }
195
+ //添加圆
196
+ if (mapCircles instanceof Array) {
197
+ t.addCircle(mapCircles);
198
+ }
199
+ //是否设置比例尺
200
+ if (t.props.showControl) {
201
+ t.showControl();
202
+ }
203
+ // 画热力图
204
+ if (heatMapData) {
205
+ t.heatMapOverlay(heatMapData);
206
+ }
207
+ //设置点聚合
208
+ if (mapCluster instanceof Array) {
209
+ t.cluster(mapCluster);
210
+ }
211
+ /*设置指定图元展示*/
212
+ if (mapVisiblePoints) {
213
+ t.setVisiblePoints(mapVisiblePoints);
214
+ }
215
+ //添加海量点
216
+ if (mapPointCollection instanceof Array) {
217
+ t.addPointCollection(mapPointCollection);
218
+ }
219
+ //设置区域限制
220
+ if (areaRestriction && !!areaRestriction[0] && !!areaRestriction[1]) {
221
+ t.setAreaRestriction(areaRestriction);
222
+ }
223
+ t.setState({
224
+ mapCreated: true
225
+ });
226
+ };
227
+ var event = function event(e, status) {
228
+ var gis = t.state.gis;
229
+
230
+ var overall_feature = null; //鼠标移入事件时记录当前的feature,为鼠标移出要素时保存操作的要素对象
231
+ var dragAddMoveFlag = false; //记录地图拖拽和移动事件
232
+ // 地图开始加载时
233
+ gis.on('loadstart', function () {
234
+ gis.getTargetElement().classList.add('spinner');
235
+ });
236
+ // 地图加载结束时
237
+ gis.on('loadend', function () {
238
+ gis.getTargetElement().classList.remove('spinner');
239
+ });
240
+ // 地图双击事件
241
+ gis.on('dbclick', function (evt) {});
242
+ // 地图点击事件
243
+ gis.on('singleclick', function (evt) {
244
+ var feature = gis.forEachFeatureAtPixel(evt.pixel, function (feature) {
245
+ return feature;
246
+ });
247
+ if (feature) {
248
+ var target = feature.getProperties();
249
+ // top: e.clientY,//当前点所在的位置(屏幕)
250
+ // left: e.clientX,
251
+ t.clickGraphic(target.id, evt);
252
+ } else {
253
+ t.clickMap(evt);
254
+ }
255
+ });
256
+ // 鼠标移动事件 - 当鼠标指向要素时改变光标状态
257
+ gis.on('pointermove', function (evt) {
258
+ var pixel = gis.getEventPixel(evt.originalEvent);
259
+ var hit = gis.hasFeatureAtPixel(pixel);
260
+ gis.getTargetElement().style.cursor = hit ? 'pointer' : 'default';
261
+ // 获取到当前鼠标移动下的feature
262
+ var feature = gis.forEachFeatureAtPixel(pixel, function (feature, layer) {
263
+ return feature;
264
+ });
265
+ if (feature) {
266
+ overall_feature = feature;
267
+ var values = feature.getProperties();
268
+ t.mouseOverGraphic(values.id, evt);
269
+ } else {
270
+ if (overall_feature) {
271
+ overall_feature.dispatchEvent({ type: 'mousein', event: evt });
272
+ var _values = overall_feature.getProperties();
273
+ t.mouseOutGraphic(_values.id, evt);
274
+ overall_feature = null;
275
+ }
276
+ }
277
+ });
278
+ // 鼠标拖拽事件 - 拖拽开始即是地图移动开始
279
+ gis.on('pointerdrag', function (evt) {
280
+ dragAddMoveFlag = true;
281
+ t.dragMapStart(evt);
282
+ t.moveStart(evt);
283
+ });
284
+ var zoom = 0;
285
+ // 地图移动事件 - 移动结束即是拖拽事件结束 也是地图缩放事件(无开始和结束事件)的监听
286
+ gis.on('moveend', function (evt) {
287
+ t.dragMapEnd(evt);
288
+ t.moveEnd(evt);
289
+ t.zoomStart(evt);
290
+ setTimeout(function () {
291
+ t.zoomEnd(evt);
292
+ }, 300);
293
+ dragAddMoveFlag = false;
294
+ });
295
+ // gis.getViewport().addEventListener('mouseout', function () {
296
+ // helpTooltipElement.classList.add('hidden');
297
+ // });
298
+ };
299
+ event();
300
+ t.setCenter(t.props.center);
301
+ initData();
302
+ }
303
+ // 创建地图
304
+
305
+ }, {
306
+ key: 'createMap',
307
+ value: function createMap() {
308
+ var t = this;
309
+ var _t$props2 = t.props,
310
+ _t$props2$olProps = _t$props2.olProps,
311
+ olProps = _t$props2$olProps === undefined ? {} : _t$props2$olProps,
312
+ _t$props2$mapCenter = _t$props2.mapCenter,
313
+ mapCenter = _t$props2$mapCenter === undefined ? [] : _t$props2$mapCenter,
314
+ mapId = _t$props2.mapId,
315
+ mapZoomLevel = _t$props2.mapZoomLevel,
316
+ minZoom = _t$props2.minZoom,
317
+ maxZoom = _t$props2.maxZoom;
318
+ var _olProps$projection = olProps.projection,
319
+ projection = _olProps$projection === undefined ? 'EPSG:4326' : _olProps$projection,
320
+ olCoverage = olProps.olCoverage;
321
+
322
+ if (window.OlMap) {
323
+ window.OlMap[mapId] = null;
324
+ } else {
325
+ window.OlMap = {};
326
+ }
327
+ window.OlMap[mapId] = t.state.gis = new ol.Map({
328
+ target: mapId.toString(),
329
+ view: new ol.View({
330
+ center: mapCenter && mapCenter instanceof Array && mapCenter.length == 2 ? mapCenter : [116.400433, 39.906705], //中心点
331
+ zoom: mapZoomLevel || 10,
332
+ projection: projection,
333
+ minZoom: minZoom,
334
+ maxZoom: maxZoom
335
+ }),
336
+ controls: ol.control.defaults({
337
+ zoom: false,
338
+ rotate: false,
339
+ attribution: false
340
+ })
341
+ });
342
+ // 基本地图视图
343
+ t.viewer = new ol.View({
344
+ center: mapCenter && mapCenter instanceof Array && mapCenter.length == 2 ? mapCenter : [116.400433, 39.906705], //中心点
345
+ zoom: mapZoomLevel || 10,
346
+ projection: projection,
347
+ minZoom: minZoom,
348
+ maxZoom: maxZoom
349
+ });
350
+ if ((olCoverage || []).length > 0) {
351
+ (olCoverage || []).map(function (item) {
352
+ if (OL_SCREEN[item.coverage]) {
353
+ var _layer = eval(OL_SCREEN[item.coverage].initLayer);
354
+ t.state.gis.addLayer(_layer);
355
+ }
356
+ });
357
+ } else {
358
+ var _layer2 = eval(OL_SCREEN.default.initLayer);
359
+ t.state.gis.addLayer(_layer2);
360
+ }
361
+ }
362
+ // 设置中心点
363
+
364
+ }, {
365
+ key: 'setCenter',
366
+ value: function setCenter(gt) {
367
+ var t = this;
368
+ if (gt) {
369
+ //经纬度 必须存在 否则不操作
370
+ if (!gt[0] || !gt[1]) {
371
+ return false;
372
+ }
373
+ //如果设置的经纬度 与当前中心点一样 不操作
374
+ var c = t.getCenter();
375
+ if (c.lng == gt[0] && c.lat == gt[1]) {
376
+ return false;
377
+ }
378
+ t.state.gis.getView().setCenter(gt);
379
+ t.viewer.animate({
380
+ center: gt,
381
+ duration: 2000
382
+ });
383
+ }
384
+ }
385
+ //获取当前中心点
386
+
387
+ }, {
388
+ key: 'getCenter',
389
+ value: function getCenter() {
390
+ var t = this;
391
+ var gis = t.state.gis;
392
+
393
+ var _gis$getView$calculat = gis.getView().calculateExtent(gis.getSize()),
394
+ _gis$getView$calculat2 = _slicedToArray(_gis$getView$calculat, 4),
395
+ xmin = _gis$getView$calculat2[0],
396
+ ymin = _gis$getView$calculat2[1],
397
+ xmax = _gis$getView$calculat2[2],
398
+ ymax = _gis$getView$calculat2[3];
399
+
400
+ return { lng: (xmin + xmax) / 2, lat: (ymin + ymax) / 2 };
401
+ }
402
+ //编辑图元
403
+
404
+ }, {
405
+ key: 'doEdit',
406
+ value: function doEdit(id) {
407
+ var t = this;
408
+ //获取图元对象
409
+ var gc = t.GM.getGraphic(id);
410
+ var gp = t.GM.getGraphicParam(id);
411
+ if (!gc) return false;
412
+ //关闭先前编辑的图元
413
+ if (!!t.state.editId) {
414
+ t.endEdit();
415
+ }
416
+ if (!t.editToolbar) {
417
+ t.editToolbar = new ol.interaction.Modify({
418
+ source: gp.source
419
+ });
420
+ t.state.gis.addInteraction(t.editToolbar);
421
+ t.editToolbar.on('modifyend', function (e) {
422
+ var feature = gc;
423
+ e.features.forEach(function (feature) {
424
+ feature = feature;
425
+ });
426
+ //返回参数
427
+ var param = {
428
+ id: id,
429
+ e: e
430
+ };
431
+ // 绘制内部管理的图元
432
+ if (gp.geometry.type == 'point') {
433
+ var cur = feature.getProperties().geometry;
434
+
435
+ var _cur$flatCoordinates = _slicedToArray(cur.flatCoordinates, 2),
436
+ lng = _cur$flatCoordinates[0],
437
+ lat = _cur$flatCoordinates[1];
438
+ //处理点返回参数
439
+
440
+
441
+ param = _extends({}, param, {
442
+ attributes: _extends({}, gp.attributes, {
443
+ longitude: lng,
444
+ latitude: lat,
445
+ other: _extends({}, gp.attributes, {
446
+ longitude: lng,
447
+ latitude: lat
448
+ })
449
+ }),
450
+ param: {
451
+ attributes: _extends({}, gp.attributes, {
452
+ longitude: lng,
453
+ latitude: lat,
454
+ other: _extends({}, gp.attributes, {
455
+ longitude: lng,
456
+ latitude: lat
457
+ })
458
+ }),
459
+ geometryType: gp.geometry.type,
460
+ mapLayer: t.GM.getGraphic(id)
461
+ },
462
+ geometryType: gp.geometry.type,
463
+ geometry: {
464
+ type: 'point',
465
+ x: lng,
466
+ y: lat
467
+ }
468
+ });
469
+ }
470
+ //线
471
+ if (gp.geometry.type == 'polyline') {
472
+ var _cur = feature.getProperties().geometry;
473
+ var oddList = [],
474
+ evenList = [];
475
+ _cur.flatCoordinates.map(function (item, index) {
476
+ // 判断下标奇偶数
477
+ if (index % 2 === 0) {
478
+ evenList.push(item);
479
+ } else {
480
+ oddList.push(item);
481
+ }
482
+ });
483
+ var path = oddList.map(function (item, index) {
484
+ return [evenList[index], oddList[index]];
485
+ });
486
+ //处理线返回参数
487
+
488
+ var _t$dealData = t.dealData(path),
489
+ lnglatAry = _t$dealData.lnglatAry,
490
+ _extent = _t$dealData._extent;
491
+
492
+ param = _extends({}, param, {
493
+ attributes: _extends({}, gp.attributes, {
494
+ paths: path,
495
+ other: _extends({}, gp.attributes, {
496
+ paths: path
497
+ })
498
+ }),
499
+ param: {
500
+ attributes: _extends({}, gp.attributes, {
501
+ paths: path,
502
+ other: _extends({}, gp.attributes, {
503
+ paths: path
504
+ })
505
+ }),
506
+ geometry: {
507
+ paths: path,
508
+ _extent: _extent,
509
+ type: "polyline"
510
+ },
511
+ geometryType: 'polyline',
512
+ lnglatAry: lnglatAry,
513
+ mapLayer: t.GM.getGraphic(id)
514
+ },
515
+ geometryType: gp.geometry.type,
516
+ geometry: {
517
+ paths: path,
518
+ _extent: _extent,
519
+ type: "polyline"
520
+ },
521
+ distance: t.calculateDistance(path)
522
+ });
523
+ }
524
+ //面
525
+ if (gp.geometry.type == 'polygon') {
526
+ var _cur2 = feature.getProperties().geometry;
527
+ var _oddList = [],
528
+ _evenList = [];
529
+ _cur2.flatCoordinates.map(function (item, index) {
530
+ // 判断下标奇偶数
531
+ if (index % 2 === 0) {
532
+ _evenList.push(item);
533
+ } else {
534
+ _oddList.push(item);
535
+ }
536
+ });
537
+ var _path = _oddList.map(function (item, index) {
538
+ return [_evenList[index], _oddList[index]];
539
+ });
540
+ //处理线返回参数
541
+
542
+ var _t$dealData2 = t.dealData(_path),
543
+ _lnglatAry = _t$dealData2.lnglatAry,
544
+ _extent2 = _t$dealData2._extent;
545
+
546
+ param = _extends({}, param, {
547
+ attributes: _extends({}, gp.attributes, {
548
+ rings: _path,
549
+ other: _extends({}, gp.attributes, {
550
+ paths: _path
551
+ })
552
+ }),
553
+ param: {
554
+ attributes: _extends({}, gp.attributes, {
555
+ rings: _path,
556
+ other: _extends({}, gp.attributes, {
557
+ paths: _path
558
+ })
559
+ }),
560
+ geometry: {
561
+ rings: _path,
562
+ type: 'polygon',
563
+ _extent: _extent2
564
+ },
565
+ geometryType: 'polygon',
566
+ lnglatAry: _lnglatAry,
567
+ mapLayer: t.GM.getGraphic(id)
568
+ },
569
+ geometryType: gp.geometry.type,
570
+ geometry: {
571
+ rings: _path,
572
+ type: 'polygon',
573
+ _extent: _extent2
574
+ },
575
+ area: (0, _MapToolFunction.getPolygonArea)(_path)
576
+ });
577
+ }
578
+ if (gp.geometry.type == 'circle') {
579
+ var _cur3 = feature.getProperties().geometry;
580
+ var center = _cur3.getCenter();
581
+ var sketchCoords_ = [_cur3.flatCoordinates[0], _cur3.flatCoordinates[1]];
582
+ var sketchCoords_2 = [_cur3.flatCoordinates[2], _cur3.flatCoordinates[3]];
583
+ var radius = ol.sphere.getDistance(sketchCoords_, sketchCoords_2);
584
+ param = _extends({}, param, {
585
+ attributes: _extends({}, gp.attributes, {
586
+ longitude: center[0],
587
+ latitude: center[1],
588
+ radius: radius,
589
+ other: _extends({}, gp.attributes, {
590
+ longitude: center[0],
591
+ latitude: center[1],
592
+ radius: radius
593
+ })
594
+ }),
595
+ param: {
596
+ attributes: _extends({}, gp.attributes, {
597
+ longitude: center[0],
598
+ latitude: center[1],
599
+ radius: radius,
600
+ other: _extends({}, gp.attributes, {
601
+ longitude: center[0],
602
+ latitude: center[1],
603
+ radius: radius
604
+ })
605
+ }),
606
+ geometry: {
607
+ x: center[0],
608
+ y: center[1],
609
+ radius: radius,
610
+ type: 'circle'
611
+ },
612
+ geometryType: 'circle',
613
+ mapLayer: t.GM.getGraphic(id)
614
+ },
615
+ geometryType: gp.geometry.type,
616
+ area: Math.PI * Math.pow(radius, 2),
617
+ geometry: {
618
+ type: 'circle',
619
+ x: center[0],
620
+ y: center[1],
621
+ radius: radius
622
+ }
623
+ });
624
+ }
625
+ if ('editGraphicChange' in t.props && typeof t.props.editGraphicChange == 'function') {
626
+ t.props.editGraphicChange(param);
627
+ }
628
+ t.GM.setGraphic(id, feature).setGraphicParam(id, _extends({}, param));
629
+ });
630
+ }
631
+ t.editId = id;
632
+ }
633
+ //关闭编辑
634
+
635
+ }, {
636
+ key: 'endEdit',
637
+ value: function endEdit() {
638
+ var t = this;
639
+ if (t.editToolbar) {
640
+ t.state.gis.removeInteraction(t.editToolbar);
641
+ t.editToolbar = null;
642
+ }
643
+ t.editId = '';
644
+ }
645
+ // 绘制图元
646
+
647
+ }, {
648
+ key: 'draw',
649
+ value: function draw(obj) {
650
+ var t = this;
651
+ var drawInfo = t.drawInfo;
652
+ var gis = t.state.gis;
653
+
654
+ var drawParam = {},
655
+ image = void 0,
656
+ stroke = void 0,
657
+ fill = void 0;
658
+ //初始化参数
659
+ drawParam.geometryType = obj.geometryType || 'point';
660
+ drawParam.parameter = obj.parameter ? _extends({}, obj.parameter) : {};
661
+ drawParam.data = obj.data ? _extends({}, obj.data) : {};
662
+ drawParam.data.id = (obj.data || {}).id || 'draw' + new Date().getTime();
663
+ //缓存 绘制的数据
664
+ t.drawParam = drawParam;
665
+ //判断id是否存在
666
+ var len = t.state.drawIds[drawParam.geometryType].indexOf(drawParam.data.id);
667
+ if (len > -1) {
668
+ //如果id存在 删除存在的图元,清除drawId中的id数据
669
+ t.removeGraphic(drawParam.data.id);
670
+ t.state.drawIds[drawParam.geometryType].splice(len, 1);
671
+ }
672
+ var type = 'Point',
673
+ style = new ol.style.Style({
674
+ image: new ol.style.Icon({
675
+ anchor: [-drawParam.parameter.markerContentX || -15, -drawParam.parameter.markerContentY || -15],
676
+ anchorXUnits: 'pixels',
677
+ anchorYUnits: 'pixels',
678
+ src: drawParam.parameter.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
679
+ opacity: 1,
680
+ scale: drawParam.parameter.scale || 1
681
+ })
682
+ });
683
+ switch (drawParam.geometryType) {
684
+ case 'point':
685
+ type = 'Point';
686
+ style = new ol.style.Style({
687
+ image: new ol.style.Icon({
688
+ anchor: [-drawParam.parameter.markerContentX || -15, -drawParam.parameter.markerContentY || -15],
689
+ anchorXUnits: 'pixels',
690
+ anchorYUnits: 'pixels',
691
+ src: drawParam.parameter.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
692
+ opacity: 1,
693
+ scale: drawParam.parameter.scale || 1
694
+ })
695
+ });
696
+ break;
697
+ case 'polyline':
698
+ type = 'LineString';
699
+ style = new ol.style.Style({
700
+ stoke: new ol.style.Stroke({
701
+ color: drawParam.parameter.color || '#277ffa',
702
+ width: drawParam.parameter.lineWidth || 3,
703
+ lineDash: drawParam.parameter.lineType == 'dashed' ? [2] : undefined
704
+ })
705
+ });
706
+ break;
707
+ case 'polygon':
708
+ type = 'Polygon';
709
+ style = new ol.style.Style({
710
+ stoke: new ol.style.Stroke({
711
+ color: drawParam.parameter.color || '#277ffa',
712
+ width: drawParam.parameter.lineWidth || 3,
713
+ lineDash: drawParam.parameter.lineType == 'dashed' ? [2] : undefined
714
+ }),
715
+ fill: new ol.style.Fill({
716
+ color: drawParam.parameter.pellucidity ? getRgbColor(drawParam.parameter.color || '#277ffa', drawParam.parameter.pellucidity) : drawParam.parameter.color || '#277ffa'
717
+ })
718
+ });
719
+ break;
720
+ case 'circle':
721
+ type = 'Circle';
722
+ style = new ol.style.Style({
723
+ stoke: new ol.style.Stroke({
724
+ color: drawParam.parameter.color || '#277ffa',
725
+ width: drawParam.parameter.lineWidth || 3,
726
+ lineDash: drawParam.parameter.lineType == 'dashed' ? [2] : undefined
727
+ }),
728
+ fill: new ol.style.Fill({
729
+ color: drawParam.parameter.pellucidity ? getRgbColor(drawParam.parameter.color || '#277ffa', drawParam.parameter.pellucidity) : drawParam.parameter.color || '#277ffa'
730
+ })
731
+ });
732
+ break;
733
+ }
734
+ if (!t.drawToolbar) {
735
+ t.drawToolbar = new ol.interaction.Draw({
736
+ source: t.drawSource,
737
+ type: type
738
+ // style: style
739
+ });
740
+ gis.addInteraction(t.drawToolbar);
741
+ t.drawToolbar.on('drawend', function (e) {
742
+ // 关闭绘制事件
743
+ t.drawToolbar.finishDrawing();
744
+ // 移除
745
+ gis.removeInteraction(t.drawToolbar);
746
+ var gc = e.feature.getGeometry();
747
+ //返回参数
748
+ var param = {};
749
+ // 绘制内部管理的图元
750
+ if (t.drawParam.geometryType == 'point') {
751
+ var _gc$flatCoordinates = _slicedToArray(gc.flatCoordinates, 2),
752
+ lng = _gc$flatCoordinates[0],
753
+ lat = _gc$flatCoordinates[1];
754
+
755
+ t.addPoint([{
756
+ id: t.drawParam.data.id,
757
+ longitude: lng,
758
+ latitude: lat,
759
+ url: t.drawParam.parameter.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
760
+ config: _extends({}, t.drawParam.parameter)
761
+ }], 'point');
762
+ //处理点返回参数
763
+ param = {
764
+ id: t.drawParam.data.id,
765
+ attributes: {
766
+ id: t.drawParam.data.id,
767
+ url: t.drawParam.parameter.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
768
+ config: {
769
+ width: t.drawParam.parameter.width || 30,
770
+ height: t.drawParam.parameter.height || 30
771
+ }
772
+ },
773
+ geometry: gc,
774
+ geometryType: 'point',
775
+ mapLayer: t.GM.getGraphic(t.drawParam.data.id)
776
+ };
777
+ }
778
+ //线
779
+ if (t.drawParam.geometryType == 'polyline') {
780
+ var oddList = [],
781
+ evenList = [];
782
+ gc.flatCoordinates.map(function (item, index) {
783
+ // 判断下标奇偶数
784
+ if (index % 2 === 0) {
785
+ evenList.push(item);
786
+ } else {
787
+ oddList.push(item);
788
+ }
789
+ });
790
+ var path = oddList.map(function (item, index) {
791
+ return [evenList[index], oddList[index]];
792
+ });
793
+ t.addLine([{
794
+ id: t.drawParam.data.id,
795
+ paths: path,
796
+ config: _extends({}, t.drawParam.parameter)
797
+ }], 'polyline');
798
+ //处理线返回参数
799
+
800
+ var _t$dealData3 = t.dealData(path),
801
+ lnglatAry = _t$dealData3.lnglatAry,
802
+ _extent = _t$dealData3._extent;
803
+
804
+ param = {
805
+ lnglatAry: lnglatAry,
806
+ id: t.drawParam.data.id,
807
+ geometry: _extends({}, e.geometry, {
808
+ paths: path,
809
+ _extent: _extent
810
+ }),
811
+ attributes: {
812
+ id: t.drawParam.data.id,
813
+ config: _extends({}, t.drawParam.parameter)
814
+ },
815
+ distance: t.calculateDistance(path),
816
+ geometryType: 'polyline',
817
+ mapLayer: t.GM.getGraphic(t.drawParam.data.id)
818
+ };
819
+ }
820
+ //面
821
+ if (t.drawParam.geometryType == 'polygon') {
822
+ var _oddList2 = [],
823
+ _evenList2 = [];
824
+ gc.flatCoordinates.map(function (item, index) {
825
+ // 判断下标奇偶数
826
+ if (index % 2 === 0) {
827
+ _evenList2.push(item);
828
+ } else {
829
+ _oddList2.push(item);
830
+ }
831
+ });
832
+ var _path2 = _oddList2.map(function (item, index) {
833
+ return [_evenList2[index], _oddList2[index]];
834
+ });
835
+ t.addPolygon([{
836
+ id: t.drawParam.data.id,
837
+ rings: _path2,
838
+ config: _extends({}, t.drawParam.parameter)
839
+ }], t.drawParam.geometryType);
840
+ //处理线返回参数
841
+
842
+ var _t$dealData4 = t.dealData(_path2),
843
+ _lnglatAry2 = _t$dealData4.lnglatAry,
844
+ _extent3 = _t$dealData4._extent;
845
+
846
+ param = {
847
+ lnglatAry: _lnglatAry2,
848
+ id: t.drawParam.data.id,
849
+ geometry: _extends({}, e.geometry, {
850
+ rings: _path2,
851
+ type: t.drawParam.geometryType,
852
+ _extent: _extent3
853
+ }),
854
+ attributes: {
855
+ id: t.drawParam.data.id,
856
+ config: _extends({}, t.drawParam.parameter)
857
+ },
858
+ area: (0, _MapToolFunction.getPolygonArea)(_path2),
859
+ geometryType: t.drawParam.geometryType,
860
+ mapLayer: t.GM.getGraphic(t.drawParam.data.id)
861
+ };
862
+ }
863
+ if (t.drawParam.geometryType == 'circle') {
864
+ var center = e.feature.getGeometry().getCenter();
865
+ // let radius = e.feature.getGeometry().getRadius();
866
+ // console.log(center, radius)
867
+ var sketchCoords_ = e.target.sketchCoords_[0];
868
+ var sketchCoords_2 = e.target.sketchCoords_[1];
869
+ var radius = ol.sphere.getDistance(sketchCoords_, sketchCoords_2);
870
+ // let metersPerUnit = gis.getView().getProjection().getMetersPerUnit();
871
+ // console.log(radius, metersPerUnit)
872
+ // let circleRadius = radius / metersPerUnit;
873
+ // console.log(circleRadius)
874
+ t.addCircle([{
875
+ id: t.drawParam.data.id,
876
+ longitude: center[0],
877
+ latitude: center[1],
878
+ radius: radius,
879
+ config: _extends({}, t.drawParam.parameter)
880
+ }], t.drawParam.geometryType);
881
+ param = {
882
+ area: Math.PI * Math.pow(radius, 2),
883
+ attributes: {
884
+ id: t.drawParam.data.id,
885
+ config: _extends({}, t.drawParam.parameter)
886
+ },
887
+ geometry: {
888
+ type: t.drawParam.geometryType,
889
+ x: center[0],
890
+ y: center[1],
891
+ radius: radius
892
+ },
893
+ geometryType: t.drawParam.geometryType,
894
+ mapLayer: t.GM.getGraphic(t.drawParam.data.id)
895
+ };
896
+ }
897
+ if ('drawEnd' in t.props && typeof t.props.drawEnd == 'function') {
898
+ t.props.drawEnd(param);
899
+ }
900
+ });
901
+ }
902
+ }
903
+ // 关闭绘制
904
+
905
+ }, {
906
+ key: 'closeDraw',
907
+ value: function closeDraw() {
908
+ var t = this;
909
+ var gis = t.state.gis;
910
+
911
+ if (t.drawToolbar) {
912
+ // 关闭绘制事件
913
+ t.drawToolbar.finishDrawing();
914
+ // 移除
915
+ gis.removeInteraction(t.drawToolbar);
916
+ t.drawToolbar = null;
917
+ t.drawInfo = {
918
+ sketch: null,
919
+ listener: null
920
+ };
921
+ }
922
+ }
923
+ // 绘图时创建绘图结果提示
924
+
925
+ }, {
926
+ key: 'createMeasureTooltip',
927
+ value: function createMeasureTooltip() {
928
+ var t = this;
929
+ var gis = t.state.gis;
930
+ var drawInfo = t.drawInfo;
931
+
932
+ if (drawInfo.measureTooltipElement) {
933
+ drawInfo.measureTooltipElement.parentNode.removeChild(measureTooltipElement);
934
+ }
935
+ drawInfo.measureTooltipElement = document.createElement('div');
936
+ drawInfo.measureTooltipElement.className = 'ol-tooltip ol-tooltip-measure';
937
+ drawInfo.measureTooltip = new ol.Overlay({
938
+ element: drawInfo.measureTooltipElement,
939
+ offset: [0, -15],
940
+ positioning: 'bottom-center',
941
+ stopEvent: false,
942
+ insertFirst: false
943
+ });
944
+ gis.addOverlay(drawInfo.measureTooltip);
945
+ }
946
+ // 绘图时创建提示
947
+
948
+ }, {
949
+ key: 'createHelpTooltip',
950
+ value: function createHelpTooltip() {
951
+ var t = this;
952
+ var gis = t.state.gis;
953
+ var drawInfo = t.drawInfo;
954
+
955
+ if (drawInfo.helpTooltipElement) {
956
+ drawInfo.helpTooltipElement.parentNode.removeChild(helpTooltipElement);
957
+ }
958
+ drawInfo.helpTooltipElement = document.createElement('div');
959
+ drawInfo.helpTooltipElement.className = 'ol-tooltip hidden';
960
+ drawInfo.helpTooltip = new ol.Overlay({
961
+ element: drawInfo.helpTooltipElement,
962
+ offset: [15, 0],
963
+ positioning: 'center-left'
964
+ });
965
+ gis.addOverlay(drawInfo.helpTooltip);
966
+ }
967
+ /*工具方法*/
968
+
969
+ }, {
970
+ key: 'vtxRangingTool',
971
+ value: function vtxRangingTool(mapRangingTool) {
972
+ var t = this;
973
+ //关闭测距时双击地图缩放功能
974
+ t.state.gis.disableDoubleClickZoom();
975
+ //开启测距状态
976
+ if (!t.rangingTool.isRanging) {
977
+ t.rangingTool.isRanging = true;
978
+ }
979
+ //初始测距回调
980
+ if (!t.rangingTool.mapRangingTool) {
981
+ t.rangingTool.mapRangingTool = mapRangingTool;
982
+ }
983
+ }
984
+ // 获取地图的当前位置状态信息
985
+
986
+ }, {
987
+ key: 'getMapExtent',
988
+ value: function getMapExtent() {
989
+ var t = this;
990
+ var gis = t.state.gis;
991
+
992
+ var obj = {};
993
+ if (gis) {
994
+ var nowBounds = gis.getView().calculateExtent(gis.getSize());
995
+ obj.southWest = {
996
+ lng: nowBounds[0],
997
+ lat: nowBounds[1]
998
+ };
999
+ obj.northEast = {
1000
+ lng: nowBounds[2],
1001
+ lat: nowBounds[3]
1002
+ };
1003
+ obj.nowCenter = t.getCenter();
1004
+ obj.zoom = t.getZoomLevel();
1005
+
1006
+ var _gis$getSize = gis.getSize(),
1007
+ _gis$getSize2 = _slicedToArray(_gis$getSize, 2),
1008
+ width = _gis$getSize2[0],
1009
+ height = _gis$getSize2[1];
1010
+
1011
+ obj.mapSize = { width: width, height: height };
1012
+ obj.radius = ol.sphere.getDistance([obj.nowCenter.lng, obj.nowCenter.lat], [obj.northEast.lng, obj.northEast.lat]);
1013
+ return obj;
1014
+ }
1015
+ }
1016
+ //将制定图元展示在视野内 (强制改变地图中心位置)
1017
+ /*
1018
+ 参数arg格式如下1,2
1019
+ 1.string 格式如:'1,a,2,3,4'
1020
+ 2.数组 ['1','2']
1021
+ */
1022
+
1023
+ }, {
1024
+ key: 'setVisiblePoints',
1025
+ value: function setVisiblePoints(mapVisiblePoints) {
1026
+ var t = this;
1027
+ var gis = t.state.gis;
1028
+
1029
+ var arg = null;
1030
+ var type = mapVisiblePoints.type;
1031
+ var ary = []; //图元id集合
1032
+ var obj = []; //经纬度集合
1033
+ switch (mapVisiblePoints.fitView) {
1034
+ case 'point':
1035
+ arg = this.state.pointIds;
1036
+ break;
1037
+ case 'line':
1038
+ arg = this.state.lineIds;
1039
+ break;
1040
+ case 'polygon':
1041
+ arg = this.state.polygonIds;
1042
+ break;
1043
+ case 'circle':
1044
+ arg = this.state.circleIds;
1045
+ break;
1046
+ case 'all':
1047
+ arg = this.state.pointIds.concat(this.state.lineIds).concat(this.state.polygonIds).concat(this.state.circleIds);
1048
+ break;
1049
+ default:
1050
+ arg = mapVisiblePoints.fitView;
1051
+ break;
1052
+ }
1053
+ if (typeof arg === 'string') {
1054
+ ary = arg.split(',');
1055
+ obj = t.getFitView(ary);
1056
+ } else if (arg instanceof Array) {
1057
+ if (ary[0] instanceof Array) {
1058
+ obj = gis.getFitView(ary[0]);
1059
+ } else {
1060
+ obj = t.getFitView(arg);
1061
+ }
1062
+ }
1063
+ if (!obj) {
1064
+ return false;
1065
+ }
1066
+ // let zoom = t.state.gis.getView().getZoom();
1067
+ if (type) {
1068
+ gis.getView().fit(obj, gis.getSize());
1069
+ }
1070
+ // if(!type || type == 'all'){
1071
+
1072
+ // }else if(type == 'zoom'){
1073
+ // gis.getView().setZoom(zoom)
1074
+ // }else if(type == 'center'){
1075
+ // gis.getView().setCenter(obj.lngLat);
1076
+ // }
1077
+ }
1078
+ }, {
1079
+ key: 'getFitView',
1080
+ value: function getFitView(ids) {
1081
+ var t = this;
1082
+ if (ids.length > 0) {
1083
+ var maxX = null,
1084
+ maxY = null,
1085
+ minX = null,
1086
+ minY = null;
1087
+ for (var i = 0; i < ids.length; i++) {
1088
+ var coord = t.GM.getGraphic(ids[i]);
1089
+ var boundsArry = coord.getGeometry().getExtent();
1090
+ if (minX === null) {
1091
+ minX = boundsArry[0];
1092
+ minY = boundsArry[1];
1093
+ maxX = boundsArry[2];
1094
+ maxY = boundsArry[3];
1095
+ } else {
1096
+ minX = Math.min(boundsArry[0], minX);
1097
+ minY = Math.min(boundsArry[1], minY);
1098
+ maxX = Math.max(boundsArry[2], maxX);
1099
+ maxY = Math.max(boundsArry[3], maxY);
1100
+ }
1101
+ }
1102
+ var bounds = [minX, minY, maxX, maxY];
1103
+ return bounds;
1104
+ }
1105
+ }
1106
+ /*功能方法*/
1107
+ //获取当前地图的中心位置
1108
+
1109
+ }, {
1110
+ key: 'getCurrentCenter',
1111
+ value: function getCurrentCenter() {
1112
+ var t = this;
1113
+ var gis = t.state.gis;
1114
+
1115
+ var extent = gis.getView().calculateExtent(gis.getSize());
1116
+ return [(extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2];
1117
+ }
1118
+ //获取当前比例尺
1119
+
1120
+ }, {
1121
+ key: 'getZoomLevel',
1122
+ value: function getZoomLevel() {
1123
+ var t = this;
1124
+ return t.state.gis.getView().getZoom();
1125
+ }
1126
+ //获取图元数据
1127
+
1128
+ }, {
1129
+ key: 'getGraphic',
1130
+ value: function getGraphic(id) {
1131
+ var t = this;
1132
+ if (!id) {
1133
+ return false;
1134
+ }
1135
+ var gp = t.GM.getGraphicParam(id);
1136
+ var gg = t.GM.getGraphic(id);
1137
+ if (!gg) {
1138
+ return false;
1139
+ }
1140
+ var p = {},
1141
+ pts = [],
1142
+ lng = 0,
1143
+ lat = 0;
1144
+ switch (gp.geometryType) {
1145
+ case 'point':
1146
+ lng = gp.geometry.x;
1147
+ lat = gp.geometry.y;
1148
+ p = _extends({}, gp, {
1149
+ mapLayer: gg,
1150
+ geometry: _extends({}, gp.geometry, {
1151
+ x: lng,
1152
+ y: lat
1153
+ }),
1154
+ attributes: _extends({}, gp.attributes, {
1155
+ longitude: lng,
1156
+ latitude: lat,
1157
+ other: _extends({}, gp.attributes.other, {
1158
+ longitude: lng,
1159
+ latitude: lat
1160
+ })
1161
+ })
1162
+ });
1163
+ break;
1164
+ case 'polyline':
1165
+ pts = gp.geometry.paths;
1166
+ p = _extends({}, gp, {
1167
+ mapLayer: gg,
1168
+ geometry: _extends({}, gp.geometry, {
1169
+ paths: pts
1170
+ }),
1171
+ attributes: _extends({}, gp.attributes, {
1172
+ paths: pts,
1173
+ other: _extends({}, gp.attributes.other, {
1174
+ paths: pts
1175
+ })
1176
+ })
1177
+ });
1178
+ break;
1179
+ case 'polygon':
1180
+ pts = gp.geometry.rings;
1181
+ p = _extends({}, gp, {
1182
+ mapLayer: gg,
1183
+ geometry: _extends({}, gp.geometry, {
1184
+ rings: pts
1185
+ }),
1186
+ attributes: _extends({}, gp.attributes, {
1187
+ rings: pts,
1188
+ other: _extends({}, gp.attributes.other, {
1189
+ rings: pts
1190
+ })
1191
+ }),
1192
+ area: (0, _MapToolFunction.getPolygonArea)(pts)
1193
+ });
1194
+ break;
1195
+ case 'circle':
1196
+ lng = gp.geometry.x;
1197
+ lat = gp.geometry.y;
1198
+ var radius = gp.geometry.radius;
1199
+ p = _extends({}, gp, {
1200
+ mapLayer: gg,
1201
+ geometry: _extends({}, gp.geometry, {
1202
+ x: lng,
1203
+ y: lat,
1204
+ radius: radius
1205
+ }),
1206
+ attributes: _extends({}, gp.attributes, {
1207
+ longitude: lng,
1208
+ latitude: lat,
1209
+ radius: radius,
1210
+ other: _extends({}, gp.attributes.other, {
1211
+ longitude: lng,
1212
+ latitude: lat,
1213
+ radius: radius
1214
+ })
1215
+ })
1216
+ });
1217
+ break;
1218
+ }
1219
+ return p;
1220
+ }
1221
+ // 转换dom节点
1222
+
1223
+ }, {
1224
+ key: 'parseDom',
1225
+ value: function parseDom(domStr) {
1226
+ var domObj = document.createElement('div');
1227
+ domObj.innerHTML = domStr;
1228
+ return domObj.childNodes;
1229
+ }
1230
+ //添加海量点
1231
+
1232
+ }, {
1233
+ key: 'addPointCollection',
1234
+ value: function addPointCollection() {
1235
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1236
+
1237
+ var t = this;
1238
+ data.map(function (item, index) {
1239
+ var d = item || {};
1240
+ var points = (d.points || []).map(function (d, i) {
1241
+ var p = t.state.gis.getPixelFromCoordinate([d.lng, d.lat]);
1242
+ return [p[0], p[1]];
1243
+ });
1244
+
1245
+ var _t$state$gis$getSize = t.state.gis.getSize(),
1246
+ _t$state$gis$getSize2 = _slicedToArray(_t$state$gis$getSize, 2),
1247
+ width = _t$state$gis$getSize2[0],
1248
+ height = _t$state$gis$getSize2[1];
1249
+
1250
+ var options = {
1251
+ size: d.size,
1252
+ shape: d.shape,
1253
+ color: d.color,
1254
+ width: width,
1255
+ height: height,
1256
+ mapId: t.props.mapId
1257
+ };
1258
+ var VotexpointCollection = new GMapLib.PointCollection(points, options);
1259
+ t.morepoints.push({
1260
+ id: d.id,
1261
+ value: VotexpointCollection
1262
+ });
1263
+ VotexpointCollection.draw();
1264
+ });
1265
+ }
1266
+ //更新海量点
1267
+
1268
+ }, {
1269
+ key: 'updatePointCollection',
1270
+ value: function updatePointCollection() {
1271
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1272
+
1273
+ var t = this;
1274
+ data.map(function (ds, ind) {
1275
+ t.morepoints.map(function (item, index) {
1276
+ if (item.id == ds.id) {
1277
+ var points = (ds.points || []).map(function (d, i) {
1278
+ var p = t.state.gis.getPixelFromCoordinate([d.lng, d.lat]);
1279
+ return [p[0], p[1]];
1280
+ });
1281
+
1282
+ var _t$state$gis$getSize3 = t.state.gis.getSize(),
1283
+ _t$state$gis$getSize4 = _slicedToArray(_t$state$gis$getSize3, 2),
1284
+ width = _t$state$gis$getSize4[0],
1285
+ height = _t$state$gis$getSize4[1];
1286
+
1287
+ var options = {
1288
+ size: ds.size,
1289
+ shape: ds.shape,
1290
+ color: ds.color,
1291
+ width: width,
1292
+ height: height
1293
+ };
1294
+ item.value.reDraw(points, options);
1295
+ }
1296
+ });
1297
+ });
1298
+ }
1299
+ //删除海量点
1300
+
1301
+ }, {
1302
+ key: 'clearPointCollection',
1303
+ value: function clearPointCollection() {
1304
+ var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1305
+
1306
+ var t = this;
1307
+ ids.map(function (id, ind) {
1308
+ t.morepoints.map(function (item, index) {
1309
+ if (id == item.id) {
1310
+ item.value.clear();
1311
+ }
1312
+ });
1313
+ });
1314
+ }
1315
+ //删除全部海量点
1316
+
1317
+ }, {
1318
+ key: 'clearAllPointCollection',
1319
+ value: function clearAllPointCollection() {
1320
+ var t = this;
1321
+ t.morepoints.map(function (item, index) {
1322
+ item.value.clear();
1323
+ });
1324
+ }
1325
+ // 添加点
1326
+
1327
+ }, {
1328
+ key: 'addPoint',
1329
+ value: function addPoint(mapPoints, type) {
1330
+ var _this2 = this;
1331
+
1332
+ var t = this;
1333
+ var ps = [];
1334
+ var psids = [].concat(_toConsumableArray(t.state.pointIds));
1335
+ mapPoints.map(function (item, index) {
1336
+ //如果id重复,直接跳过不执行.
1337
+ if (_this2.GM.isRepetition(item.id)) {
1338
+ console.warn('\u52A0\u70B9id: ' + item.id + ' \u91CD\u590D');
1339
+ return false;
1340
+ }
1341
+ //点位数据不符合,直接跳过
1342
+ if (!item.longitude || !item.latitude) {
1343
+ console.warn('\u70B9 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF');
1344
+ return false;
1345
+ }
1346
+ // 创建点位图元要素
1347
+ var feature = new ol.Feature({
1348
+ geometry: new ol.geom.Point([item.longitude, item.latitude]),
1349
+ name: item.name,
1350
+ id: item.id,
1351
+ params: _extends({}, item)
1352
+ });
1353
+ var cg = {
1354
+ width: 30,
1355
+ height: 30,
1356
+ labelContent: '',
1357
+ labelPixelX: 0,
1358
+ labelPixelY: 34,
1359
+ markerContentX: -13,
1360
+ markerContentY: -42,
1361
+ zIndex: 100,
1362
+ deg: 0,
1363
+ scale: 1
1364
+ };
1365
+ //初始化默认数据
1366
+ if (item.config) {
1367
+ cg = _extends({}, cg, item.config);
1368
+ }
1369
+ // 覆盖物样式参数
1370
+ var style = void 0,
1371
+ icon = void 0,
1372
+ txt = void 0;
1373
+ if (!!item.markerContent) {
1374
+ var nodes = t.parseDom(item.markerContent)[0];
1375
+ // 创建地图自定义覆盖物
1376
+ var pop = new ol.Overlay({
1377
+ id: item.id,
1378
+ position: [item.longitude, item.latitude],
1379
+ positioning: 'center-center',
1380
+ element: nodes,
1381
+ autoPanMargin: 20,
1382
+ autoPan: true,
1383
+ offset: [0, -20],
1384
+ insertFirst: true
1385
+ });
1386
+ t.state.gis.addOverlay(pop);
1387
+ } else {
1388
+ // 创建地图要素图标样式
1389
+ style = new ol.style.Style({
1390
+ image: new ol.style.Icon({
1391
+ anchor: [-cg.markerContentX, -cg.markerContentY],
1392
+ anchorXUnits: 'pixels',
1393
+ anchorYUnits: 'pixels',
1394
+ src: item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
1395
+ // imgSize: [cg.width, cg.height],
1396
+ opacity: cg.opacity,
1397
+ scale: cg.scale || 1
1398
+ })
1399
+ });
1400
+ }
1401
+ if (!!item.canShowLabel && item.canShowLabel) {
1402
+ // 创建地图要素图标样式
1403
+ style = new ol.style.Style({
1404
+ image: new ol.style.Icon({
1405
+ anchor: [-cg.markerContentX, -cg.markerContentY],
1406
+ anchorXUnits: 'pixels',
1407
+ anchorYUnits: 'pixels',
1408
+ src: item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
1409
+ // imgSize: [cg.width, cg.height],
1410
+ opacity: cg.opacity,
1411
+ scale: cg.scale || 1
1412
+ }),
1413
+ // 创建地图要素文字样式
1414
+ text: new ol.style.Text({
1415
+ textAlign: 'center', //对齐方式
1416
+ textBaseline: 'middle', //文本基线
1417
+ font: 'normal 12px 微软雅黑', //字体样式
1418
+ text: cg.labelContent, //文本内容
1419
+ offsetX: cg.labelPixelX, // x轴偏置
1420
+ offsetY: cg.labelPixelY, // Y轴偏置
1421
+ fill: new ol.style.Fill({
1422
+ //填充样式
1423
+ color: 'rgba(0,0,0,0.8)'
1424
+ }),
1425
+ backgroundFill: new ol.style.Fill({
1426
+ // 填充背景
1427
+ color: 'rgba(255, 255, 255, 0.3)'
1428
+ }),
1429
+ padding: [2, 5, 2, 5]
1430
+ })
1431
+ });
1432
+ }
1433
+ feature.setStyle(style);
1434
+ // 初始化适量数据源
1435
+ var source = new ol.source.Vector({
1436
+ features: [feature],
1437
+ name: 'point',
1438
+ id: item.id
1439
+ });
1440
+ var pointLayer = new ol.layer.Vector({
1441
+ name: 'point',
1442
+ source: source,
1443
+ id: item.id
1444
+ });
1445
+ //添加点位图层
1446
+ t.state.gis.addLayer(pointLayer);
1447
+ if (!item.markerContent && cg.BAnimationType == 0) {
1448
+ marker.setAnimation(BMAP_ANIMATION_BOUNCE);
1449
+ } else if (!item.markerContent && cg.BAnimationType == 1) {
1450
+ marker.setAnimation(BMAP_ANIMATION_DROP);
1451
+ }
1452
+ psids.push(item.id);
1453
+ //缓存图元的数据,偏于后期操作
1454
+ _this2.GM.setGraphic(item.id, feature).setGraphicParam(item.id, {
1455
+ attributes: _extends({}, item, { other: item }),
1456
+ geometryType: 'point',
1457
+ geometry: {
1458
+ type: 'point',
1459
+ x: item.longitude,
1460
+ y: item.latitude
1461
+ },
1462
+ source: source
1463
+ });
1464
+ });
1465
+ if (type !== 'defined') {
1466
+ t.state.pointIds = psids;
1467
+ }
1468
+ }
1469
+ //更新点
1470
+
1471
+ }, {
1472
+ key: 'updatePoint',
1473
+ value: function updatePoint() {
1474
+ var _this3 = this;
1475
+
1476
+ var mapPoints = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1477
+
1478
+ var t = this;
1479
+ mapPoints.map(function (item, index) {
1480
+ //判断图元是否存在.
1481
+ if (_this3.GM.isRepetition(item.id)) {
1482
+ //点位数据不符合,直接跳过
1483
+ if (!item.longitude || !item.latitude) {
1484
+ console.warn('\u70B9 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF');
1485
+ return false;
1486
+ }
1487
+ var gc = t.GM.getGraphic(item.id);
1488
+ var cg = {
1489
+ width: 30,
1490
+ height: 30,
1491
+ labelContent: '',
1492
+ labelPixelX: 0,
1493
+ labelPixelY: 34,
1494
+ BAnimationType: 3,
1495
+ //默认点的偏移值就不同
1496
+ markerContentX: -15,
1497
+ markerContentY: -30,
1498
+ deg: 0
1499
+ };
1500
+ if (item.config) {
1501
+ cg = _extends({}, cg, item.config);
1502
+ }
1503
+ var fStyle = gc.getStyle();
1504
+ var fText = fStyle.getText();
1505
+ var text = void 0,
1506
+ icon = void 0,
1507
+ _marker = void 0;
1508
+ if (item.markerContent) {
1509
+ var overlay = t.state.gis.getOverlayById(item.id);
1510
+ var nodes = t.parseDom(item.markerContent)[0];
1511
+ overlay.setElement(nodes);
1512
+ overlay.setPosition([item.longitude, item.latitude]);
1513
+ t.state.gis.changed();
1514
+ } else {
1515
+ icon = new ol.style.Icon({
1516
+ anchor: [-cg.markerContentX, -cg.markerContentY],
1517
+ anchorXUnits: 'pixels',
1518
+ anchorYUnits: 'pixels',
1519
+ src: item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
1520
+ // imgSize: [cg.width, cg.height],
1521
+ opacity: cg.opacity,
1522
+ scale: cg.scale || 1,
1523
+ rotation: Math.PI / 180 * cg.deg
1524
+ });
1525
+ if (item.canShowLabel) {
1526
+ text = new ol.style.Text({
1527
+ textAlign: 'center', //对齐方式
1528
+ textBaseline: 'middle', //文本基线
1529
+ font: 'normal 12px 微软雅黑', //字体样式
1530
+ text: cg.labelContent, //文本内容
1531
+ offsetX: cg.labelPixelX || fText.offsetX_, // x轴偏置
1532
+ offsetY: cg.labelPixelY || fText.offsetY_, // Y轴偏置
1533
+ fill: new ol.style.Fill({
1534
+ //填充样式
1535
+ color: 'rgba(0,0,0,0.8)'
1536
+ }),
1537
+ backgroundFill: new ol.style.Fill({
1538
+ // 填充背景
1539
+ color: 'rgba(255, 255, 255, 0.3)'
1540
+ }),
1541
+ padding: [2, 5, 2, 5]
1542
+ });
1543
+ }
1544
+ if (text) {
1545
+ gc.setStyle(new ol.style.Style({
1546
+ image: icon,
1547
+ text: text
1548
+ }));
1549
+ } else {
1550
+ gc.setStyle(new ol.style.Style({
1551
+ image: icon
1552
+ }));
1553
+ }
1554
+ }
1555
+ gc.setGeometry(new ol.geom.Point([item.longitude, item.latitude]));
1556
+ _this3.GM.setGraphicParam(item.id, {
1557
+ attributes: _extends({}, item, { other: item }),
1558
+ geometryType: 'point',
1559
+ geometry: {
1560
+ type: 'point',
1561
+ x: item.longitude,
1562
+ y: item.latitude
1563
+ },
1564
+ source: gc.source
1565
+ });
1566
+ } else {
1567
+ console.warn('\u66F4\u65B0\u7684\u70B9\u4F4Did\u4E0D\u5B58\u5728!');
1568
+ return false;
1569
+ }
1570
+ });
1571
+ }
1572
+ // 添加先
1573
+
1574
+ }, {
1575
+ key: 'addLine',
1576
+ value: function addLine(mapLines, type) {
1577
+ var _this4 = this;
1578
+
1579
+ var t = this;
1580
+ var ls = [];
1581
+ var lsids = [].concat(_toConsumableArray(t.state.lineIds));
1582
+ //遍历添加线(图元)
1583
+ mapLines.map(function (item, index) {
1584
+ //如果id重复,直接跳过不执行.
1585
+ if (_this4.GM.isRepetition(item.id)) {
1586
+ console.warn('\u591A\u6298\u7EBFid: ' + item.id + ' \u91CD\u590D');
1587
+ return false;
1588
+ }
1589
+ //多折线点位数据不符合,直接跳过
1590
+ if (!(item.paths && item.paths.length >= 2)) {
1591
+ console.warn('\u591A\u6298\u7EBFpaths\u6570\u636E\u9519\u8BEF');
1592
+ return false;
1593
+ }
1594
+ var cg = {
1595
+ color: '#277ffa',
1596
+ pellucidity: 0.9,
1597
+ lineWidth: 5,
1598
+ lineType: 'solid',
1599
+ isHidden: false
1600
+ };
1601
+ if (item.config) {
1602
+ cg = _extends({}, cg, item.config);
1603
+ }
1604
+ var style = new ol.style.Style({
1605
+ stroke: new ol.style.Stroke({
1606
+ color: cg.color,
1607
+ width: cg.lineWidth,
1608
+ lineDash: cg.lineType == 'dashed' ? [2] : undefined
1609
+ })
1610
+ });
1611
+ var polyline = new ol.Feature({
1612
+ geometry: new ol.geom.LineString(item.paths),
1613
+ id: item.id,
1614
+ params: _extends({}, item)
1615
+ });
1616
+ polyline.setStyle(style);
1617
+ var source = new ol.source.Vector({
1618
+ features: [polyline],
1619
+ name: 'polyline',
1620
+ id: item.id
1621
+ });
1622
+ var lineLayer = new ol.layer.Vector({
1623
+ name: 'polyline',
1624
+ id: item.id,
1625
+ source: source
1626
+ });
1627
+ t.state.gis.addLayer(lineLayer);
1628
+ //缓存图元的数据,便于后期操作
1629
+ var pts = item.paths.map(function (itt, ind) {
1630
+ return [].concat(_toConsumableArray(itt));
1631
+ });
1632
+ _this4.GM.setGraphic(item.id, polyline).setGraphicParam(item.id, {
1633
+ attributes: _extends({}, item, {
1634
+ paths: pts,
1635
+ other: item
1636
+ }),
1637
+ geometryType: 'polyline',
1638
+ geometry: {
1639
+ type: 'polyline',
1640
+ paths: pts
1641
+ },
1642
+ source: source
1643
+ });
1644
+ ls.push(polyline);
1645
+ lsids.push(item.id);
1646
+ t.state.lineIds.push(item.id);
1647
+ });
1648
+ if (type !== 'defined') {
1649
+ t.state.lineIds = lsids;
1650
+ }
1651
+ }
1652
+ //更新线
1653
+
1654
+ }, {
1655
+ key: 'updateLine',
1656
+ value: function updateLine(mapLines) {
1657
+ var _this5 = this;
1658
+
1659
+ var t = this;
1660
+ //遍历添加线(图元)
1661
+ mapLines.map(function (item, index) {
1662
+ //判断图元是否存在.
1663
+ if (_this5.GM.isRepetition(item.id)) {
1664
+ //多折线点位数据不符合,直接跳过
1665
+ if (!(item.paths && item.paths.length >= 2)) {
1666
+ console.warn('\u591A\u6298\u7EBFpaths\u6570\u636E\u9519\u8BEF');
1667
+ return false;
1668
+ }
1669
+ //初始化默认参数
1670
+ var cg = {
1671
+ color: '#277ffa',
1672
+ pellucidity: 0.9,
1673
+ lineWidth: 5,
1674
+ lineType: 'solid', //'solid' 'dashed'
1675
+ isHidden: false
1676
+ //获取原有的图元
1677
+ };var gc = _this5.GM.getGraphic(item.id);
1678
+ var gp = _this5.GM.getGraphicParam(item.id);
1679
+ //重新初始化值
1680
+ if (item.config) {
1681
+ cg = _extends({}, cg, item.config);
1682
+ }
1683
+ var pts = item.paths.map(function (itt, ind) {
1684
+ return [].concat(_toConsumableArray(itt));
1685
+ });
1686
+ var style = new ol.style.Style({
1687
+ stroke: new ol.style.Stroke({
1688
+ color: cg.color,
1689
+ width: cg.lineWidth,
1690
+ lineDash: cg.lineType == 'dashed' ? [2] : undefined,
1691
+ zIndex: cg.zIndex || 0
1692
+ })
1693
+ });
1694
+ gc.setStyle(function () {
1695
+ return style;
1696
+ });
1697
+ gc.setGeometry(new ol.geom.LineString(pts));
1698
+ _this5.GM.setGraphicParam(item.id, {
1699
+ attributes: _extends({}, item, {
1700
+ paths: pts,
1701
+ other: item
1702
+ }),
1703
+ geometryType: 'polyline',
1704
+ geometry: {
1705
+ type: 'polyline',
1706
+ paths: pts
1707
+ },
1708
+ source: gp.source
1709
+ });
1710
+ } else {
1711
+ console.warn('\u66F4\u65B0\u7684\u591A\u6298\u7EBFid\u4E0D\u5B58\u5728!');
1712
+ return false;
1713
+ }
1714
+ });
1715
+ }
1716
+ //添加面
1717
+
1718
+ }, {
1719
+ key: 'addPolygon',
1720
+ value: function addPolygon(mapPolygons) {
1721
+ var _this6 = this;
1722
+
1723
+ var t = this;
1724
+ var pgs = [];
1725
+ var pgsids = [].concat(_toConsumableArray(t.state.polygonIds));
1726
+ //遍历添加面(图元)
1727
+ mapPolygons.map(function (item, index) {
1728
+ //如果id重复,直接跳过不执行.
1729
+ if (_this6.GM.isRepetition(item.id)) {
1730
+ console.warn('\u591A\u8FB9\u5F62id: ' + item.id + ' \u91CD\u590D');
1731
+ return false;
1732
+ }
1733
+ //多边形点位数据不符合,直接跳过
1734
+ if (!(item.rings && item.rings.length >= 3)) {
1735
+ console.warn('\u591A\u8FB9\u5F62rings\u6570\u636E\u9519\u8BEF');
1736
+ return false;
1737
+ }
1738
+ var cg = {
1739
+ lineType: 'solid',
1740
+ lineWidth: 5,
1741
+ lineColor: '#277ffa',
1742
+ lineOpacity: 1,
1743
+ color: '#fff',
1744
+ pellucidity: 0.5
1745
+ };
1746
+ if (item.config) {
1747
+ cg = _extends({}, cg, item.config);
1748
+ }
1749
+ var style = new ol.style.Style({
1750
+ stroke: new ol.style.Stroke({
1751
+ color: cg.lineColor,
1752
+ width: cg.lineWidth,
1753
+ lineDash: cg.lineType == 'dashed' ? [2] : undefined
1754
+ }),
1755
+ fill: new ol.style.Fill({
1756
+ color: cg.pellucidity ? getRgbColor(cg.color, cg.pellucidity) : cg.color
1757
+ })
1758
+ });
1759
+ var polygon = new ol.Feature({
1760
+ geometry: new ol.geom.Polygon([item.rings]),
1761
+ id: item.id,
1762
+ params: _extends({}, item),
1763
+ name: 'polygon'
1764
+ });
1765
+ polygon.setStyle(style);
1766
+ var source = new ol.source.Vector({
1767
+ features: [polygon],
1768
+ id: item.id
1769
+ });
1770
+ var polygonLayer = new ol.layer.Vector({
1771
+ name: 'polygon',
1772
+ id: item.id,
1773
+ source: source
1774
+ });
1775
+ t.state.gis.addLayer(polygonLayer);
1776
+ //缓存图元的数据,便于后期操作
1777
+ var pts = item.rings.map(function (itt, ind) {
1778
+ return [].concat(_toConsumableArray(itt));
1779
+ });
1780
+ _this6.GM.setGraphic(item.id, polygon).setGraphicParam(item.id, {
1781
+ attributes: _extends({}, item, {
1782
+ rings: pts,
1783
+ other: item
1784
+ }),
1785
+ geometryType: 'polygon',
1786
+ geometry: {
1787
+ type: 'polygon',
1788
+ rings: pts
1789
+ },
1790
+ source: source
1791
+ });
1792
+ pgs.push(polygon);
1793
+ pgsids.push(item.id);
1794
+ });
1795
+ t.state.polygonIds = pgsids;
1796
+ }
1797
+ //更新面
1798
+
1799
+ }, {
1800
+ key: 'updatePolygon',
1801
+ value: function updatePolygon(mapPolygons) {
1802
+ var _this7 = this;
1803
+
1804
+ var t = this;
1805
+ mapPolygons.map(function (item, index) {
1806
+ //判断图元是否存在.
1807
+ if (_this7.GM.isRepetition(item.id)) {
1808
+ //多边形点位数据不符合,直接跳过
1809
+ if (!(item.rings && item.rings.length >= 3)) {
1810
+ console.warn('\u591A\u8FB9\u5F62rings\u6570\u636E\u9519\u8BEF');
1811
+ return false;
1812
+ }
1813
+ //获取原有的图元
1814
+ var gc = _this7.GM.getGraphic(item.id);
1815
+ //获取原有的面属性,转换key值
1816
+ var cg = {
1817
+ lineType: 'solid',
1818
+ lineWidth: 5,
1819
+ lineColor: '#277ffa',
1820
+ lineOpacity: 1,
1821
+ color: '#fff',
1822
+ pellucidity: 0.5
1823
+ };
1824
+ //重新初始化值
1825
+ if (item.config) {
1826
+ cg = _extends({}, cg, item.config);
1827
+ }
1828
+ var pts = item.rings.map(function (itt, ind) {
1829
+ return [].concat(_toConsumableArray(itt));
1830
+ });
1831
+ gc.setGeometry(new ol.geom.Polygon([pts]));
1832
+ gc.setStyle(new ol.style.Style({
1833
+ stroke: new ol.style.Stroke({
1834
+ color: cg.lineColor,
1835
+ width: cg.lineWidth,
1836
+ lineDash: cg.lineType == 'dashed' ? [2] : undefined
1837
+ }),
1838
+ fill: new ol.style.Fill({
1839
+ color: cg.pellucidity ? getRgbColor(cg.color, cg.pellucidity) : cg.color
1840
+ })
1841
+ }));
1842
+ _this7.GM.setGraphicParam(item.id, {
1843
+ attributes: _extends({}, item, {
1844
+ rings: pts,
1845
+ other: item
1846
+ }),
1847
+ geometryType: 'polygon',
1848
+ geometry: {
1849
+ type: 'polygon',
1850
+ rings: pts
1851
+ },
1852
+ source: gc.source
1853
+ });
1854
+ } else {
1855
+ console.warn('\u66F4\u65B0\u7684\u591A\u8FB9\u5F62id\u4E0D\u5B58\u5728!');
1856
+ return false;
1857
+ }
1858
+ });
1859
+ }
1860
+ //添加圆 circle
1861
+
1862
+ }, {
1863
+ key: 'addCircle',
1864
+ value: function addCircle(mapCircles, type) {
1865
+ var t = this;
1866
+ var ccsids = [].concat(_toConsumableArray(t.state.circleIds));
1867
+ if (type) {
1868
+ ccsids = [].concat(_toConsumableArray(t.state.drawIds[type]));
1869
+ }
1870
+ mapCircles.map(function (item, index) {
1871
+ //如果id重复,直接跳过不执行.
1872
+ if (t.GM.isRepetition(item.id)) {
1873
+ console.warn('\u5706id: ' + item.id + ' \u91CD\u590D');
1874
+ return false;
1875
+ }
1876
+ //圆 点位数据不符合,直接跳过
1877
+ if (!item.longitude || !item.latitude) {
1878
+ console.warn('\u5706 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF');
1879
+ return false;
1880
+ }
1881
+ var cg = {
1882
+ lineType: 'solid',
1883
+ lineWidth: 5,
1884
+ lineColor: '#277ffa',
1885
+ lineOpacity: 1,
1886
+ color: '#fff',
1887
+ pellucidity: 0.5
1888
+ // isHidden: false //后期需要在加
1889
+ };
1890
+ if (item.config) {
1891
+ cg = _extends({}, cg, item.config);
1892
+ }
1893
+ var style = new ol.style.Style({
1894
+ stroke: new ol.style.Stroke({
1895
+ color: cg.lineColor,
1896
+ width: cg.lineWidth,
1897
+ lineDash: cg.lineType == 'dashed' ? [2] : undefined
1898
+ }),
1899
+ fill: new ol.style.Fill({
1900
+ color: cg.pellucidity ? getRgbColor(cg.color, cg.pellucidity) : cg.color
1901
+ })
1902
+ });
1903
+ var metersPerUnit = t.state.gis.getView().getProjection().getMetersPerUnit();
1904
+ var circleRadius = item.radius / metersPerUnit;
1905
+ var circle = new ol.Feature({
1906
+ geometry: new ol.geom.Circle([item.longitude, item.latitude], parseFloat(circleRadius)),
1907
+ id: item.id,
1908
+ params: _extends({}, item),
1909
+ name: 'circle'
1910
+ });
1911
+ circle.setStyle(style);
1912
+ var source = new ol.source.Vector({
1913
+ features: [circle],
1914
+ name: 'circle',
1915
+ id: item.id
1916
+ });
1917
+ var circleLayer = new ol.layer.Vector({
1918
+ name: 'circle',
1919
+ id: item.id,
1920
+ source: source
1921
+ });
1922
+ t.state.gis.addLayer(circleLayer);
1923
+ ccsids.push(item.id);
1924
+ t.GM.setGraphic(item.id, circle).setGraphicParam(item.id, {
1925
+ attributes: _extends({}, item, { other: item }),
1926
+ geometryType: 'circle',
1927
+ geometry: {
1928
+ type: 'circle',
1929
+ x: parseFloat(item.longitude),
1930
+ y: parseFloat(item.latitude),
1931
+ radius: parseFloat(item.radius)
1932
+ },
1933
+ source: source
1934
+ });
1935
+ });
1936
+ //添加绘制点
1937
+ if (type) {
1938
+ t.state.drawIds = _extends({}, t.state.drawIds, _defineProperty({}, type, ccsids));
1939
+ } else {
1940
+ t.state.circleIds = ccsids;
1941
+ }
1942
+ }
1943
+ //更新圆
1944
+
1945
+ }, {
1946
+ key: 'updateCircle',
1947
+ value: function updateCircle(mapCircles) {
1948
+ var t = this;
1949
+ mapCircles.map(function (item, index) {
1950
+ //判断图元是否存在.
1951
+ if (t.GM.isRepetition(item.id)) {
1952
+ //圆 点位数据不符合,直接跳过
1953
+ if (!item.longitude || !item.latitude) {
1954
+ console.warn('\u5706 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF');
1955
+ return false;
1956
+ }
1957
+ } else {
1958
+ console.warn('\u66F4\u65B0\u7684\u5706id\u4E0D\u5B58\u5728!');
1959
+ return false;
1960
+ }
1961
+ //获取原有的图元
1962
+ var gc = t.GM.getGraphic(item.id);
1963
+ //获取原有的面属性,转换key值
1964
+ var cg = {
1965
+ lineType: 'solid',
1966
+ lineWidth: 5,
1967
+ lineColor: '#277ffa',
1968
+ lineOpacity: 1,
1969
+ color: '#fff',
1970
+ pellucidity: 0.5
1971
+ // isHidden: false //后期需要在加
1972
+ };
1973
+ if (item.config) {
1974
+ cg = _extends({}, cg, item.config);
1975
+ }
1976
+ var metersPerUnit = t.state.gis.getView().getProjection().getMetersPerUnit();
1977
+ var circleRadius = item.radius / metersPerUnit;
1978
+ gc.setGeometry(new ol.geom.Circle([item.longitude, item.latitude], parseFloat(circleRadius)));
1979
+ gc.setStyle(new ol.style.Style({
1980
+ stroke: new ol.style.Stroke({
1981
+ color: cg.lineColor,
1982
+ width: cg.lineWidth,
1983
+ lineDash: cg.lineType == 'dashed' ? [2] : undefined
1984
+ }),
1985
+ fill: new ol.style.Fill({
1986
+ color: cg.pellucidity ? getRgbColor(cg.color, cg.pellucidity) : cg.color
1987
+ })
1988
+ }));
1989
+ t.GM.setGraphicParam(item.id, {
1990
+ attributes: _extends({}, item, { other: item }),
1991
+ geometryType: 'circle',
1992
+ geometry: {
1993
+ type: 'circle',
1994
+ x: parseFloat(item.longitude),
1995
+ y: parseFloat(item.latitude),
1996
+ radius: parseFloat(item.radius)
1997
+ },
1998
+ source: gc.source
1999
+ });
2000
+ });
2001
+ //刷新图元
2002
+ }
2003
+ // 工具方法
2004
+ //删除图元
2005
+
2006
+ }, {
2007
+ key: 'removeGraphic',
2008
+ value: function removeGraphic(id, type) {
2009
+ var t = this;
2010
+ var graphic = t.GM.getGraphic(id);
2011
+ var gp = t.GM.getGraphicParam(id);
2012
+ //刪除label
2013
+ if (t.Label[id]) {
2014
+ t.Label[id].html.remove();
2015
+ delete t.Label[id];
2016
+ }
2017
+ if (!!graphic) {
2018
+ //清除聚合点 避免异常
2019
+ // t._cluster.removeMarker(this.GM.getGraphic(id));
2020
+ //清除地图中图元
2021
+ // const layers = t.state.gis.getLayers().getArray();
2022
+ // console.log(layers)
2023
+ // const layer = layers.filter(item => item.getProperties().name == type)[0];
2024
+ // console.log(layer)
2025
+ console.log(gp);
2026
+ console.log(gp.source);
2027
+ gp.source.removeFeature(graphic);
2028
+ // layer && layer.getSource().removeFeature(graphic);
2029
+ //清除对应id的图元数据缓存
2030
+ t.GM.removeGraphic(id);
2031
+ } else {
2032
+ return false;
2033
+ }
2034
+ for (var i = 0; i < t.movePoints.length; i++) {
2035
+ if (t.movePoints[i].id == id) {
2036
+ t.movePoints.splice(i, 1);
2037
+ continue;
2038
+ }
2039
+ }
2040
+ var ids = [];
2041
+ switch (type) {
2042
+ case 'point':
2043
+ ids = t.state.pointIds;
2044
+ break;
2045
+ case 'line':
2046
+ ids = t.state.lineIds;
2047
+ break;
2048
+ case 'polygon':
2049
+ ids = t.state.polygonIds;
2050
+ break;
2051
+ case 'circle':
2052
+ ids = t.state.circleIds;
2053
+ break;
2054
+ case 'draw':
2055
+ if (t.state.drawIds.point.indexOf(id) > -1) {
2056
+ t.state.drawIds.point.splice(t.state.drawIds.point.indexOf(id), 1);
2057
+ }
2058
+ if (t.state.drawIds.polyline.indexOf(id) > -1) {
2059
+ t.state.drawIds.polyline.splice(t.state.drawIds.polyline.indexOf(id), 1);
2060
+ }
2061
+ if (t.state.drawIds.polygon.indexOf(id) > -1) {
2062
+ t.state.drawIds.polygon.splice(t.state.drawIds.polygon.indexOf(id), 1);
2063
+ }
2064
+ if (t.state.drawIds.circle.indexOf(id) > -1) {
2065
+ t.state.drawIds.circle.splice(t.state.drawIds.circle.indexOf(id), 1);
2066
+ }
2067
+ if (t.state.drawIds.rectangle.indexOf(id) > -1) {
2068
+ t.state.drawIds.rectangle.splice(t.state.drawIds.rectangle.indexOf(id), 1);
2069
+ }
2070
+ break;
2071
+ default:
2072
+ if (t.state.pointIds.indexOf(id) > -1) {
2073
+ t.state.pointIds.splice(t.state.pointIds.indexOf(id), 1);
2074
+ }
2075
+ if (t.state.lineIds.indexOf(id) > -1) {
2076
+ t.state.lineIds.splice(t.state.lineIds.indexOf(id), 1);
2077
+ }
2078
+ if (t.state.polygonIds.indexOf(id) > -1) {
2079
+ t.state.polygonIds.splice(t.state.polygonIds.indexOf(id), 1);
2080
+ }
2081
+ if (t.state.circleIds.indexOf(id) > -1) {
2082
+ t.state.circleIds.splice(t.state.circleIds.indexOf(id), 1);
2083
+ }
2084
+ break;
2085
+ }
2086
+ if (id == t.state.editId) {
2087
+ t.state.editId = '';
2088
+ }
2089
+ if (ids.indexOf(id) != -1) {
2090
+ ids.splice(ids.indexOf(id), 1);
2091
+ }
2092
+ }
2093
+ //清空地图
2094
+
2095
+ }, {
2096
+ key: 'clearAll',
2097
+ value: function clearAll() {
2098
+ var t = this;
2099
+ var gis = t.state.gis;
2100
+
2101
+ var layers = gis.getLayers();
2102
+ //清空热力图
2103
+ if (t.heatmap) {
2104
+ var hMap = layers.filter(function (item) {
2105
+ return item.name == 'heatMap';
2106
+ })[0];
2107
+ hMap.getSource().clear();
2108
+ map.removeLayer(layer);
2109
+ }
2110
+ t.heatmap = null;
2111
+ t.movePoints = [];
2112
+ t.clearAllPointCollection();
2113
+ //循环所有id删除
2114
+ var _t$state = t.state,
2115
+ pointIds = _t$state.pointIds,
2116
+ lineIds = _t$state.lineIds,
2117
+ polygonIds = _t$state.polygonIds,
2118
+ circleIds = _t$state.circleIds,
2119
+ drawIds = _t$state.drawIds;
2120
+ //拷贝数组,避免原数组操作,影响循环
2121
+
2122
+ var ps = [].concat(_toConsumableArray(pointIds)),
2123
+ ls = [].concat(_toConsumableArray(lineIds)),
2124
+ pgs = [].concat(_toConsumableArray(polygonIds)),
2125
+ cs = [].concat(_toConsumableArray(circleIds));
2126
+ // 删除点
2127
+ for (var i = 0; i < ps.length; i++) {
2128
+ t.removeGraphic(ps[i], 'point');
2129
+ }
2130
+ // 删除线
2131
+ for (var _i = 0; _i < ls.length; _i++) {
2132
+ t.removeGraphic(ls[_i], 'line');
2133
+ }
2134
+ // 删除面
2135
+ for (var _i2 = 0; _i2 < pgs.length; _i2++) {
2136
+ t.removeGraphic(pgs[_i2], 'polygon');
2137
+ }
2138
+ // 删除圆
2139
+ for (var _i3 = 0; _i3 < cs.length; _i3++) {
2140
+ t.removeGraphic(cs[_i3], 'circle');
2141
+ }
2142
+ //删除绘制的点
2143
+ var point = drawIds.point,
2144
+ polyline = drawIds.polyline,
2145
+ polygon = drawIds.polygon,
2146
+ circle = drawIds.circle,
2147
+ rectangle = drawIds.rectangle;
2148
+
2149
+ for (var _i4 = 0; _i4 < point.length; _i4++) {
2150
+ t.removeGraphic(point[_i4]);
2151
+ }
2152
+ for (var _i5 = 0; _i5 < polyline.length; _i5++) {
2153
+ t.removeGraphic(polyline[_i5]);
2154
+ }
2155
+ for (var _i6 = 0; _i6 < polygon.length; _i6++) {
2156
+ t.removeGraphic(polygon[_i6]);
2157
+ }
2158
+ for (var _i7 = 0; _i7 < circle.length; _i7++) {
2159
+ t.removeGraphic(circle[_i7]);
2160
+ }
2161
+ for (var _i8 = 0; _i8 < rectangle.length; _i8++) {
2162
+ t.removeGraphic(rectangle[_i8]);
2163
+ }
2164
+ }
2165
+ //展示比例尺
2166
+
2167
+ }, {
2168
+ key: 'showControl',
2169
+ value: function showControl() {
2170
+ var t = this,
2171
+ type = '',
2172
+ location = { top: 20, left: 20 },
2173
+ ls = { top: 20, left: 60 };
2174
+ var gis = t.state.gis;
2175
+
2176
+ var _gis$getSize3 = gis.getSize(),
2177
+ _gis$getSize4 = _slicedToArray(_gis$getSize3, 2),
2178
+ w = _gis$getSize4[0],
2179
+ h = _gis$getSize4[1];
2180
+
2181
+ var scaleControl = new ol.control.ScaleLine({
2182
+ units: 'metric' //设置度量单位
2183
+ });
2184
+ var zoomControl = new ol.control.Zoom({});
2185
+ var ZoomSliderControl = new ol.control.ZoomSlider({});
2186
+ gis.addControl(scaleControl);
2187
+ gis.addControl(zoomControl);
2188
+ gis.addControl(ZoomSliderControl);
2189
+ }
2190
+ //设置区域限制
2191
+
2192
+ }, {
2193
+ key: 'setAreaRestriction',
2194
+ value: function setAreaRestriction(areaRestriction) {
2195
+ var t = this;
2196
+
2197
+ var _t$dealData5 = t.dealData(areaRestriction),
2198
+ _et = _t$dealData5._extent;
2199
+
2200
+ t.areaRestriction = t.state.gis.getView().setProperties({
2201
+ extent: [_et.xmax, _et.ymax, _et.xmin, _et.ymin]
2202
+ }, false);
2203
+ }
2204
+ //关闭区域限制
2205
+
2206
+ }, {
2207
+ key: 'clearAreaRestriction',
2208
+ value: function clearAreaRestriction() {
2209
+ var t = this;
2210
+ t.areaRestriction = null;
2211
+ }
2212
+ //区域限制逻辑
2213
+
2214
+ }, {
2215
+ key: 'dealAreaRestriction',
2216
+ value: function dealAreaRestriction(e) {
2217
+ var t = this;
2218
+ //如果在区域内,不处理
2219
+ if (t.areaRestriction.contains(e.extent.getCenter())) {
2220
+ return;
2221
+ }
2222
+ // if(t.containsExtent(t.areaRestriction,e.extent)){
2223
+ // return;
2224
+ // }
2225
+ var _t$areaRestriction = t.areaRestriction,
2226
+ xmin1 = _t$areaRestriction.xmin,
2227
+ xmax1 = _t$areaRestriction.xmax,
2228
+ ymin1 = _t$areaRestriction.ymin,
2229
+ ymax1 = _t$areaRestriction.ymax;
2230
+ var _e$extent = e.extent,
2231
+ xmin2 = _e$extent.xmin,
2232
+ xmax2 = _e$extent.xmax,
2233
+ ymin2 = _e$extent.ymin,
2234
+ ymax2 = _e$extent.ymax;
2235
+
2236
+ var x = e.extent.getCenter().x,
2237
+ y = e.extent.getCenter().y;
2238
+ if (x < xmin1) x = xmin1 + 0.1;
2239
+ if (x > xmax1) x = xmax1 - 0.1;
2240
+ if (y < ymin1) y = ymin1 + 0.1;
2241
+ if (y > ymax1) y = ymax1 - 0.1;
2242
+ t.state.gis.getView().setCenter([x, y]);
2243
+ }
2244
+ /*公共方法*/
2245
+ //判断extent1是否在extent2内部
2246
+
2247
+ }, {
2248
+ key: 'containsExtent',
2249
+ value: function containsExtent(e1, e2) {
2250
+ var xmin1 = e1.xmin,
2251
+ xmax1 = e1.xmax,
2252
+ ymin1 = e1.ymin,
2253
+ ymax1 = e1.ymax;
2254
+ var xmin2 = e2.xmin,
2255
+ xmax2 = e2.xmax,
2256
+ ymin2 = e2.ymin,
2257
+ ymax2 = e2.ymax;
2258
+
2259
+ return xmin2 > xmin1 && xmax2 < xmax1 && ymin2 > ymin1 && ymax2 < ymax1;
2260
+ }
2261
+ //将图元z-index设置成最高
2262
+
2263
+ }, {
2264
+ key: 'czIndex',
2265
+ value: function czIndex(id) {
2266
+ var t = this;
2267
+ $('#' + t.props.mapId + '_graphics_layer').append(t.GM.getGraphic(id).getNode());
2268
+ }
2269
+ }, {
2270
+ key: 'equalsPoint',
2271
+ value: function equalsPoint(a, b) {
2272
+ return a.x == b.x && a.y == b.y;
2273
+ }
2274
+ //计算2点间距离 单位m 精确到2位小数
2275
+
2276
+ }, {
2277
+ key: 'calculatePointsDistance',
2278
+ value: function calculatePointsDistance(fp, ep) {
2279
+ return Math.round(ol.sphere.getDistance(fp, ep));
2280
+ }
2281
+ //计算多个点的距离(常用于线计算)
2282
+
2283
+ }, {
2284
+ key: 'calculateDistance',
2285
+ value: function calculateDistance(ps) {
2286
+ var t = this,
2287
+ totalDistance = 0;
2288
+ if (ps.length < 0) {
2289
+ return 0;
2290
+ }
2291
+ for (var i = 0; i < ps.length; i++) {
2292
+ if (i < ps.length - 1) {
2293
+ totalDistance += t.calculatePointsDistance(ps[i], ps[i + 1]);
2294
+ }
2295
+ }
2296
+ return Math.round(totalDistance * 100) / 100;
2297
+ }
2298
+ //处理线和面的 经纬度数据
2299
+
2300
+ }, {
2301
+ key: 'dealData',
2302
+ value: function dealData(paths) {
2303
+ //区别点和圆的经纬度数据处理
2304
+ var lnglatAry = [],
2305
+ _extent = { xmax: 0, xmin: 0, ymax: 0, ymin: 0 },
2306
+ path = [];
2307
+ path = paths.map(function (item, index) {
2308
+ var lng = item[0],
2309
+ lat = item[1];
2310
+ if (lng > _extent.xmax) {
2311
+ _extent.xmax = lng;
2312
+ }
2313
+ if (lng < _extent.xmin || _extent.xmin == 0) {
2314
+ _extent.xmin = lng;
2315
+ }
2316
+ if (lat > _extent.ymax) {
2317
+ _extent.ymax = lat;
2318
+ }
2319
+ if (lat < _extent.ymin || _extent.ymin == 0) {
2320
+ _extent.ymin = lat;
2321
+ }
2322
+ lnglatAry.push({
2323
+ lngX: lng,
2324
+ latX: lat
2325
+ });
2326
+ return [lng, lat];
2327
+ });
2328
+ return { lnglatAry: lnglatAry, _extent: _extent, path: path };
2329
+ }
2330
+ //处理点位图元的添加 和 更新
2331
+
2332
+ }, {
2333
+ key: 'dealLabelGraphics',
2334
+ value: function dealLabelGraphics(id, label) {
2335
+ var t = this;
2336
+ if (label) {
2337
+ var position = (t.GM.getGraphic(id) || {}).geometry || label.position;
2338
+ //经纬度转top和left
2339
+ var tl = t.state.gis.toScreen(position),
2340
+ lbl = _extends({}, label);
2341
+ //渲染優化
2342
+ if (!(tl.y < -50 || tl.x < -50 || tl.y > t.state.gis.height || tl.x > t.state.gis.width)) {
2343
+ //设置label的位置(通过定位来实现)
2344
+ label.html.css({
2345
+ position: 'absolute',
2346
+ top: tl.y + (label.offset.y || 0) - t.labelLayer.y,
2347
+ left: tl.x + (label.offset.x || 0) - t.labelLayer.x
2348
+ });
2349
+ //添加点位到(地图)
2350
+ $('#' + t.htmlPointsId).append(label.html);
2351
+ lbl.add = true;
2352
+ } else {
2353
+ lbl.add = false;
2354
+ }
2355
+ //记录下label的dom对象,用于后期修改和删除(基本是删除)
2356
+ t.Label[id] = lbl;
2357
+ }
2358
+ }
2359
+ //点的跳动动画
2360
+
2361
+ }, {
2362
+ key: 'pointAnimation',
2363
+ value: function pointAnimation(id, marker) {
2364
+ var t = this;
2365
+ //null时关闭跳动
2366
+ if (!!marker) {
2367
+ if (t.animTimer[id]) {
2368
+ clearInterval(t.animTimer[id]);
2369
+ }
2370
+ t.animTimer[id] = setInterval(function () {
2371
+ //点被隐藏时,没有执行,定时不关
2372
+ if (marker.symbol) {
2373
+ var shape = _extends({}, marker.symbol);
2374
+ //初始数据 点位有变动,重新刷新数据
2375
+ if (!t.animCount[id] || shape.yoffset != t.animCount[id].now) {
2376
+ t.animCount[id] = {
2377
+ start: shape.yoffset,
2378
+ now: shape.yoffset,
2379
+ notation: -1
2380
+ };
2381
+ }
2382
+ if (t.animCount[id].now - t.animCount[id].start == 20) {
2383
+ t.animCount[id].notation = -1;
2384
+ }
2385
+ if (t.animCount[id].now - t.animCount[id].start == 0) {
2386
+ t.animCount[id].notation = 1;
2387
+ }
2388
+ shape.yoffset = t.animCount[id].now = t.animCount[id].now + t.animCount[id].notation * 2;
2389
+ marker.symbol.setOffset(shape.xoffset, shape.yoffset);
2390
+ t.state.gis.graphics.refresh();
2391
+ }
2392
+ }, 35);
2393
+ } else {
2394
+ clearInterval(t.animTimer[id]);
2395
+ }
2396
+ }
2397
+ }, {
2398
+ key: 'moveAnimation',
2399
+ value: function moveAnimation() {
2400
+ var t = this;
2401
+ if (t.moveToTimer) {
2402
+ clearInterval(t.moveToTimer);
2403
+ }
2404
+ t.moveToTimer = setInterval(function () {
2405
+ for (var i = 0; i < t.movePoints.length; i++) {
2406
+ t.movePoints[i].waitTime += 10;
2407
+ t.movePoints[i].deleteTime -= 10;
2408
+ }
2409
+ t.movePoints.sort(function (x, y) {
2410
+ return y.waitTime - x.waitTime;
2411
+ });
2412
+ var nowMovePoints = t.movePoints.slice(0, 10),
2413
+ deleteIndex = [];
2414
+ for (var _i9 = 0; _i9 < nowMovePoints.length; _i9++) {
2415
+ var _nowMovePoints$_i = nowMovePoints[_i9],
2416
+ id = _nowMovePoints$_i.id,
2417
+ rx = _nowMovePoints$_i.rx,
2418
+ ry = _nowMovePoints$_i.ry,
2419
+ waitTime = _nowMovePoints$_i.waitTime,
2420
+ deleteTime = _nowMovePoints$_i.deleteTime,
2421
+ ddeg = _nowMovePoints$_i.ddeg;
2422
+
2423
+ var gc = t.GM.getGraphic(id);
2424
+ if (!gc || !gc._graphicsLayer) {
2425
+ clearInterval(t.moveToTimer);
2426
+ } else {
2427
+ var gg = gc.getGeometry();
2428
+ var tx = gg[0] + rx,
2429
+ ty = gg[1] + ry;
2430
+ gc.setGeometry([tx, ty]);
2431
+ t.movePoints[_i9].waitTime = 0;
2432
+ if (deleteTime <= 0) {
2433
+ deleteIndex.push(_i9);
2434
+ }
2435
+ }
2436
+ }
2437
+ deleteIndex.sort(function (a, b) {
2438
+ return b - a;
2439
+ });
2440
+ for (var _i10 = 0; _i10 < deleteIndex.length; _i10++) {
2441
+ t.movePoints.splice(deleteIndex[_i10], 1);
2442
+ }
2443
+ if (nowMovePoints.length == 0) {
2444
+ clearInterval(t.moveToTimer);
2445
+ }
2446
+ }, 10);
2447
+ }
2448
+ //点位移动动画效果
2449
+
2450
+ }, {
2451
+ key: 'moveTo',
2452
+ value: function moveTo(id, lnglat, delay, autoRotation, urlright, urlleft) {
2453
+ delay = delay || 3;
2454
+ var t = this,
2455
+ timer = 10;
2456
+ delay = eval(delay) * 1000;
2457
+ var count = delay / timer,
2458
+ gc = this.GM.getGraphic(id);
2459
+ var s = gc.geometry,
2460
+ e = { x: lnglat[0], y: lnglat[1] };
2461
+ if (t.equalsPoint(s, e)) {
2462
+ return false;
2463
+ } else {
2464
+ var ddeg = 0,
2465
+ url = null;
2466
+ //计算角度,旋转
2467
+ if (autoRotation) {
2468
+ //自己实现旋转
2469
+ ddeg = t.rotateDeg(gc.geometry, lnglat);
2470
+ if (urlleft && ddeg < -90 && ddeg > -270) {
2471
+ ddeg += 180;
2472
+ url = urlleft;
2473
+ } else {
2474
+ url = urlright;
2475
+ }
2476
+ gc.setStyle(new ol.style.Style({
2477
+ image: new ol.style.Icon({
2478
+ src: url,
2479
+ rotation: Math.PI / 180 * ddeg
2480
+ })
2481
+ }));
2482
+ }
2483
+ //拆分延迟移动定位
2484
+ var rx = (e.x - s.x) / count,
2485
+ ry = (e.y - s.y) / count;
2486
+ var isHave = false;
2487
+ for (var i = 0; i < t.movePoints.length; i++) {
2488
+ if (t.movePoints[i].id == id) {
2489
+ t.movePoints.splice(i, 1, {
2490
+ id: id,
2491
+ rx: rx,
2492
+ ry: ry,
2493
+ waitTime: 0,
2494
+ deleteTime: delay
2495
+ });
2496
+ isHave = true;
2497
+ }
2498
+ }
2499
+ if (!isHave) {
2500
+ t.movePoints.push({
2501
+ id: id,
2502
+ rx: rx,
2503
+ ry: ry,
2504
+ waitTime: 0,
2505
+ deleteTime: delay
2506
+ });
2507
+ }
2508
+ }
2509
+ }
2510
+ //点位角度旋转(以指向东(右)为0°)
2511
+
2512
+ }, {
2513
+ key: 'rotateDeg',
2514
+ value: function rotateDeg(sp, ep) {
2515
+ var t = this;
2516
+ var spLngLat = sp;
2517
+ if (Array.isArray(sp)) {
2518
+ spLngLat = new ol.geom.Point(sp[0], sp[1]);
2519
+ }
2520
+ var s = t.state.gis.getPixelFromCoordinate(spLngLat),
2521
+
2522
+ //获取当前点位的经纬度
2523
+ e = t.state.gis.getPixelFromCoordinate(new ol.geom.Point(ep[0], ep[1])),
2524
+ deg = 0;
2525
+ if (e.x != s.x) {
2526
+ var tan = (e.y - s.y) / (e.x - s.x),
2527
+ atan = Math.atan(tan);
2528
+ deg = atan * 360 / (2 * Math.PI);
2529
+ //degree correction;
2530
+ if (e.x < s.x) {
2531
+ deg = -deg + 90 + 90;
2532
+ } else {
2533
+ deg = -deg;
2534
+ }
2535
+ deg = -deg;
2536
+ } else {
2537
+ var disy = e.y - s.y;
2538
+ var bias = 0;
2539
+ if (disy > 0) bias = -1;else bias = 1;
2540
+ if (disy == 0) bias = 0;
2541
+ deg = -bias * 90;
2542
+ }
2543
+ return deg;
2544
+ }
2545
+ //对比对象数据是否相等
2546
+
2547
+ }, {
2548
+ key: 'deepEqual',
2549
+ value: function deepEqual(a, b) {
2550
+ return _immutable2.default.is(_immutable2.default.fromJS(a), _immutable2.default.fromJS(b));
2551
+ }
2552
+ //数据解析(分析,新增,更新,删除对应的数据)
2553
+
2554
+ }, {
2555
+ key: 'dataMatch',
2556
+ value: function dataMatch(oldData, newData, type) {
2557
+ var onlyOldData = Set(oldData).subtract(Set(newData)).toJS();
2558
+ var onlyNewData = Set(newData).subtract(Set(oldData)).toJS();
2559
+ var onlyOldIDs = onlyOldData.map(function (item) {
2560
+ return item[type];
2561
+ });
2562
+ var onlyNewIDs = onlyNewData.map(function (item) {
2563
+ return item[type];
2564
+ });
2565
+ var updateDataIDs = Set(onlyOldIDs).intersect(Set(onlyNewIDs)).toJS();
2566
+ var updatedData = onlyNewData.filter(function (item) {
2567
+ return updateDataIDs.indexOf(item[type]) > -1;
2568
+ });
2569
+ var replacedData = onlyOldData.filter(function (item) {
2570
+ return updateDataIDs.indexOf(item[type]) > -1;
2571
+ });
2572
+ var deletedDataIDs = onlyOldIDs.filter(function (oldID) {
2573
+ return updateDataIDs.indexOf(oldID) == -1;
2574
+ });
2575
+ var addedData = onlyNewData.filter(function (item) {
2576
+ return updateDataIDs.indexOf(item[type]) == -1;
2577
+ });
2578
+
2579
+ return { deletedDataIDs: deletedDataIDs, addedData: addedData, updatedData: updatedData, replacedData: replacedData };
2580
+ }
2581
+ //处理需要增加图元的数据(避免意外问题)
2582
+
2583
+ }, {
2584
+ key: 'dealAdd',
2585
+ value: function dealAdd(ary, ids) {
2586
+ var ads = [],
2587
+ otherupds = [];
2588
+ for (var i = 0; i < ary.length; i++) {
2589
+ if (ids.indexOf(ary[i].id) > -1) {
2590
+ otherupds.push(ary[i]);
2591
+ } else {
2592
+ ads.push(ary[i]);
2593
+ }
2594
+ }
2595
+ return { ads: ads, otherupds: otherupds };
2596
+ }
2597
+ //处理需要更新图元的数据(避免意外问题)
2598
+
2599
+ }, {
2600
+ key: 'dealUpdate',
2601
+ value: function dealUpdate(ary, ids) {
2602
+ var upds = [],
2603
+ otherads = [];
2604
+ for (var i = 0; i < ary.length; i++) {
2605
+ if (ids.indexOf(ary[i].id) > -1) {
2606
+ upds.push(ary[i]);
2607
+ } else {
2608
+ otherads.push(ary[i]);
2609
+ }
2610
+ }
2611
+ return { upds: upds, otherads: otherads };
2612
+ }
2613
+ }, {
2614
+ key: 'render',
2615
+ value: function render() {
2616
+ var t = this;
2617
+ var _map = this.props;
2618
+ return _react2.default.createElement('div', { id: _map.mapId, style: { width: '100%', height: '100%' } });
2619
+ }
2620
+ //初始化
2621
+
2622
+ }, {
2623
+ key: 'componentDidMount',
2624
+ value: function componentDidMount() {
2625
+ var t = this;
2626
+ t.loadMapComplete.then(function () {
2627
+ t.init();
2628
+ });
2629
+ }
2630
+ //已加载组件,收到新的参数时调用
2631
+
2632
+ }, {
2633
+ key: 'componentWillReceiveProps',
2634
+ value: function componentWillReceiveProps(nextProps, prevProps) {
2635
+ var t = this;
2636
+ //点/线旧数据
2637
+ var _t$state2 = t.state,
2638
+ pointIds = _t$state2.pointIds,
2639
+ lineIds = _t$state2.lineIds,
2640
+ polygonIds = _t$state2.polygonIds,
2641
+ circleIds = _t$state2.circleIds,
2642
+ drawIds = _t$state2.drawIds;
2643
+ var point = drawIds.point,
2644
+ polyline = drawIds.polyline,
2645
+ polygon = drawIds.polygon,
2646
+ circle = drawIds.circle,
2647
+ rectangle = drawIds.rectangle;
2648
+ //点/线新数据
2649
+
2650
+ var _nextProps$mapPoints = nextProps.mapPoints,
2651
+ mapPoints = _nextProps$mapPoints === undefined ? [] : _nextProps$mapPoints,
2652
+ _nextProps$mapLines = nextProps.mapLines,
2653
+ mapLines = _nextProps$mapLines === undefined ? [] : _nextProps$mapLines,
2654
+ _nextProps$mapPolygon = nextProps.mapPolygons,
2655
+ mapPolygons = _nextProps$mapPolygon === undefined ? [] : _nextProps$mapPolygon,
2656
+ _nextProps$mapCircles = nextProps.mapCircles,
2657
+ mapCircles = _nextProps$mapCircles === undefined ? [] : _nextProps$mapCircles,
2658
+ _nextProps$customized = nextProps.customizedBoundary,
2659
+ customizedBoundary = _nextProps$customized === undefined ? [] : _nextProps$customized,
2660
+ isOpenTrafficInfo = nextProps.isOpenTrafficInfo,
2661
+ boundaryName = nextProps.boundaryName,
2662
+ heatMapData = nextProps.heatMapData,
2663
+ mapVisiblePoints = nextProps.mapVisiblePoints,
2664
+ setVisiblePoints = nextProps.setVisiblePoints,
2665
+ setCenter = nextProps.setCenter,
2666
+ mapCenter = nextProps.mapCenter,
2667
+ setZoomLevel = nextProps.setZoomLevel,
2668
+ mapZoomLevel = nextProps.mapZoomLevel,
2669
+ setCluster = nextProps.setCluster,
2670
+ mapCluster = nextProps.mapCluster,
2671
+ isRangingTool = nextProps.isRangingTool,
2672
+ mapRangingTool = nextProps.mapRangingTool,
2673
+ isRemove = nextProps.isRemove,
2674
+ mapRemove = nextProps.mapRemove,
2675
+ mapDraw = nextProps.mapDraw,
2676
+ isDraw = nextProps.isDraw,
2677
+ isCloseDraw = nextProps.isCloseDraw,
2678
+ editGraphicId = nextProps.editGraphicId,
2679
+ isDoEdit = nextProps.isDoEdit,
2680
+ isEndEdit = nextProps.isEndEdit,
2681
+ mapPointCollection = nextProps.mapPointCollection,
2682
+ isclearAllPointCollection = nextProps.isclearAllPointCollection,
2683
+ isSetAreaRestriction = nextProps.isSetAreaRestriction,
2684
+ areaRestriction = nextProps.areaRestriction,
2685
+ isClearAreaRestriction = nextProps.isClearAreaRestriction,
2686
+ isClearAll = nextProps.isClearAll;
2687
+ // 等待地图加载
2688
+
2689
+ if (!t.state.mapCreated) return;
2690
+ /*点数据处理
2691
+ pointData[2]相同的点,执行刷新
2692
+ pointData[1]的数据在idsForGraphicId中不存在的,执行新增
2693
+ pointData[0]数据中多余的id,执行删除
2694
+ */
2695
+ if (mapPoints instanceof Array && t.props.mapPoints instanceof Array && !t.deepEqual(mapPoints, t.props.mapPoints)) {
2696
+ var oldMapPoints = t.props.mapPoints;
2697
+ var newMapPoints = mapPoints;
2698
+ //过滤编辑的图元
2699
+ if (!!t.editId) {
2700
+ oldMapPoints = t.props.mapPoints.filter(function (item) {
2701
+ return item.id !== editGraphicId;
2702
+ });
2703
+ newMapPoints = mapPoints.filter(function (item) {
2704
+ return item.id !== editGraphicId;
2705
+ });
2706
+ }
2707
+
2708
+ var _t$dataMatch = t.dataMatch(oldMapPoints, newMapPoints, 'id'),
2709
+ deletedDataIDs = _t$dataMatch.deletedDataIDs,
2710
+ addedData = _t$dataMatch.addedData,
2711
+ updatedData = _t$dataMatch.updatedData;
2712
+
2713
+ var _t$dealAdd = t.dealAdd(addedData, [].concat(_toConsumableArray(pointIds), _toConsumableArray(point))),
2714
+ ads = _t$dealAdd.ads,
2715
+ otherupds = _t$dealAdd.otherupds;
2716
+
2717
+ var _t$dealUpdate = t.dealUpdate(updatedData, [].concat(_toConsumableArray(pointIds), _toConsumableArray(point))),
2718
+ upds = _t$dealUpdate.upds,
2719
+ otherads = _t$dealUpdate.otherads;
2720
+ //删在增之前,(因为增加后会刷新pointIds的值,造成多删的问题)
2721
+
2722
+
2723
+ var _iteratorNormalCompletion = true;
2724
+ var _didIteratorError = false;
2725
+ var _iteratorError = undefined;
2726
+
2727
+ try {
2728
+ for (var _iterator = deletedDataIDs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
2729
+ var id = _step.value;
2730
+
2731
+ t.removeGraphic(id, 'point');
2732
+ }
2733
+ //增加
2734
+ } catch (err) {
2735
+ _didIteratorError = true;
2736
+ _iteratorError = err;
2737
+ } finally {
2738
+ try {
2739
+ if (!_iteratorNormalCompletion && _iterator.return) {
2740
+ _iterator.return();
2741
+ }
2742
+ } finally {
2743
+ if (_didIteratorError) {
2744
+ throw _iteratorError;
2745
+ }
2746
+ }
2747
+ }
2748
+
2749
+ t.addPoint([].concat(_toConsumableArray(ads), _toConsumableArray(otherads)));
2750
+ //更新
2751
+ t.updatePoint([].concat(_toConsumableArray(upds), _toConsumableArray(otherupds)));
2752
+ }
2753
+ /*
2754
+ 线数据处理
2755
+ 先全删除,再新增
2756
+ */
2757
+ if (mapLines instanceof Array && t.props.mapLines instanceof Array && !t.deepEqual(mapLines, t.props.mapLines)) {
2758
+ var oldMapLines = t.props.mapLines;
2759
+ var newMapLines = mapLines;
2760
+ if (!!t.editId) {
2761
+ oldMapLines = t.props.mapLines.filter(function (item) {
2762
+ return item.id !== editGraphicId;
2763
+ });
2764
+ newMapLines = mapLines.filter(function (item) {
2765
+ return item.id !== editGraphicId;
2766
+ });
2767
+ }
2768
+
2769
+ var _t$dataMatch2 = t.dataMatch(oldMapLines, newMapLines, 'id'),
2770
+ _deletedDataIDs = _t$dataMatch2.deletedDataIDs,
2771
+ _addedData = _t$dataMatch2.addedData,
2772
+ _updatedData = _t$dataMatch2.updatedData;
2773
+
2774
+ var _t$dealAdd2 = t.dealAdd(_addedData, [].concat(_toConsumableArray(lineIds), _toConsumableArray(polyline))),
2775
+ _ads = _t$dealAdd2.ads,
2776
+ _otherupds = _t$dealAdd2.otherupds;
2777
+
2778
+ var _t$dealUpdate2 = t.dealUpdate(_updatedData, [].concat(_toConsumableArray(lineIds), _toConsumableArray(polyline))),
2779
+ _upds = _t$dealUpdate2.upds,
2780
+ _otherads = _t$dealUpdate2.otherads;
2781
+ //删在增之前,(因为增加后会刷新pointIds的值,造成多删的问题)
2782
+
2783
+
2784
+ var _iteratorNormalCompletion2 = true;
2785
+ var _didIteratorError2 = false;
2786
+ var _iteratorError2 = undefined;
2787
+
2788
+ try {
2789
+ for (var _iterator2 = _deletedDataIDs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
2790
+ var _id = _step2.value;
2791
+
2792
+ t.removeGraphic(_id, 'line');
2793
+ }
2794
+ //增加
2795
+ } catch (err) {
2796
+ _didIteratorError2 = true;
2797
+ _iteratorError2 = err;
2798
+ } finally {
2799
+ try {
2800
+ if (!_iteratorNormalCompletion2 && _iterator2.return) {
2801
+ _iterator2.return();
2802
+ }
2803
+ } finally {
2804
+ if (_didIteratorError2) {
2805
+ throw _iteratorError2;
2806
+ }
2807
+ }
2808
+ }
2809
+
2810
+ t.addLine([].concat(_toConsumableArray(_ads), _toConsumableArray(_otherads)));
2811
+ //更新
2812
+ t.updateLine([].concat(_toConsumableArray(_upds), _toConsumableArray(_otherupds)));
2813
+ }
2814
+ /*
2815
+ 面数据处理
2816
+ 先全删除,再新增
2817
+ */
2818
+ if (mapPolygons instanceof Array && t.props.mapPolygons instanceof Array && !t.deepEqual(mapPolygons, t.props.mapPolygons)) {
2819
+ var oldMapPolygons = t.props.mapPolygons;
2820
+ var newMapPolygons = mapPolygons;
2821
+ if (!!t.editId) {
2822
+ oldMapPolygons = t.props.mapPolygons.filter(function (item) {
2823
+ return item.id !== editGraphicId;
2824
+ });
2825
+ newMapPolygons = mapPolygons.filter(function (item) {
2826
+ return item.id !== editGraphicId;
2827
+ });
2828
+ }
2829
+
2830
+ var _t$dataMatch3 = t.dataMatch(oldMapPolygons, newMapPolygons, 'id'),
2831
+ _deletedDataIDs2 = _t$dataMatch3.deletedDataIDs,
2832
+ _addedData2 = _t$dataMatch3.addedData,
2833
+ _updatedData2 = _t$dataMatch3.updatedData;
2834
+
2835
+ var _t$dealAdd3 = t.dealAdd(_addedData2, [].concat(_toConsumableArray(rectangle), _toConsumableArray(polygon), _toConsumableArray(polygonIds))),
2836
+ _ads2 = _t$dealAdd3.ads,
2837
+ _otherupds2 = _t$dealAdd3.otherupds;
2838
+
2839
+ var _t$dealUpdate3 = t.dealUpdate(_updatedData2, [].concat(_toConsumableArray(rectangle), _toConsumableArray(polygon), _toConsumableArray(polygonIds))),
2840
+ _upds2 = _t$dealUpdate3.upds,
2841
+ _otherads2 = _t$dealUpdate3.otherads;
2842
+ //删在增之前,(因为增加后会刷新pointIds的值,造成多删的问题)
2843
+
2844
+
2845
+ var _iteratorNormalCompletion3 = true;
2846
+ var _didIteratorError3 = false;
2847
+ var _iteratorError3 = undefined;
2848
+
2849
+ try {
2850
+ for (var _iterator3 = _deletedDataIDs2[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
2851
+ var _id2 = _step3.value;
2852
+
2853
+ t.removeGraphic(_id2, 'polygon');
2854
+ }
2855
+ //增加
2856
+ } catch (err) {
2857
+ _didIteratorError3 = true;
2858
+ _iteratorError3 = err;
2859
+ } finally {
2860
+ try {
2861
+ if (!_iteratorNormalCompletion3 && _iterator3.return) {
2862
+ _iterator3.return();
2863
+ }
2864
+ } finally {
2865
+ if (_didIteratorError3) {
2866
+ throw _iteratorError3;
2867
+ }
2868
+ }
2869
+ }
2870
+
2871
+ t.addPolygon([].concat(_toConsumableArray(_ads2), _toConsumableArray(_otherads2)));
2872
+ //更新
2873
+ t.updatePolygon([].concat(_toConsumableArray(_upds2), _toConsumableArray(_otherupds2)));
2874
+ }
2875
+ /*
2876
+ 圆数据处理
2877
+ 先全删除,再新增
2878
+ */
2879
+ if (mapCircles instanceof Array && t.props.mapCircles instanceof Array && !t.deepEqual(mapCircles, t.props.mapCircles)) {
2880
+ var oldMapCircles = t.props.mapCircles;
2881
+ var newMapCircles = mapCircles;
2882
+ if (!!t.editId) {
2883
+ oldMapCircles = t.props.mapCircles.filter(function (item) {
2884
+ return item.id !== editGraphicId;
2885
+ });
2886
+ newMapCircles = mapCircles.filter(function (item) {
2887
+ return item.id !== editGraphicId;
2888
+ });
2889
+ }
2890
+
2891
+ var _t$dataMatch4 = t.dataMatch(oldMapCircles, newMapCircles, 'id'),
2892
+ _deletedDataIDs3 = _t$dataMatch4.deletedDataIDs,
2893
+ _addedData3 = _t$dataMatch4.addedData,
2894
+ _updatedData3 = _t$dataMatch4.updatedData;
2895
+
2896
+ var _t$dealAdd4 = t.dealAdd(_addedData3, [].concat(_toConsumableArray(circleIds), _toConsumableArray(circle))),
2897
+ _ads3 = _t$dealAdd4.ads,
2898
+ _otherupds3 = _t$dealAdd4.otherupds;
2899
+
2900
+ var _t$dealUpdate4 = t.dealUpdate(_updatedData3, [].concat(_toConsumableArray(circleIds), _toConsumableArray(circle))),
2901
+ _upds3 = _t$dealUpdate4.upds,
2902
+ _otherads3 = _t$dealUpdate4.otherads;
2903
+ //删在增之前,(因为增加后会刷新pointIds的值,造成多删的问题)
2904
+
2905
+
2906
+ var _iteratorNormalCompletion4 = true;
2907
+ var _didIteratorError4 = false;
2908
+ var _iteratorError4 = undefined;
2909
+
2910
+ try {
2911
+ for (var _iterator4 = _deletedDataIDs3[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
2912
+ var _id3 = _step4.value;
2913
+
2914
+ t.removeGraphic(_id3, 'circle');
2915
+ }
2916
+ //增加
2917
+ } catch (err) {
2918
+ _didIteratorError4 = true;
2919
+ _iteratorError4 = err;
2920
+ } finally {
2921
+ try {
2922
+ if (!_iteratorNormalCompletion4 && _iterator4.return) {
2923
+ _iterator4.return();
2924
+ }
2925
+ } finally {
2926
+ if (_didIteratorError4) {
2927
+ throw _iteratorError4;
2928
+ }
2929
+ }
2930
+ }
2931
+
2932
+ t.addCircle([].concat(_toConsumableArray(_ads3), _toConsumableArray(_otherads3)));
2933
+ //更新
2934
+ t.updateCircle([].concat(_toConsumableArray(_upds3), _toConsumableArray(_otherupds3)));
2935
+ }
2936
+ //图元编辑调用
2937
+ if (typeof isDoEdit == 'boolean' && isDoEdit || isDoEdit && isDoEdit !== t.props.isDoEdit) {
2938
+ t.doEdit(editGraphicId);
2939
+ }
2940
+ // 获取热力图
2941
+ if (heatMapData && !t.deepEqual(heatMapData, t.props.heatMapData)) {
2942
+ t.heatMapOverlay(heatMapData);
2943
+ }
2944
+ //清空地图
2945
+ if (typeof isClearAll == 'boolean' && isClearAll || isClearAll && isClearAll !== t.props.isClearAll) {
2946
+ t.clearAll();
2947
+ }
2948
+ //测距工具调用
2949
+ if (typeof isRangingTool == 'boolean' && isRangingTool || isRangingTool && isRangingTool !== t.props.isRangingTool) {
2950
+ t.vtxRangingTool(mapRangingTool);
2951
+ }
2952
+ /*设置指定图元展示*/
2953
+ if (typeof setVisiblePoints == 'boolean' && setVisiblePoints || setVisiblePoints && setVisiblePoints !== t.props.setVisiblePoints) {
2954
+ t.setVisiblePoints(mapVisiblePoints);
2955
+ }
2956
+ //设置中心点
2957
+ if (typeof setCenter == 'boolean' && setCenter || setCenter && setCenter !== t.props.setCenter) {
2958
+ if (!(t.getCurrentCenter().lng == mapCenter[0] && t.getCurrentCenter().lat == mapCenter[1])) {
2959
+ t.setCenter(mapCenter);
2960
+ }
2961
+ }
2962
+ //设置点聚合
2963
+ if (typeof setCluster == 'boolean' && setCluster || setCluster && setCluster !== t.props.setCluster) {
2964
+ t.cluster(mapCluster);
2965
+ }
2966
+ //图元编辑调用
2967
+ if (typeof isDoEdit == 'boolean' && isDoEdit || isDoEdit && isDoEdit !== t.props.isDoEdit) {
2968
+ t.doEdit(editGraphicId);
2969
+ }
2970
+ //关闭图元编辑
2971
+ if (typeof isEndEdit == 'boolean' && isEndEdit || isEndEdit && isEndEdit !== t.props.isEndEdit) {
2972
+ t.endEdit();
2973
+ }
2974
+ //绘制图元
2975
+ if (typeof isDraw == 'boolean' && isDraw || isDraw && isDraw !== t.props.isDraw) {
2976
+ t.draw(mapDraw);
2977
+ }
2978
+ //关闭绘制
2979
+ if (typeof isCloseDraw == 'boolean' && isCloseDraw || isCloseDraw && isCloseDraw !== t.props.isCloseDraw) {
2980
+ t.closeDraw();
2981
+ }
2982
+ //单独删除操作
2983
+ if (typeof isRemove == 'boolean' && isRemove || isRemove && isRemove !== t.props.isRemove) {
2984
+ mapRemove.map(function (item, index) {
2985
+ t.removeGraphic(item.id, item.type);
2986
+ });
2987
+ }
2988
+ //设置区域限制
2989
+ if (typeof isSetAreaRestriction == 'boolean' && isSetAreaRestriction || isSetAreaRestriction && isSetAreaRestriction !== t.props.isSetAreaRestriction && areaRestriction && !!areaRestriction[0] && !!areaRestriction[1]) {
2990
+ t.setAreaRestriction(areaRestriction);
2991
+ }
2992
+ //关闭区域限制
2993
+ if (typeof isClearAreaRestriction == 'boolean' && isClearAreaRestriction || isClearAreaRestriction && isClearAreaRestriction !== t.props.isClearAreaRestriction) {
2994
+ t.clearAreaRestriction();
2995
+ }
2996
+ }
2997
+ // 地图事件
2998
+ //地图点击事件
2999
+
3000
+ }, {
3001
+ key: 'clickMap',
3002
+ value: function clickMap(e) {
3003
+ var t = this;
3004
+ if (typeof t.props.clickMap === 'function') {
3005
+ var obj = t.getMapExtent();
3006
+ obj.e = e;
3007
+ obj.clickLngLat = {
3008
+ lng: (e.mapPoint || {}).x,
3009
+ lat: (e.mapPoint || {}).y
3010
+ };
3011
+ obj.pixel = {
3012
+ x: (e.screenPoint || {}).x,
3013
+ y: (e.screenPoint || {}).y
3014
+ };
3015
+ t.props.clickMap(obj);
3016
+ }
3017
+ }
3018
+ // 要素鼠标悬浮事件
3019
+
3020
+ }, {
3021
+ key: 'mouseOverGraphic',
3022
+ value: function mouseOverGraphic(id, e) {
3023
+ var t = this;
3024
+ if (t.state.editId == id) return false;
3025
+ if (typeof t.props.mouseOverGraphic === 'function') {
3026
+ var obj = {
3027
+ e: e,
3028
+ id: id,
3029
+ param: t.getGraphic(id),
3030
+ top: e.pixel_ ? e.pixel_[0] : undefined, //当前点所在的位置(屏幕)
3031
+ left: e.pixel_ ? e.pixel_[1] : undefined
3032
+ };
3033
+ t.props.mouseOverGraphic(obj);
3034
+ }
3035
+ }
3036
+ // 要素鼠标移开事件
3037
+
3038
+ }, {
3039
+ key: 'mouseOutGraphic',
3040
+ value: function mouseOutGraphic(id, e) {
3041
+ var t = this;
3042
+ //编辑中的图元关闭其他事件返回
3043
+ if (t.state.editId == id) return false;
3044
+ if (typeof t.props.mouseOutGraphic === 'function') {
3045
+ var obj = {
3046
+ e: e,
3047
+ id: id,
3048
+ param: t.getGraphic(id),
3049
+ top: e.pixel_ ? e.pixel_[0] : undefined, //当前点所在的位置(屏幕)
3050
+ left: e.pixel_ ? e.pixel_[1] : undefined
3051
+ };
3052
+ t.props.mouseOutGraphic(obj);
3053
+ }
3054
+ }
3055
+ //地图拖动之前事件
3056
+
3057
+ }, {
3058
+ key: 'dragMapStart',
3059
+ value: function dragMapStart(e) {
3060
+ var t = this;
3061
+ if (typeof t.props.dragMapStart === 'function') {
3062
+ var obj = t.getMapExtent();
3063
+ obj.e = e;
3064
+ t.props.dragMapStart(obj);
3065
+ }
3066
+ }
3067
+ //地图拖动结束后事件
3068
+
3069
+ }, {
3070
+ key: 'dragMapEnd',
3071
+ value: function dragMapEnd(e) {
3072
+ var t = this;
3073
+ if (typeof t.props.dragMapEnd === 'function') {
3074
+ var obj = t.getMapExtent();
3075
+ obj.e = e;
3076
+ t.props.dragMapEnd(obj);
3077
+ }
3078
+ }
3079
+ //热力图
3080
+
3081
+ }, {
3082
+ key: 'heatMapOverlay',
3083
+ value: function heatMapOverlay() {
3084
+ var d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3085
+
3086
+ var t = this;
3087
+ var cg = {
3088
+ radius: 20,
3089
+ max: 100,
3090
+ visible: true,
3091
+ opacity: 0.7,
3092
+ gradient: ['#00f', '#0ff', '#0f0', '#ff0', '#f00']
3093
+ };
3094
+ if (d.config) {
3095
+ cg = _extends({}, cg, d.config);
3096
+ }
3097
+ var gradient = [];
3098
+ if (cg.gradient) {
3099
+ for (var key in cg.gradient) {
3100
+ gradient.push(cg.gradient[key]);
3101
+ }
3102
+ cg.gradient = gradient;
3103
+ }
3104
+ var heatData = {
3105
+ type: 'FeatureCollection',
3106
+ features: (d.data || []).map(function (item) {
3107
+ return {
3108
+ type: 'Feature',
3109
+ properties: {
3110
+ weight: item.count ? item.count / 100 : 0.5
3111
+ },
3112
+ geometry: {
3113
+ type: 'Point',
3114
+ coordinates: [item.lng, item.lat]
3115
+ }
3116
+ };
3117
+ })
3118
+ };
3119
+ var heatSource = new ol.source.Vector({
3120
+ features: new ol.format.GeoJSON().readFeatures(heatData)
3121
+ });
3122
+ t.heatmap = new ol.layer.Heatmap({
3123
+ name: 'heatmap',
3124
+ source: heatSource,
3125
+ radius: cg.radius,
3126
+ visible: cg.visible,
3127
+ blur: eval(cg.opacity) * 100,
3128
+ gradient: gradient,
3129
+ weight: function weight(e) {
3130
+ return e.getProperties().count; //根据权重展示热力图!关键点,weight范围为:0-1!!!
3131
+ }
3132
+ });
3133
+ t.state.gis.addLayer(t.heatmap);
3134
+ }
3135
+ //地图移动之前事件
3136
+
3137
+ }, {
3138
+ key: 'moveStart',
3139
+ value: function moveStart(e) {
3140
+ var t = this;
3141
+ if (typeof t.props.moveStart === 'function') {
3142
+ var obj = t.getMapExtent();
3143
+ obj.e = e;
3144
+ t.props.moveStart(obj);
3145
+ }
3146
+ }
3147
+ //地图移动结束后事件
3148
+
3149
+ }, {
3150
+ key: 'moveEnd',
3151
+ value: function moveEnd(e) {
3152
+ var t = this;
3153
+ if (typeof t.props.moveEnd === 'function') {
3154
+ var obj = t.getMapExtent();
3155
+ obj.e = e;
3156
+ t.props.moveEnd(obj);
3157
+ }
3158
+ }
3159
+ //地图更改缩放级别开始时触发触发此事件
3160
+
3161
+ }, {
3162
+ key: 'zoomStart',
3163
+ value: function zoomStart(e) {
3164
+ var t = this;
3165
+ if (typeof t.props.zoomStart === 'function') {
3166
+ var obj = t.getMapExtent();
3167
+ obj.e = e;
3168
+ t.props.zoomStart(obj);
3169
+ }
3170
+ }
3171
+ //地图更改缩放级别结束时触发触发此事件
3172
+
3173
+ }, {
3174
+ key: 'zoomEnd',
3175
+ value: function zoomEnd(e) {
3176
+ var t = this;
3177
+ if (typeof t.props.zoomEnd === 'function') {
3178
+ var obj = t.getMapExtent();
3179
+ obj.e = e;
3180
+ t.props.zoomEnd(obj);
3181
+ }
3182
+ }
3183
+ // 图元点击事件
3184
+
3185
+ }, {
3186
+ key: 'clickGraphic',
3187
+ value: function clickGraphic(id, e) {
3188
+ var t = this;
3189
+ if (id) {
3190
+ //编辑中的图元关闭其他事件返回
3191
+ if (t.editId == id) return false;
3192
+ if (typeof t.props.clickGraphic === 'function') {
3193
+ var _e$pixel_ = _slicedToArray(e.pixel_, 2),
3194
+ clientX = _e$pixel_[0],
3195
+ clientY = _e$pixel_[1];
3196
+
3197
+ var param = t.getGraphic(id, clientX, clientY);
3198
+ var obj = {
3199
+ param: param,
3200
+ type: param.geometry.type, //图元类型
3201
+ attributes: _extends({}, param.attributes.other, { config: param.attributes.config }), //添加时图元信息
3202
+ top: clientY, //当前点所在的位置(屏幕)
3203
+ left: clientX,
3204
+ e: e
3205
+ };
3206
+ t.props.clickGraphic(obj);
3207
+ }
3208
+ }
3209
+ }
3210
+ }, {
3211
+ key: 'componentWillUnmount',
3212
+ value: function componentWillUnmount() {
3213
+ //关闭moveTo定时
3214
+ var t = this;
3215
+ if (t.moveToTimer) {
3216
+ clearInterval(t.moveToTimer);
3217
+ }
3218
+ //关闭animation定时
3219
+ for (var j in t.animTimer) {
3220
+ if (t.animTimer[j]) {
3221
+ clearInterval(t.animTimer[j]);
3222
+ }
3223
+ }
3224
+ window.OlMap[t.state.mapId] = null;
3225
+ }
3226
+ }]);
3227
+
3228
+ return OlMap;
3229
+ }(_react2.default.Component);
3230
+
3231
+ exports.default = OlMap;
3232
+
3233
+
3234
+ function getRgbColor(color, opacity) {
3235
+ var reg = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
3236
+ if (!reg.test(color)) {
3237
+ return;
3238
+ }
3239
+ var newStr = color.toLowerCase().replace(/\#/g, '');
3240
+ var len = newStr.length;
3241
+ if (len == 3) {
3242
+ var t = '';
3243
+ for (var i = 0; i < len; i++) {
3244
+ t += newStr.slice(i, i + 1).concat(newStr.slice(i, i + 1));
3245
+ }
3246
+ newStr = t;
3247
+ }
3248
+ var arr = []; //将字符串分隔,两个两个的分隔
3249
+ for (var i = 0; i < 6; i = i + 2) {
3250
+ var s = newStr.slice(i, i + 2);
3251
+ arr.push(parseInt('0x' + s));
3252
+ }
3253
+ return 'rgba(' + arr.join(',') + ',' + opacity + ')';
3254
+ }
3255
+ module.exports = exports['default'];