@vtx/map 1.0.3

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