@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,3932 @@
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('./Map.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 Map = function (_React$Component) {
41
+ _inherits(Map, _React$Component);
42
+
43
+ function Map(props) {
44
+ _classCallCheck(this, Map);
45
+
46
+ var _this = _possibleConstructorReturn(this, (Map.__proto__ || Object.getPrototypeOf(Map)).call(this, props));
47
+
48
+ _this.GM = new _MapToolFunction.graphicManage(); //初始化 图元管理方法
49
+ _this.initPointIndex = 0; //初始化地图时记录点当前位置
50
+ _this._cluster = null; //点聚合对象
51
+ _this.clusterIdList = []; //点聚合id集合
52
+ _this._rangingTool = null; //测距对象
53
+ _this._bmar = null; //区域限制对象
54
+ _this._drawmanager = null; //图元绘制对象
55
+ _this.editGraphicChange = null; //编辑方法回调
56
+ _this.editTimeout = null; //圆编辑回调延迟时间对象
57
+ _this._boundary = null; //获取行政区域数据的对象
58
+ _this.moveToTimer = null; //moveTo时间对象
59
+ _this.heatmap = null; //热力图对象
60
+ _this.morepoints = []; //海量点数组
61
+ _this.movePoints = []; //移动点的动画集合
62
+ _this.editEvent = {}; //编辑监听的事件
63
+ //是否绘制测距
64
+ _this.rangingTool = {
65
+ isRanging: false, //是否开启状态
66
+ line: {}, //线
67
+ points: [], //点
68
+ distance: 0, //测距长度
69
+ mapRangingTool: null, //测距回调
70
+ eventList: {},
71
+ isDbclick: false
72
+ };
73
+ _this.rangingTools = {}; //测距点线缓存
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
+ boundaryInfo: [], //当前画出的边界线的id和区域名
85
+ drawIds: { //绘制工具id集合
86
+ point: [],
87
+ polyline: [],
88
+ polygon: [],
89
+ circle: [],
90
+ rectangle: []
91
+ }
92
+ };
93
+ _this.cacheImgRecord = {}; //缓存图片记录,避免多次加载缓存
94
+ // 图片缓存dom位置
95
+ var cacheImg = document.getElementById('vtxomapdefaultimg');
96
+ if (!cacheImg) {
97
+ cacheImg = _this.cacheImg = document.createElement('div');
98
+ cacheImg.id = 'vtxomapcacheImg';
99
+ cacheImg.style.display = 'none';
100
+ document.body.appendChild(cacheImg);
101
+ }
102
+ _this.cacheImg = cacheImg;
103
+ //缓存默认点位地址
104
+ if (!document.getElementById('vtxomapdefaultimg')) {
105
+ var defImg = new Image();
106
+ defImg.src = _default2.default.mapServerURL + '/images/defaultMarker.png';
107
+ defImg.id = 'vtxomapdefaultimg';
108
+ cacheImg.appendChild(defImg);
109
+ }
110
+ //加载地图
111
+ _this.loadMapJs();
112
+ return _this;
113
+ }
114
+
115
+ _createClass(Map, [{
116
+ key: 'loadMapJs',
117
+ value: function loadMapJs() {
118
+ var t = this;
119
+ this.loadMapComplete = new Promise(function (resolve, reject) {
120
+ if (window.google) {
121
+ resolve(t.omap = window.google.maps);
122
+ } else {
123
+ //&language=zh-CN
124
+ //测试用地址,暂时只支持 10.10.11.227的ip
125
+ $.getScript('http://ditu.google.cn/maps/api/js?key=AIzaSyAelEHQosKi09YLhXwmw3OR5ggScxOda2A&libraries=geometry,visualization,drawing', function () {
126
+ var PointCollection = new Promise(function (resolve, reject) {
127
+ $.getScript(_default2.default.mapServerURL + '/GPointCollection.js', function () {
128
+ resolve();
129
+ });
130
+ });
131
+ var OmapCluster = new Promise(function (resolve, reject) {
132
+ $.getScript(_default2.default.mapServerURL + '/omapCluster.js', function () {
133
+ resolve();
134
+ });
135
+ });
136
+ Promise.all([PointCollection, OmapCluster]).then(function () {
137
+ resolve(t.omap = window.google.maps);
138
+ });
139
+ });
140
+ }
141
+ });
142
+ }
143
+ //初始化地图数据
144
+
145
+ }, {
146
+ key: 'init',
147
+ value: function init() {
148
+ var t = this;
149
+ //创建地图
150
+ t.createMap();
151
+ var _props = this.props,
152
+ mapPoints = _props.mapPoints,
153
+ mapLines = _props.mapLines,
154
+ mapPolygons = _props.mapPolygons,
155
+ mapCircles = _props.mapCircles,
156
+ mapVisiblePoints = _props.mapVisiblePoints,
157
+ mapCluster = _props.mapCluster,
158
+ mapZoomLevel = _props.mapZoomLevel,
159
+ isOpenTrafficInfo = _props.isOpenTrafficInfo,
160
+ mapPointCollection = _props.mapPointCollection,
161
+ areaRestriction = _props.areaRestriction;
162
+ var _props2 = this.props,
163
+ boundaryName = _props2.boundaryName,
164
+ heatMapData = _props2.heatMapData,
165
+ customizedBoundary = _props2.customizedBoundary;
166
+ var _state = this.state,
167
+ boundaryInfo = _state.boundaryInfo,
168
+ pointIds = _state.pointIds,
169
+ lineIds = _state.lineIds,
170
+ polygonIds = _state.polygonIds,
171
+ circleIds = _state.circleIds;
172
+ // //添加点
173
+
174
+ if (mapPoints instanceof Array) {
175
+ t.addPoint(mapPoints);
176
+ }
177
+ //添加线
178
+ if (mapLines instanceof Array) {
179
+ t.addLine(mapLines);
180
+ }
181
+ //添加面
182
+ if (mapPolygons instanceof Array) {
183
+ t.addPolygon(mapPolygons);
184
+ }
185
+ //添加圆
186
+ if (mapCircles instanceof Array) {
187
+ t.addCircle(mapCircles);
188
+ }
189
+ // 画热力图
190
+ if (heatMapData) {
191
+ t.heatMapOverlay(heatMapData);
192
+ }
193
+ if (mapPointCollection instanceof Array) {
194
+ t.addPointCollection(mapPointCollection);
195
+ }
196
+ /*设置指定图元展示*/
197
+ if (mapVisiblePoints) {
198
+ t.setVisiblePoints(mapVisiblePoints);
199
+ }
200
+ //设置点聚合
201
+ if (mapCluster instanceof Array) {
202
+ t.cluster(mapCluster);
203
+ }
204
+ //开关路况
205
+ if (isOpenTrafficInfo) {
206
+ t.openTrafficInfo();
207
+ } else {
208
+ t.hideTrafficInfo();
209
+ }
210
+ /*地图事件*/
211
+ //初始化地图点击事件
212
+ t.clickMap();
213
+ //地图拖动之前事件
214
+ t.dragMapStart();
215
+ // //地图拖动结束后事件
216
+ t.dragMapEnd();
217
+ // //地图移动之前事件
218
+ t.moveStart();
219
+ // //地图缩放开始前事件
220
+ t.zoomStart();
221
+ // //地图移动结束后事件/地图缩放结束后事件
222
+ t.moveEndAndZoomEnd();
223
+
224
+ t.setState({
225
+ mapCreated: true
226
+ });
227
+ }
228
+ //创建地图
229
+
230
+ }, {
231
+ key: 'createMap',
232
+ value: function createMap() {
233
+ var t = this;
234
+ var _t$props = t.props,
235
+ mapCenter = _t$props.mapCenter,
236
+ mapId = _t$props.mapId,
237
+ mapZoomLevel = _t$props.mapZoomLevel,
238
+ minZoom = _t$props.minZoom,
239
+ maxZoom = _t$props.maxZoom,
240
+ showControl = _t$props.showControl,
241
+ areaRestriction = _t$props.areaRestriction;
242
+
243
+ var options = {
244
+ zoom: mapZoomLevel || 10,
245
+ center: mapCenter || [626.3002300508477, 37.90942995363547],
246
+ minZoom: minZoom || 0,
247
+ maxZoom: maxZoom || 22
248
+ };
249
+ //缓存 zoom等级,用于事件判断
250
+ t.oldZoomLevel = options.zoom;
251
+ if (window.VtxMap) {
252
+ window.VtxMap[mapId] = null;
253
+ } else {
254
+ window.VtxMap = {};
255
+ }
256
+ // 地图控件处理
257
+ var isShowControl = false,
258
+ controlPosition = t.matchControlPosition();
259
+ if (showControl) {
260
+ controlPosition = t.matchControlPosition(showControl.location);
261
+ isShowControl = !!showControl;
262
+ }
263
+ var latLngBounds = [];
264
+ if (areaRestriction && Array.isArray(areaRestriction) && Array.isArray(areaRestriction[0])) {
265
+ //处理 区域限制数据
266
+ latLngBounds = [areaRestriction[0][0], areaRestriction[0][1], areaRestriction[1][0], areaRestriction[1][1]];
267
+ latLngBounds.sort(function (a, b) {
268
+ return a - b;
269
+ });
270
+ }
271
+ //创建地图 缓存地图对象
272
+ var map = window.VtxMap[mapId] = t.state.gis = new t.omap.Map(document.getElementById(mapId.toString()), {
273
+ center: { lng: options.center[0], lat: options.center[1] },
274
+ disableDoubleClickZoom: false,
275
+ draggableCursor: 'url("http://maps.gstatic.cn/mapfiles/openhand_8_8.cur"), default',
276
+ zoom: options.zoom,
277
+ minZoom: options.minZoom,
278
+ maxZoom: options.maxZoom,
279
+ controlSize: 24,
280
+ //全屏控件-禁用
281
+ rotateControl: isShowControl,
282
+ scaleControl: isShowControl,
283
+ streetViewControl: isShowControl,
284
+ fullscreenControl: isShowControl,
285
+ mapTypeControl: isShowControl,
286
+ zoomControl: isShowControl,
287
+ rotateControlOptions: { position: controlPosition },
288
+ streetViewControlOptions: { position: controlPosition },
289
+ fullscreenControlOptions: { position: controlPosition },
290
+ zoomControlOptions: { position: controlPosition },
291
+ mapTypeControlOptions: { position: google.maps.ControlPosition.TOP_CENTER },
292
+ //区域限制
293
+ restriction: {
294
+ latLngBounds: {
295
+ north: latLngBounds[1] || 90,
296
+ south: latLngBounds[0] || -90,
297
+ west: latLngBounds[2] || -180,
298
+ east: latLngBounds[3] || 180
299
+ },
300
+ strictBounds: false
301
+ }
302
+ });
303
+ /*=================================start========================================*/
304
+ /*
305
+ draw对象声明, 绘制返回方法实现
306
+ */
307
+ if (!t._drawmanager) {
308
+ t._drawmanager = new google.maps.drawing.DrawingManager({
309
+ drawingControl: false
310
+ });
311
+ t._drawmanager.setMap(t.state.gis);
312
+ }
313
+ /*=================================start========================================*/
314
+ //初始化点聚合对象
315
+ if (!t._cluster) {
316
+ t._cluster = new OMapLib.MarkerClusterer(map, [], { maxZoom: options.maxZoom });
317
+ }
318
+ /*=================================start========================================*/
319
+ /*
320
+ 声明OverlayView 类
321
+ 用于切换lnglat和 pixel
322
+ */
323
+ function CanvasProjectionOverlay() {}
324
+ CanvasProjectionOverlay.prototype = new google.maps.OverlayView();
325
+ CanvasProjectionOverlay.prototype.constructor = CanvasProjectionOverlay;
326
+ CanvasProjectionOverlay.prototype.onAdd = function () {};
327
+ CanvasProjectionOverlay.prototype.draw = function () {};
328
+ CanvasProjectionOverlay.prototype.onRemove = function () {};
329
+ this.canvasProjectionOverlay = new CanvasProjectionOverlay();
330
+ this.canvasProjectionOverlay.setMap(map);
331
+ /*=================================start========================================*/
332
+ /*
333
+ 重写marker对象,支持html
334
+ 要使用google对象,所以在creatMap中声明
335
+ */
336
+ var MyLabel = t.MyLabel = function (map) {
337
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
338
+
339
+ //编辑
340
+ this.editable = options.editable || false;
341
+ this.editParam = {
342
+ sx: 0,
343
+ sy: 0
344
+ };
345
+ //地图
346
+ this.map = map;
347
+ this.isLabel = options.isLabel;
348
+ //基本参数
349
+ this.labelClass = options.labelClass;
350
+ this.labelContent = options.labelContent;
351
+ this.labelOffset = options.labelOffset || { x: 0, y: 0 };
352
+ this.lnglat = options.lnglat;
353
+
354
+ this._label = null;
355
+
356
+ this.funs = {};
357
+ };
358
+ //继承OverlayView类
359
+ MyLabel.prototype = new google.maps.OverlayView();
360
+ //添加地图时被调用(setMap时被调用)
361
+ MyLabel.prototype.onAdd = function () {
362
+ //创建文字标签
363
+ if (!this._label) {
364
+ this._label = document.createElement('div');
365
+ this._label.innerHTML = this.labelContent;
366
+ this._label.style.position = 'absolute';
367
+ this._label.className = this.labelClass;
368
+ //获取承载点位的框
369
+ var panes = this.getPanes();
370
+ if (this.isLabel) {
371
+ panes.markerLayer.appendChild(this._label);
372
+ } else {
373
+ panes.overlayMouseTarget.appendChild(this._label);
374
+ }
375
+ } else {
376
+ this._label.innerHTML = this.labelContent;
377
+ this._label.className = this.labelClass;
378
+ }
379
+ for (var i in this.funs) {
380
+ this.removeListener(i);
381
+ this.addListener(i, this.funs[i]);
382
+ }
383
+ };
384
+ //计算位置, onAdd和缩放和平移之后调用
385
+ MyLabel.prototype.draw = function () {
386
+ //返回MapCanvasProjection对象,拥有计算pixel和lnglat的方法
387
+ var overlayProjection = this.getProjection();
388
+ //将地理坐标转换成屏幕坐标
389
+ var position = overlayProjection.fromLatLngToDivPixel(this.lnglat);
390
+ if (position) {
391
+ this._label.style.left = position.x + parseFloat(this.labelOffset.x) + 'px';
392
+ this._label.style.top = position.y + parseFloat(this.labelOffset.y) + 'px';
393
+ }
394
+ };
395
+ //更新点位信息
396
+ MyLabel.prototype.setOptions = function (options) {
397
+ this.labelClass = options.labelClass;
398
+ this.labelContent = options.labelContent;
399
+ this.labelOffset = options.labelOffset || { x: 0, y: 0 };
400
+ this.lnglat = options.lnglat || this.lnglat;
401
+ if (this._label) {
402
+ this.onAdd();
403
+ }
404
+ };
405
+ //更新点位信息
406
+ MyLabel.prototype.setPosition = function (lnglat) {
407
+ this.lnglat = lnglat;
408
+ if (this._label) {
409
+ this.draw();
410
+ } else {
411
+ //触发onAdd draw
412
+ this.setMap(map);
413
+ }
414
+ };
415
+ //更新点位信息
416
+ MyLabel.prototype.getPosition = function () {
417
+ return this.lnglat;
418
+ };
419
+ //更新点位信息
420
+ MyLabel.prototype.setZIndex = function (index) {
421
+ if (this._label) {
422
+ this._label.style.ZIndex = index;
423
+ }
424
+ };
425
+ //用于updatePoint时 判断原来的点图元类型
426
+ MyLabel.prototype.isMarkerContent = function () {
427
+ return true;
428
+ };
429
+ //被删除时会调用
430
+ MyLabel.prototype.onRemove = function () {
431
+ this._label.parentNode.removeChild(this._label);
432
+ this._label = null;
433
+ };
434
+ MyLabel.prototype.addListener = function (key, fun) {
435
+ var tt = this;
436
+ if (key == 'dragend') {
437
+ //编辑返回函数
438
+ this.dragendFun = fun;
439
+ return false;
440
+ }
441
+ setTimeout(function () {
442
+ if (tt._label) {
443
+ tt.funs[key] = function (event) {
444
+ if (event.stopPropagation) {
445
+ event.stopPropagation();
446
+ }
447
+ if (!tt.editable) {
448
+ fun({
449
+ latLng: tt.lnglat,
450
+ va: event,
451
+ pixel: tt.getProjection().fromLatLngToDivPixel(tt.lnglat)
452
+ });
453
+ }
454
+ };
455
+ tt._label.addEventListener(key, tt.funs[key]);
456
+ } else {
457
+ tt.addListener(key, fun);
458
+ }
459
+ }, 50);
460
+ };
461
+ MyLabel.prototype.removeListener = function (key) {
462
+ if (key == 'dragend') {
463
+ this.dragendFun = function () {};
464
+ return false;
465
+ }
466
+ if (this._label) {
467
+ this._label.removeEventListener(key, this.funs[key]);
468
+ }
469
+ };
470
+ //设置是否可以编辑
471
+ MyLabel.prototype.setDraggable = function (boolean) {
472
+ this.editable = boolean;
473
+ if (boolean) {
474
+ this.edit();
475
+ } else {
476
+ this._label.removeEventListener('mousedown', this.mdown);
477
+ }
478
+ };
479
+ //编辑时 事件和逻辑
480
+ MyLabel.prototype.edit = function () {
481
+ var tt = this;
482
+ tt.mdown = function (event) {
483
+ event.stopPropagation();
484
+ //禁止文本选中
485
+ tt._label.className = 'noselect';
486
+ // 记录原始位置
487
+ tt.editParam.sx = event.clientX;
488
+ tt.editParam.sy = event.clientY;
489
+
490
+ var mmEvent = function mmEvent(e) {
491
+ e.stopPropagation();
492
+ //计算与上一次的差值 累加到label dom上
493
+ tt._label.style.left = parseFloat(tt._label.style.left.replace('px', '')) + e.clientX - tt.editParam.sx + 'px';
494
+ tt._label.style.top = parseFloat(tt._label.style.top.replace('px', '')) + e.clientY - tt.editParam.sy + 'px';
495
+ //更新原始位置
496
+ tt.editParam.sx = e.clientX;
497
+ tt.editParam.sy = e.clientY;
498
+ };
499
+ var mupEvent = function mupEvent(e) {
500
+ e.stopPropagation();
501
+ //计算与上一次的差值 累加到label dom上
502
+ var x = parseFloat(tt._label.style.left.replace('px', '')) + e.clientX - tt.editParam.sx,
503
+ y = parseFloat(tt._label.style.top.replace('px', '')) + e.clientY - tt.editParam.sy;
504
+ //计算经纬度,固定label的位置
505
+ tt._label.style.left = x + 'px';
506
+ tt._label.style.top = y + 'px';
507
+ var overlayProjection = tt.getProjection(),
508
+ latlng = overlayProjection.fromDivPixelToLatLng(new google.maps.Point(x, y));
509
+ tt.setPosition(latlng);
510
+ // 清空 文本禁选
511
+ tt._label.className = '';
512
+ tt.dragendFun(e);
513
+ //关闭全局监听
514
+ document.removeEventListener('mousemove', mmEvent);
515
+ document.removeEventListener('mouseup', mupEvent);
516
+ };
517
+ document.addEventListener('mousemove', mmEvent);
518
+ document.addEventListener('mouseup', mupEvent);
519
+ };
520
+ tt._label.addEventListener('mousedown', tt.mdown);
521
+ };
522
+ /*=================================end========================================*/
523
+ }
524
+ //设置指定图元展示 google只有zoom和center全适应,单适应暂时无法实现
525
+
526
+ }, {
527
+ key: 'setVisiblePoints',
528
+ value: function setVisiblePoints(obj) {
529
+ var t = this;
530
+ var ls = [];
531
+ var _t$state = t.state,
532
+ pointIds = _t$state.pointIds,
533
+ lineIds = _t$state.lineIds,
534
+ polygonIds = _t$state.polygonIds,
535
+ circleIds = _t$state.circleIds;
536
+
537
+ var getLngLats = function getLngLats(ids, type) {
538
+ var alnglat = [],
539
+ lngs = [],
540
+ lats = [];
541
+ if (!type) {
542
+ t.GM.getMoreGraphicParam(ids).map(function (item, index) {
543
+ var _alnglat, _alnglat2;
544
+
545
+ //根据天地图 覆盖物类型获取lnglat
546
+ switch (item.geometryType) {
547
+ case 'point':
548
+ alnglat.push([item.geometry.x, item.geometry.y]);
549
+ break;
550
+ case 'polyline':
551
+ (_alnglat = alnglat).push.apply(_alnglat, _toConsumableArray(item.geometry.paths));
552
+ break;
553
+ case 'polygon':
554
+ (_alnglat2 = alnglat).push.apply(_alnglat2, _toConsumableArray(item.geometry.rings));
555
+ break;
556
+ case 'circle':
557
+ alnglat.push([item.geometry.x, item.geometry.y]);
558
+ break;
559
+ }
560
+ });
561
+ } else {
562
+ alnglat = ids;
563
+ }
564
+ alnglat.forEach(function (item, index) {
565
+ lngs.push(item[0]);
566
+ lats.push(item[1]);
567
+ });
568
+ lngs.sort();lats.sort();
569
+ return {
570
+ sw: new google.maps.LatLng({ lng: lngs[0], lat: lats[0] }),
571
+ ne: new google.maps.LatLng({ lng: lngs[lngs.length - 1], lat: lats[lats.length - 1] })
572
+ };
573
+ };
574
+ //算出 要展示的图元点位
575
+ switch (obj.fitView) {
576
+ case 'point':
577
+ ls = getLngLats(pointIds);
578
+ break;
579
+ case 'line':
580
+ ls = getLngLats(lineIds);
581
+ break;
582
+ case 'polygon':
583
+ ls = getLngLats(polygonIds);
584
+ break;
585
+ case 'circle':
586
+ ls = getLngLats(circleIds);
587
+ break;
588
+ case 'all':
589
+ ls = getLngLats([].concat(_toConsumableArray(pointIds), _toConsumableArray(lineIds), _toConsumableArray(polygonIds), _toConsumableArray(circleIds)));
590
+ break;
591
+ default:
592
+ var ids = [];
593
+ if (obj.fitView instanceof Array) {
594
+ ids = obj.fitView;
595
+ } else if (typeof obj.fitView === 'string') {
596
+ ids = obj.fitView.split(',');
597
+ }
598
+ //支持传经纬度
599
+ if (ids[0] instanceof Array) {
600
+ ls = getLngLats(ids, 'lnglat');
601
+ } else {
602
+ ls = getLngLats(ids);
603
+ }
604
+ break;
605
+ }
606
+ t.state.gis.fitBounds(new google.maps.LatLngBounds(ls.sw, ls.ne));
607
+ }
608
+ //设置地图中心位置 lng/经度 lat/纬度
609
+
610
+ }, {
611
+ key: 'setCenter',
612
+ value: function setCenter(gt) {
613
+ var t = this;
614
+ var mgt = [626.3002300508477, 37.90942995363547];
615
+ if (gt) {
616
+ //经纬度 必须存在 否则不操作
617
+ if (!gt[0] || !gt[1]) {
618
+ return false;
619
+ }
620
+ //如果设置的经纬度 与当前中心点一样 不操作
621
+ var c = t.state.gis.getCenter();
622
+ if (c.lng == gt[0] && c.lat == gt[1]) {
623
+ return false;
624
+ }
625
+ mgt = gt;
626
+ }
627
+ t.state.gis.setCenter(new google.maps.LatLng({ lng: mgt[0], lat: mgt[1] }));
628
+ t.setState({ center: mgt });
629
+ }
630
+ //设置地图比例尺
631
+
632
+ }, {
633
+ key: 'setZoomLevel',
634
+ value: function setZoomLevel(zoom) {
635
+ var t = this;
636
+ var z = t.getZoomLevel();
637
+ if (z == zoom) {
638
+ return false;
639
+ }
640
+ t.state.gis.setZoom(zoom);
641
+ }
642
+ //清空地图所有图元
643
+
644
+ }, {
645
+ key: 'clearAll',
646
+ value: function clearAll() {
647
+ var t = this;
648
+ //清空热力图
649
+ if (t.heatmap) {
650
+ t.heatmap.setMap(null);
651
+ }
652
+ t.heatmap = null;
653
+ //先清除所有标记
654
+ if (t.clusterIdList.length) {
655
+ t.clearClusters();
656
+ }
657
+ t.clearAllPointCollection();
658
+ //清空点
659
+ for (var i in t.GM.allGraphics) {
660
+ if (t.GM.allGraphics[i]) {
661
+ t.GM.allGraphics[i].setMap(null);
662
+ }
663
+ }
664
+ //清空缓存数据
665
+ t.GM.clearAll();
666
+ //清空历史数据记录
667
+ t.setState({
668
+ pointIds: [],
669
+ lineIds: [],
670
+ polygonIds: [],
671
+ circleIds: [],
672
+ boundaryInfo: [],
673
+ drawIds: {
674
+ point: [],
675
+ polyline: [],
676
+ polygon: [],
677
+ circle: [],
678
+ rectangle: []
679
+ }
680
+ });
681
+ }
682
+ //图元功能处理方法
683
+ //新增点位
684
+
685
+ }, {
686
+ key: 'addPoint',
687
+ value: function addPoint(mapPoints, type) {
688
+ var _this2 = this;
689
+
690
+ var t = this;
691
+ var psids = [].concat(_toConsumableArray(t.state.pointIds));
692
+ var apf = function apf() {
693
+ mapPoints.map(function (item, index) {
694
+ //如果id重复,直接跳过不执行.
695
+ if (_this2.GM.isRepetition(item.id)) {
696
+ console.warn('\u52A0\u70B9id: ' + item.id + ' \u91CD\u590D');
697
+ return false;
698
+ }
699
+ //点位数据不符合,直接跳过
700
+ if (!item.longitude || !item.latitude) {
701
+ console.warn('\u70B9 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF');
702
+ return false;
703
+ }
704
+
705
+ var cg = {
706
+ width: 30,
707
+ height: 30,
708
+ labelContent: '',
709
+ labelPixelX: 0,
710
+ labelPixelY: 34,
711
+ BAnimationType: 3,
712
+ //高德以左上定位,百度以中心为定位
713
+ //默认点的偏移值就不同
714
+ markerContentX: -15,
715
+ markerContentY: -30,
716
+ deg: 0
717
+ };
718
+ if (item.markerContent) {
719
+ cg = _extends({}, cg, { markerContentX: 0, markerContentY: 0, width: 100, height: 30 });
720
+ }
721
+ //初始化默认数据
722
+ if (item.config) {
723
+ cg = _extends({}, cg, item.config);
724
+ }
725
+ var position = new t.omap.LatLng({ lng: item.longitude, lat: item.latitude });
726
+ var marker = null;
727
+ if (item.markerContent) {
728
+ /*自定义html加点
729
+ 用Label来实现,无法再添加label(高德有判断,实现不同)*/
730
+ //覆盖物参数
731
+ marker = new t.MyLabel(t.state.gis, {
732
+ labelContent: item.markerContent,
733
+ labelOffset: { x: cg.markerContentX, y: cg.markerContentY }
734
+ });
735
+ marker.setPosition(position);
736
+ } else {
737
+ /*添加非html点位*/
738
+ // //添加label
739
+ if (item.canShowLabel && cg.labelContent) {
740
+ //label默认样式
741
+ var labelClass = 'label-content';
742
+ //接受label自定义样式
743
+ if (item.labelClass) {
744
+ labelClass = item.labelClass.split(',').join(' ');
745
+ }
746
+ var label = new t.MyLabel(t.state.gis, {
747
+ isLabel: true,
748
+ labelClass: labelClass,
749
+ labelContent: cg.labelContent,
750
+ /*
751
+ 为和百度等地图相同的参数 加上g.markerContentY值
752
+ label是使用OverlayView手动实现,与marker没有关联的原因
753
+ */
754
+ labelOffset: { x: cg.labelPixelX, y: cg.labelPixelY + cg.markerContentY }
755
+ });
756
+ label.setPosition(position);
757
+ //缓存
758
+ t.GM.setGraphic(item.id + '_vtxoMap_label', label);
759
+ }
760
+ var iconUrl = '';
761
+ // 360deg 不需要旋转
762
+ if (parseFloat(cg.deg) % 360 != 0) {
763
+ iconUrl = new _MapToolFunction.RotateIcon({
764
+ url: item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
765
+ width: cg.width,
766
+ height: cg.height
767
+ });
768
+ }
769
+ var icon = {
770
+ anchor: { x: -cg.markerContentX, y: -cg.markerContentY },
771
+ size: new t.omap.Size(cg.width, cg.height),
772
+ scaledSize: new t.omap.Size(cg.width, cg.height),
773
+ url: parseFloat(cg.deg) % 360 != 0 ? iconUrl.setRotation(cg.deg).getUrl() : item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
774
+ labelOrigin: { x: cg.labelPixelX, y: cg.labelPixelY }
775
+ };
776
+ //添加点到地图
777
+ marker = new t.omap.Marker({
778
+ icon: icon,
779
+ position: position,
780
+ map: t.state.gis
781
+ });
782
+ if (item.canShowLabel && cg.labelContent) {
783
+ marker.ishaveLabel = true;
784
+ }
785
+ }
786
+ if (cg.zIndex || cg.zIndex === 0) {
787
+ marker.setZIndex(cg.zIndex);
788
+ }
789
+ if (!item.markerContent && cg.BAnimationType == 0) {
790
+ marker.setAnimation(google.maps.Animation.BOUNCE);
791
+ } else if (!item.markerContent && cg.BAnimationType == 1) {
792
+ marker.setAnimation(google.maps.Animation.DROP);
793
+ }
794
+ //点击事件
795
+ var mClick = marker.addListener('click', function (e) {
796
+ //避免鼠标在图元上 测距工具不起作用
797
+ if (t.rangingTool.isRanging) {
798
+ t.rangingToolFun(e);
799
+ } else {
800
+ t.clickGraphic(item.id, e);
801
+ }
802
+ });
803
+ //鼠标移入事件
804
+ var mMouseover = marker.addListener('mouseover', function (e) {
805
+ t.mouseOverGraphic(item.id, e);
806
+ });
807
+ //鼠标移出事件
808
+ var mMouseout = marker.addListener('mouseout', function (e) {
809
+ t.mouseOutGraphic(item.id, e);
810
+ });
811
+ //缓存所有点的id
812
+ psids.push(item.id);
813
+ //缓存当前点的图元对象和基本数据
814
+ t.GM.setGraphic(item.id, marker).setGraphicParam(item.id, {
815
+ attributes: _extends({}, item, { other: item }),
816
+ geometryType: 'point',
817
+ geometry: {
818
+ type: 'point',
819
+ x: item.longitude,
820
+ y: item.latitude
821
+ }
822
+ }).setGraphicParam(item.id + '_omap_event', {
823
+ click: mClick,
824
+ mouseover: mMouseover,
825
+ mouseout: mMouseout
826
+ });
827
+ });
828
+ if (type !== 'defined') {
829
+ //所有点缓存在state中
830
+ t.state.pointIds = psids;
831
+ // t.setState({
832
+ // pointIds: psids
833
+ // });
834
+ }
835
+ };
836
+ //内部 不需要旋转图标的处理方式
837
+ if (type == 'nodeg') {
838
+ apf();
839
+ } else {
840
+ //缓存图片 旋转功能使用
841
+ mapPoints.map(function (item, index) {
842
+ //避免多次缓存
843
+ if (item.url && !t.cacheImgRecord[item.url]) {
844
+ var i = new Image();
845
+ i.src = item.url;
846
+ t.cacheImg.appendChild(i);
847
+ t.cacheImgRecord[item.url] = true;
848
+ }
849
+ });
850
+ //定时等待 图片缓存,点位旋转功能需要
851
+ t.addPsTimer = setTimeout(function () {
852
+ apf();
853
+ }, 200);
854
+ }
855
+ }
856
+ //更新点位
857
+
858
+ }, {
859
+ key: 'updatePoint',
860
+ value: function updatePoint(mapPoints, type) {
861
+ var _this3 = this;
862
+
863
+ var t = this;
864
+ var upf = function upf() {
865
+ mapPoints.map(function (item, index) {
866
+ //判断图元是否存在.
867
+ if (_this3.GM.isRepetition(item.id)) {
868
+ //点位数据不符合,直接跳过
869
+ if (!item.longitude || !item.latitude) {
870
+ console.warn('\u70B9 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF');
871
+ return false;
872
+ }
873
+ //获取原有的图元 和 对应的label
874
+ var gc = t.GM.getGraphic(item.id),
875
+ gc_label = t.GM.getGraphic(item.id + '_vtxoMap_label');
876
+ //更新前删除聚合
877
+ if (t.clusterIdList.indexOf(item.id) > -1) {
878
+ t._cluster.removeMarker(gc);
879
+ if (gc_label) {
880
+ t._cluster.removeMarker(gc_label);
881
+ }
882
+ }
883
+ var cg = {
884
+ width: 30,
885
+ height: 30,
886
+ labelContent: '',
887
+ labelPixelX: 0,
888
+ labelPixelY: 34,
889
+ BAnimationType: 3,
890
+ //高德以左上定位,百度以中心为定位
891
+ //默认点的偏移值就不同
892
+ markerContentX: -15,
893
+ markerContentY: -30,
894
+ deg: 0
895
+ };
896
+ if (item.markerContent) {
897
+ cg = _extends({}, cg, { markerContentX: 0, markerContentY: 0, width: 100, height: 30 });
898
+ }
899
+ if (item.config) {
900
+ cg = _extends({}, cg, item.config);
901
+ }
902
+ //新旧经纬度 旧经纬度配合moveTo使用
903
+ var position = new t.omap.LatLng({ lng: item.longitude, lat: item.latitude });
904
+ var oldPosition = gc.getPosition();
905
+ //前后点位类型都是markerContent
906
+ if (gc.isMarkerContent && gc.isMarkerContent() && item.markerContent) {
907
+ /*
908
+ 自定义html加点
909
+ 用Label来实现,无法再添加label(高德有判断,实现不同)
910
+ */
911
+ //覆盖物参数
912
+ gc.setOptions({
913
+ labelContent: item.markerContent,
914
+ labelOffset: { x: cg.markerContentX, y: cg.markerContentY },
915
+ lnglat: oldPosition
916
+ });
917
+ } else if (gc.isMarkerContent && gc.isMarkerContent() && !item.markerContent) {
918
+ //markerContent类型转 marker-url类型
919
+ //清除事件
920
+ gc.removeListener('click');
921
+ gc.removeListener('mouseover');
922
+ gc.removeListener('mouseout');
923
+ //删除原点位
924
+ gc.setMap(null);
925
+ var iconUrl = '';
926
+ // 360deg 不需要旋转
927
+ if (parseFloat(cg.deg) % 360 != 0) {
928
+ iconUrl = new _MapToolFunction.RotateIcon({
929
+ url: item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
930
+ width: cg.width,
931
+ height: cg.height
932
+ });
933
+ }
934
+ var icon = {
935
+ anchor: { x: -cg.markerContentX, y: -cg.markerContentY },
936
+ size: new t.omap.Size(cg.width, cg.height),
937
+ scaledSize: new t.omap.Size(cg.width, cg.height),
938
+ url: parseFloat(cg.deg) % 360 != 0 ? iconUrl.setRotation(cg.deg).getUrl() : item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
939
+ labelOrigin: { x: cg.labelPixelX, y: cg.labelPixelY }
940
+ };
941
+ //重新加载点位
942
+ gc = new t.omap.Marker({
943
+ icon: icon,
944
+ position: oldPosition,
945
+ map: t.state.gis
946
+ });
947
+ //切换 图元对象缓存
948
+ t.GM.setGraphic(item.id, gc);
949
+ if (item.canShowLabel && cg.labelContent) {
950
+ //label默认样式
951
+ var labelClass = 'label-content';
952
+ //接受label自定义样式
953
+ if (item.labelClass) {
954
+ labelClass = item.labelClass.split(',').join(' ');
955
+ }
956
+ if (!gc_label) {
957
+ gc_label = new t.MyLabel();
958
+ t.GM.setGraphic(item.id + '_vtxoMap_label', gc_label);
959
+ }
960
+ gc_label.setOptions({
961
+ labelClass: labelClass,
962
+ labelContent: cg.labelContent,
963
+ /*
964
+ 为和百度等地图相同的参数 加上g.markerContentY值
965
+ label是使用OverlayView手动实现,与marker没有关联的原因
966
+ */
967
+ labelOffset: { x: cg.labelPixelX, y: cg.labelPixelY + cg.markerContentY }
968
+ });
969
+ gc.ishaveLabel = true;
970
+ }
971
+ //点击事件
972
+ var mClick = gc.addListener('click', function (e) {
973
+ //避免鼠标在图元上 测距工具不起作用
974
+ if (t.rangingTool.isRanging) {
975
+ t.rangingToolFun(e);
976
+ } else {
977
+ t.clickGraphic(item.id, e);
978
+ }
979
+ });
980
+ //鼠标移入事件
981
+ var mMouseover = gc.addListener('mouseover', function (e) {
982
+ t.mouseOverGraphic(item.id, e);
983
+ });
984
+ //鼠标移出事件
985
+ var mMouseout = gc.addListener('mouseout', function (e) {
986
+ t.mouseOutGraphic(item.id, e);
987
+ });
988
+ t.GM.setGraphicParam(item.id + '_omap_event', {
989
+ click: mClick,
990
+ mouseover: mMouseover,
991
+ mouseout: mMouseout
992
+ });
993
+ } else if (!gc.isMarkerContent && item.markerContent) {
994
+ //marker-url类型转markerContent类型
995
+ //清除事件
996
+ if (t.GM.getGraphicParam(item.id + '_omap_event').click) {
997
+ t.GM.getGraphicParam(item.id + '_omap_event').click.remove();
998
+ }
999
+ if (t.GM.getGraphicParam(item.id + '_omap_event').mouseover) {
1000
+ t.GM.getGraphicParam(item.id + '_omap_event').mouseover.remove();
1001
+ }
1002
+ if (t.GM.getGraphicParam(item.id + '_omap_event').mouseout) {
1003
+ t.GM.getGraphicParam(item.id + '_omap_event').mouseout.remove();
1004
+ }
1005
+ //删除原点位
1006
+ gc.setMap(null);
1007
+ //存在 label点位 直接删除
1008
+ if (gc_label) {
1009
+ gc_label.setMap(null);
1010
+ t.GM.removeGraphic(item.id + '_vtxoMap_label');
1011
+ }
1012
+ //重新加载点位 (原有位置加载,配合moveTo方法使用)
1013
+ gc = new t.MyLabel(t.state.gis, {
1014
+ labelContent: item.markerContent,
1015
+ labelOffset: { x: cg.markerContentX, y: cg.markerContentY }
1016
+ });
1017
+ gc.setPosition(oldPosition);
1018
+ //切换 图元对象缓存
1019
+ t.GM.setGraphic(item.id, gc);
1020
+ //点击事件
1021
+ var _mClick = gc.addListener('click', function (e) {
1022
+ //避免鼠标在图元上 测距工具不起作用
1023
+ if (t.rangingTool.isRanging) {
1024
+ t.rangingToolFun(e);
1025
+ } else {
1026
+ t.clickGraphic(item.id, e);
1027
+ }
1028
+ });
1029
+ //鼠标移入事件
1030
+ var _mMouseover = gc.addListener('mouseover', function (e) {
1031
+ t.mouseOverGraphic(item.id, e);
1032
+ });
1033
+ //鼠标移出事件
1034
+ var _mMouseout = gc.addListener('mouseout', function (e) {
1035
+ t.mouseOutGraphic(item.id, e);
1036
+ });
1037
+ t.GM.setGraphicParam(item.id + '_omap_event', {
1038
+ click: _mClick,
1039
+ mouseover: _mMouseover,
1040
+ mouseout: _mMouseout
1041
+ });
1042
+ } else {
1043
+ var _iconUrl = '';
1044
+ // 360deg 不需要旋转
1045
+ if (parseFloat(cg.deg) % 360 != 0) {
1046
+ _iconUrl = new _MapToolFunction.RotateIcon({
1047
+ url: item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
1048
+ width: cg.width,
1049
+ height: cg.height
1050
+ });
1051
+ }
1052
+ //前后点位类型都是marker-url
1053
+ var _icon = {
1054
+ anchor: { x: -cg.markerContentX, y: -cg.markerContentY },
1055
+ size: new t.omap.Size(cg.width, cg.height),
1056
+ scaledSize: new t.omap.Size(cg.width, cg.height),
1057
+ url: parseFloat(cg.deg) % 360 != 0 ? _iconUrl.setRotation(cg.deg).getUrl() : item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
1058
+ labelOrigin: { x: cg.labelPixelX, y: cg.labelPixelY }
1059
+ };
1060
+ gc.setIcon(_icon);
1061
+ if (item.canShowLabel && cg.labelContent) {
1062
+ //label默认样式
1063
+ var _labelClass = 'label-content';
1064
+ //接受label自定义样式
1065
+ if (item.labelClass) {
1066
+ _labelClass = item.labelClass.split(',').join(' ');
1067
+ }
1068
+ if (!gc_label) {
1069
+ gc_label = new t.MyLabel();
1070
+ t.GM.setGraphic(item.id + '_vtxoMap_label', gc_label);
1071
+ }
1072
+ gc_label.setOptions({
1073
+ labelClass: _labelClass,
1074
+ labelContent: cg.labelContent,
1075
+ /*
1076
+ 为和百度等地图相同的参数 加上g.markerContentY值
1077
+ label是使用OverlayView手动实现,与marker没有关联的原因
1078
+ */
1079
+ labelOffset: { x: cg.labelPixelX, y: cg.labelPixelY + cg.markerContentY }
1080
+ });
1081
+ gc.ishaveLabel = true;
1082
+ }
1083
+ }
1084
+ if (!item.markerContent && cg.BAnimationType == 0) {
1085
+ gc.setAnimation(google.maps.Animation.BOUNCE);
1086
+ } else if (!item.markerContent && cg.BAnimationType == 1) {
1087
+ gc.setAnimation(google.maps.Animation.DROP);
1088
+ }
1089
+ /*moveTo*/
1090
+ //动画效果会延迟执行经纬度的切换
1091
+ if (cg.isAnimation) {
1092
+ t.moveTo(item.id, [item.longitude, item.latitude], cg.animationDelay, cg.autoRotation, item.url, item.urlleft);
1093
+ } else {
1094
+ if (gc_label) {
1095
+ gc_label.setPosition(position);
1096
+ }
1097
+ //修改经纬度
1098
+ gc.setPosition(position);
1099
+ }
1100
+ if (cg.zIndex || cg.zIndex === 0) {
1101
+ gc.setZIndex(cg.zIndex);
1102
+ }
1103
+ t.GM.setGraphicParam(item.id, {
1104
+ attributes: _extends({}, item, { other: item }),
1105
+ geometryType: 'point',
1106
+ geometry: {
1107
+ type: 'point',
1108
+ x: item.longitude,
1109
+ y: item.latitude
1110
+ }
1111
+ });
1112
+ } else {
1113
+ console.warn('\u66F4\u65B0\u7684\u70B9\u4F4Did\u4E0D\u5B58\u5728!');
1114
+ return false;
1115
+ }
1116
+ });
1117
+ t.moveAnimation();
1118
+ };
1119
+ //内部 不需要旋转图标的处理方式
1120
+ if (type == 'nodeg') {
1121
+ upf();
1122
+ } else {
1123
+ //缓存图片 旋转功能使用
1124
+ mapPoints.map(function (item, index) {
1125
+ //排除已经缓存的
1126
+ if (item.url && !t.cacheImgRecord[item.url]) {
1127
+ var i = new Image();
1128
+ i.src = item.url;
1129
+ t.cacheImg.appendChild(i);
1130
+ t.cacheImgRecord[item.url] = true;
1131
+ }
1132
+ if (item.urlleft && !t.cacheImgRecord[item.urlleft]) {
1133
+ var _i = new Image();
1134
+ _i.src = item.urlleft;
1135
+ t.cacheImg.appendChild(_i);
1136
+ t.cacheImgRecord[item.urlleft] = true;
1137
+ }
1138
+ });
1139
+ // 定时等待 图片缓存,点位旋转功能需要
1140
+ t.upPsTimer = setTimeout(function () {
1141
+ upf();
1142
+ }, 200);
1143
+ }
1144
+ }
1145
+ //添加线
1146
+
1147
+ }, {
1148
+ key: 'addLine',
1149
+ value: function addLine(mapLines, type) {
1150
+ var t = this;
1151
+ var lsids = [].concat(_toConsumableArray(t.state.lineIds));
1152
+ //遍历添加线(图元)
1153
+ mapLines.map(function (item, index) {
1154
+ //如果id重复,直接跳过不执行.
1155
+ if (t.GM.isRepetition(item.id)) {
1156
+ console.warn('\u591A\u6298\u7EBFid: ' + item.id + ' \u91CD\u590D');
1157
+ return false;
1158
+ }
1159
+ //多折线点位数据不符合,直接跳过
1160
+ if (!(item.paths && item.paths.length >= 2)) {
1161
+ console.warn('\u591A\u6298\u7EBFpaths\u6570\u636E\u9519\u8BEF');
1162
+ return false;
1163
+ }
1164
+ //初始化默认参数
1165
+ var cg = {
1166
+ color: '#277ffa',
1167
+ pellucidity: 0.9,
1168
+ lineWidth: 5,
1169
+ lineType: 'solid',
1170
+ isHidden: false
1171
+ //合并参数
1172
+ };if (item.config) {
1173
+ cg = _extends({}, cg, item.config);
1174
+ }
1175
+ // 线样式
1176
+ var icons = [];
1177
+ if (cg.lineType == 'dashed') {
1178
+ var lineSymbol = {
1179
+ path: 'M 0,-1 0,1',
1180
+ strokeOpacity: 1,
1181
+ scale: cg.lineWidth > 5 ? 5 : cg.lineWidth < 2.5 ? 2.5 : cg.lineWidth
1182
+ };
1183
+ icons = [{ icon: lineSymbol, offset: '0', repeat: '20px' }];
1184
+ }
1185
+ //处理线的点数组
1186
+ var linePath = item.paths.map(function (item, index) {
1187
+ return new google.maps.LatLng({ lng: item[0], lat: item[1] });
1188
+ }),
1189
+
1190
+ //处理线的参数
1191
+ lineOption = {
1192
+ strokeColor: cg.color, // 线颜色
1193
+ strokeWeight: cg.lineWidth, // 线宽
1194
+ strokeOpacity: cg.lineType == 'dashed' ? 0 : cg.pellucidity, // 线透明度
1195
+ icons: icons
1196
+ };
1197
+ //创建线对象
1198
+ var line = new google.maps.Polyline(_extends({}, lineOption, { path: linePath }));
1199
+ //判断线显示和隐藏
1200
+ if (cg.isHidden) {
1201
+ line.setVisible(false);
1202
+ } else {
1203
+ line.setVisible(true);
1204
+ }
1205
+ lsids.push(item.id);
1206
+ //添加线至地图
1207
+ line.setMap(t.state.gis);
1208
+ //点击事件
1209
+ var mClick = line.addListener('click', function (e) {
1210
+ //避免鼠标在图元上 测距工具不起作用
1211
+ if (t.rangingTool.isRanging) {
1212
+ t.rangingToolFun(e);
1213
+ } else {
1214
+ t.clickGraphic(item.id, e);
1215
+ }
1216
+ });
1217
+ //鼠标移入事件
1218
+ var mMouseover = line.addListener('mouseover', function (e) {
1219
+ t.mouseOverGraphic(item.id, e);
1220
+ });
1221
+ //鼠标移出事件
1222
+ var mMouseout = line.addListener('mouseout', function (e) {
1223
+ t.mouseOutGraphic(item.id, e);
1224
+ });
1225
+ t.GM.setGraphic(item.id, line).setGraphicParam(item.id, {
1226
+ attributes: _extends({}, item, {
1227
+ paths: item.paths,
1228
+ other: item
1229
+ }),
1230
+ geometryType: 'polyline',
1231
+ geometry: {
1232
+ type: 'polyline',
1233
+ paths: item.paths
1234
+ }
1235
+ }).setGraphicParam(item.id + '_omap_event', {
1236
+ click: mClick,
1237
+ mouseover: mMouseover,
1238
+ mouseout: mMouseout
1239
+ });
1240
+ });
1241
+ if (type !== 'defined') {
1242
+ t.state.lineIds = lsids;
1243
+ // t.setState({
1244
+ // lineIds: lsids
1245
+ // });
1246
+ }
1247
+ }
1248
+ //更新线
1249
+
1250
+ }, {
1251
+ key: 'updateLine',
1252
+ value: function updateLine(mapLines) {
1253
+ var t = this;
1254
+ //遍历添加线(图元)
1255
+ mapLines.map(function (item, index) {
1256
+ //判断图元是否存在.
1257
+ if (t.GM.isRepetition(item.id)) {
1258
+ //多折线点位数据不符合,直接跳过
1259
+ if (!(item.paths && item.paths.length >= 2)) {
1260
+ console.warn('\u591A\u6298\u7EBFpaths\u6570\u636E\u9519\u8BEF');
1261
+ return false;
1262
+ }
1263
+ } else {
1264
+ console.warn('\u66F4\u65B0\u7684\u591A\u6298\u7EBFid\u4E0D\u5B58\u5728!');
1265
+ return false;
1266
+ }
1267
+ var gc = t.GM.getGraphic(item.id);
1268
+ //初始化默认参数
1269
+ var cg = {
1270
+ color: '#277ffa',
1271
+ pellucidity: 0.9,
1272
+ lineWidth: 5,
1273
+ lineType: 'solid', //'solid' 'dashed'
1274
+ isHidden: false
1275
+ //合并参数
1276
+ };if (item.config) {
1277
+ cg = _extends({}, cg, item.config);
1278
+ }
1279
+ // 线样式
1280
+ var icons = [];
1281
+ if (cg.lineType == 'dashed') {
1282
+ var lineSymbol = {
1283
+ path: 'M 0,-1 0,1',
1284
+ strokeOpacity: 1,
1285
+ scale: cg.lineWidth > 5 ? 5 : cg.lineWidth < 2.5 ? 2.5 : cg.lineWidth
1286
+ };
1287
+ icons = [{ icon: lineSymbol, offset: '0', repeat: '20px' }];
1288
+ }
1289
+ //处理线的点数组
1290
+ var linePath = item.paths.map(function (item, index) {
1291
+ return new google.maps.LatLng({ lng: item[0], lat: item[1] });
1292
+ }),
1293
+
1294
+ //处理线的参数
1295
+ lineOption = {
1296
+ strokeColor: cg.color, // 线颜色
1297
+ strokeWeight: cg.lineWidth, // 线宽
1298
+ strokeOpacity: cg.lineType == 'dashed' ? 0 : cg.pellucidity, // 线透明度
1299
+ icons: icons
1300
+ };
1301
+ //修改线点位数据
1302
+ gc.setPath(linePath);
1303
+ //修改线配置
1304
+ gc.setOptions(lineOption);
1305
+ //判断线显示和隐藏
1306
+ if (cg.isHidden) {
1307
+ gc.setVisible(false);
1308
+ } else {
1309
+ gc.setVisible(true);
1310
+ }
1311
+ t.GM.setGraphicParam(item.id, {
1312
+ attributes: _extends({}, item, {
1313
+ paths: item.paths,
1314
+ other: item
1315
+ }),
1316
+ geometryType: 'polyline',
1317
+ geometry: {
1318
+ type: 'polyline',
1319
+ paths: item.paths
1320
+ }
1321
+ });
1322
+ });
1323
+ }
1324
+ //添加面
1325
+
1326
+ }, {
1327
+ key: 'addPolygon',
1328
+ value: function addPolygon(mapPolygons) {
1329
+ var t = this;
1330
+ var pgsids = [].concat(_toConsumableArray(t.state.polygonIds));
1331
+ //遍历添加面(图元)
1332
+ mapPolygons.map(function (item, index) {
1333
+ //如果id重复,直接跳过不执行.
1334
+ if (t.GM.isRepetition(item.id)) {
1335
+ console.warn('\u591A\u8FB9\u5F62id: ' + item.id + ' \u91CD\u590D');
1336
+ return false;
1337
+ }
1338
+ //多边形点位数据不符合,直接跳过
1339
+ if (!(item.rings && item.rings.length >= 3)) {
1340
+ console.warn('\u591A\u8FB9\u5F62rings\u6570\u636E\u9519\u8BEF');
1341
+ return false;
1342
+ }
1343
+ //初始化参数
1344
+ var cg = {
1345
+ lineType: 'solid',
1346
+ lineWidth: 5,
1347
+ lineColor: '#277ffa',
1348
+ lineOpacity: 1,
1349
+ color: '#fff',
1350
+ pellucidity: 0.5
1351
+ // isHidden: false //后期需要再加
1352
+ };
1353
+ if (item.config) {
1354
+ cg = _extends({}, cg, item.config);
1355
+ }
1356
+ //面的参数
1357
+ var polygonOption = {
1358
+ strokeColor: cg.lineColor,
1359
+ strokeOpacity: cg.lineOpacity,
1360
+ strokeWeight: cg.lineWidth,
1361
+ strokeStyle: cg.lineType,
1362
+ fillColor: cg.color,
1363
+ fillOpacity: cg.pellucidity
1364
+ },
1365
+ polygonPath = item.rings.map(function (item, index) {
1366
+ return new google.maps.LatLng({ lng: item[0], lat: item[1] });
1367
+ });
1368
+ //创建面对象
1369
+ var polygon = new google.maps.Polygon(_extends({}, polygonOption, { paths: polygonPath }));
1370
+ //添加面至地图
1371
+ polygon.setMap(t.state.gis);
1372
+ //点击事件
1373
+ var mClick = polygon.addListener('click', function (e) {
1374
+ //避免鼠标在图元上 测距工具不起作用
1375
+ if (t.rangingTool.isRanging) {
1376
+ t.rangingToolFun(e);
1377
+ } else {
1378
+ t.clickGraphic(item.id, e);
1379
+ }
1380
+ });
1381
+ //鼠标移入事件
1382
+ var mMouseover = polygon.addListener('mouseover', function (e) {
1383
+ t.mouseOverGraphic(item.id, e);
1384
+ });
1385
+ //鼠标移出事件
1386
+ var mMouseout = polygon.addListener('mouseout', function (e) {
1387
+ t.mouseOutGraphic(item.id, e);
1388
+ });
1389
+ //缓存面id
1390
+ pgsids.push(item.id);
1391
+ //缓存面图元对象和对于传入数据
1392
+ t.GM.setGraphic(item.id, polygon).setGraphicParam(item.id, {
1393
+ attributes: _extends({}, item, {
1394
+ rings: item.rings,
1395
+ other: item
1396
+ }),
1397
+ geometryType: 'polygon',
1398
+ geometry: {
1399
+ type: 'polygon',
1400
+ rings: item.rings
1401
+ }
1402
+ }).setGraphicParam(item.id + '_omap_event', {
1403
+ click: mClick,
1404
+ mouseover: mMouseover,
1405
+ mouseout: mMouseout
1406
+ });
1407
+ });
1408
+ t.state.polygonIds = pgsids;
1409
+ // t.setState({
1410
+ // polygonIds: pgsids
1411
+ // });
1412
+ }
1413
+ //更新面
1414
+
1415
+ }, {
1416
+ key: 'updatePolygon',
1417
+ value: function updatePolygon(mapPolygons) {
1418
+ var t = this;
1419
+ mapPolygons.map(function (item, index) {
1420
+ //判断图元是否存在.
1421
+ if (t.GM.isRepetition(item.id)) {
1422
+ //多边形点位数据不符合,直接跳过
1423
+ if (!(item.rings && item.rings.length >= 3)) {
1424
+ console.warn('\u591A\u8FB9\u5F62rings\u6570\u636E\u9519\u8BEF');
1425
+ return false;
1426
+ }
1427
+ //获取原有的图元
1428
+ var gc = t.GM.getGraphic(item.id);
1429
+ //初始化参数
1430
+ var cg = {
1431
+ lineType: 'solid',
1432
+ lineWidth: 5,
1433
+ lineColor: '#277ffa',
1434
+ lineOpacity: 1,
1435
+ color: '#fff',
1436
+ pellucidity: 0.5
1437
+ // isHidden: false //后期需要再加
1438
+ };
1439
+ if (item.config) {
1440
+ cg = _extends({}, cg, item.config);
1441
+ }
1442
+ //面的参数
1443
+ var polygonOption = {
1444
+ strokeColor: cg.lineColor,
1445
+ strokeOpacity: cg.lineOpacity,
1446
+ strokeWeight: cg.lineWidth,
1447
+ strokeStyle: cg.lineType,
1448
+ fillColor: cg.color,
1449
+ fillOpacity: cg.pellucidity
1450
+ },
1451
+ polygonPath = item.rings.map(function (item, index) {
1452
+ return new google.maps.LatLng({ lng: item[0], lat: item[1] });
1453
+ });
1454
+ //更新经纬度
1455
+ gc.setPath(polygonPath);
1456
+ //更新 多边形 参数
1457
+ gc.setOptions(polygonOption);
1458
+ t.GM.setGraphicParam(item.id, {
1459
+ attributes: _extends({}, item, {
1460
+ rings: item.rings,
1461
+ other: item
1462
+ }),
1463
+ geometryType: 'polygon',
1464
+ geometry: {
1465
+ type: 'polygon',
1466
+ rings: item.rings
1467
+ }
1468
+ });
1469
+ } else {
1470
+ console.warn('\u66F4\u65B0\u7684\u591A\u8FB9\u5F62id\u4E0D\u5B58\u5728!');
1471
+ return false;
1472
+ }
1473
+ });
1474
+ }
1475
+ //添加圆 circle
1476
+
1477
+ }, {
1478
+ key: 'addCircle',
1479
+ value: function addCircle(mapCircles) {
1480
+ var t = this;
1481
+ var ccsids = [].concat(_toConsumableArray(t.state.circleIds));
1482
+ mapCircles.map(function (item, index) {
1483
+ //如果id重复,直接跳过不执行.
1484
+ if (t.GM.isRepetition(item.id)) {
1485
+ console.warn('\u5706id: ' + item.id + ' \u91CD\u590D');
1486
+ return false;
1487
+ }
1488
+ //圆 点位数据不符合,直接跳过
1489
+ if (!item.longitude || !item.latitude) {
1490
+ console.warn('\u5706 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF');
1491
+ return false;
1492
+ }
1493
+ var cg = {
1494
+ lineType: 'solid',
1495
+ lineWidth: 5,
1496
+ lineColor: '#277ffa',
1497
+ lineOpacity: 1,
1498
+ color: '#fff',
1499
+ pellucidity: 0.5
1500
+ // isHidden: false //后期需要在加
1501
+ };
1502
+ if (item.config) {
1503
+ cg = _extends({}, cg, item.config);
1504
+ }
1505
+ //初始化配置数据
1506
+ var circleOption = {
1507
+ strokeColor: cg.lineColor,
1508
+ strokeOpacity: cg.lineOpacity,
1509
+ strokeWeight: cg.lineWidth,
1510
+ strokeStyle: cg.lineType,
1511
+ fillColor: cg.color,
1512
+ fillOpacity: cg.pellucidity
1513
+ },
1514
+ centerPoint = new google.maps.LatLng({ lng: item.longitude, lat: item.latitude });
1515
+ //创建圆图元实例
1516
+ var circle = new google.maps.Circle(_extends({}, circleOption, {
1517
+ radius: item.radius,
1518
+ center: centerPoint
1519
+ }));
1520
+ //添加圆至地图
1521
+ circle.setMap(t.state.gis);
1522
+ //点击事件
1523
+ var mClick = circle.addListener('click', function (e) {
1524
+ //避免鼠标在图元上 测距工具不起作用
1525
+ if (t.rangingTool.isRanging) {
1526
+ t.rangingToolFun(e);
1527
+ } else {
1528
+ t.clickGraphic(item.id, e);
1529
+ }
1530
+ });
1531
+ //鼠标移入事件
1532
+ var mMouseover = circle.addListener('mouseover', function (e) {
1533
+ t.mouseOverGraphic(item.id, e);
1534
+ });
1535
+ //鼠标移出事件
1536
+ var mMouseout = circle.addListener('mouseout', function (e) {
1537
+ t.mouseOutGraphic(item.id, e);
1538
+ });
1539
+ ccsids.push(item.id);
1540
+ //缓存数据
1541
+ t.GM.setGraphic(item.id, circle).setGraphicParam(item.id, {
1542
+ attributes: _extends({}, item, { other: item }),
1543
+ geometryType: 'circle',
1544
+ geometry: {
1545
+ type: 'circle',
1546
+ x: item.longitude,
1547
+ y: item.latitude,
1548
+ radius: item.radius
1549
+ }
1550
+ }).setGraphicParam(item.id + '_omap_event', {
1551
+ click: mClick,
1552
+ mouseover: mMouseover,
1553
+ mouseout: mMouseout
1554
+ });
1555
+ });
1556
+ t.state.circleIds = ccsids;
1557
+ // t.setState({
1558
+ // circleIds: ccsids
1559
+ // });
1560
+ }
1561
+ //更新圆
1562
+
1563
+ }, {
1564
+ key: 'updateCircle',
1565
+ value: function updateCircle(mapCircles) {
1566
+ var t = this;
1567
+ mapCircles.map(function (item, index) {
1568
+ //判断图元是否存在.
1569
+ if (t.GM.isRepetition(item.id)) {
1570
+ //圆 点位数据不符合,直接跳过
1571
+ if (!item.longitude || !item.latitude) {
1572
+ console.warn('\u5706 \u7ECF\u7EAC\u5EA6 \u6570\u636E\u9519\u8BEF');
1573
+ return false;
1574
+ }
1575
+ //获取原有的图元
1576
+ var gc = t.GM.getGraphic(item.id);
1577
+ //获取原有的面属性,转换key值
1578
+ var cg = {
1579
+ lineType: 'solid',
1580
+ lineWidth: 5,
1581
+ lineColor: '#277ffa',
1582
+ lineOpacity: 1,
1583
+ color: '#fff',
1584
+ pellucidity: 0.5
1585
+ // isHidden: false //后期需要在加
1586
+ };
1587
+ if (item.config) {
1588
+ cg = _extends({}, cg, item.config);
1589
+ }
1590
+ //初始化配置数据
1591
+ var circleOption = {
1592
+ strokeColor: cg.lineColor,
1593
+ strokeOpacity: cg.lineOpacity,
1594
+ strokeWeight: cg.lineWidth,
1595
+ strokeStyle: cg.lineType,
1596
+ fillColor: cg.color,
1597
+ fillOpacity: cg.pellucidity
1598
+ },
1599
+ centerPoint = new google.maps.LatLng({ lng: item.longitude, lat: item.latitude });
1600
+ //修改中心点
1601
+ gc.setCenter(centerPoint);
1602
+ //修改半径
1603
+ gc.setRadius(item.radius);
1604
+ //修改圆 参数
1605
+ gc.setOptions(circleOption);
1606
+ //缓存图元的数据,便于后期操作
1607
+ t.GM.setGraphicParam(item.id, {
1608
+ attributes: _extends({}, item, { other: item }),
1609
+ geometryType: 'circle',
1610
+ geometry: {
1611
+ type: 'circle',
1612
+ x: item.longitude,
1613
+ y: item.latitude,
1614
+ radius: item.radius
1615
+ }
1616
+ });
1617
+ } else {
1618
+ console.warn('\u66F4\u65B0\u7684\u5706id\u4E0D\u5B58\u5728!');
1619
+ return false;
1620
+ }
1621
+ });
1622
+ }
1623
+ //热力图
1624
+
1625
+ }, {
1626
+ key: 'heatMapOverlay',
1627
+ value: function heatMapOverlay() {
1628
+ var d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1629
+
1630
+ var t = this;
1631
+ var cg = {
1632
+ radius: 20,
1633
+ max: 100,
1634
+ visible: true,
1635
+ opacity: 0.7
1636
+ };
1637
+ if (d.config) {
1638
+ cg = _extends({}, cg, d.config);
1639
+ }
1640
+ if (!t.heatmap) {
1641
+ t.heatmap = new google.maps.visualization.HeatmapLayer({
1642
+ map: t.state.gis
1643
+ });
1644
+ }
1645
+ var option = {
1646
+ radius: cg.radius,
1647
+ //百度是1-100,高德是0-1
1648
+ opacity: cg.visible ? cg.opacity : 0
1649
+ // maxIntensity: cg.max
1650
+ };
1651
+ if (cg.gradient) {
1652
+ option.gradient = ['rgba(102,255, 0,0)'];
1653
+ //将gradient排序,与其他地图的热力图数据一致
1654
+ var sortArray = [];
1655
+ for (var i in cg.gradient) {
1656
+ sortArray.push({ key: i, value: cg.gradient[i] });
1657
+ }
1658
+ option.gradient = [].concat(_toConsumableArray(option.gradient), _toConsumableArray(sortArray.sort(function (a, b) {
1659
+ return a.key > b.key;
1660
+ }).map(function (item) {
1661
+ return item.value;
1662
+ })));
1663
+ }
1664
+ t.heatmap.setOptions(option);
1665
+ t.heatmap.setData((d.data || []).map(function (item, index) {
1666
+ return new google.maps.LatLng({ lng: item.lng, lat: item.lat });
1667
+ }));
1668
+ }
1669
+ //添加海量点
1670
+
1671
+ }, {
1672
+ key: 'addPointCollection',
1673
+ value: function addPointCollection() {
1674
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1675
+
1676
+ var t = this;
1677
+ //处理海量点
1678
+ var panes = t.canvasProjectionOverlay.getPanes(),
1679
+ ftp = t.canvasProjectionOverlay.getProjection();
1680
+ if (panes) {
1681
+ if (!t.pointCollectionId) {
1682
+ t.pointCollectionId = t.props.mapId + '_vtx_gmap_html_pointCollection';
1683
+ var divpc = document.createElement('div');
1684
+ divpc.className = 'vtx_gmap_html_pointCollection_a';
1685
+ divpc.style.top = '-' + t.state.gis.getDiv().offsetHeight / 2 + 'px';
1686
+ divpc.style.left = '-' + t.state.gis.getDiv().offsetWidth / 2 + 'px';
1687
+ divpc.id = t.pointCollectionId;
1688
+ panes.markerLayer.appendChild(divpc);
1689
+ }
1690
+ data.map(function (item, index) {
1691
+ var d = item || {};
1692
+ var points = (d.points || []).map(function (d, i) {
1693
+ var p = new google.maps.LatLng(d);
1694
+ p = ftp.fromLatLngToContainerPixel(p);
1695
+ return [p.x, p.y];
1696
+ });
1697
+ var options = {
1698
+ size: d.size,
1699
+ shape: d.shape,
1700
+ color: d.color,
1701
+ width: t.state.gis.getDiv().offsetWidth,
1702
+ height: t.state.gis.getDiv().offsetHeight,
1703
+ mapId: t.props.mapId
1704
+ };
1705
+ var VotexpointCollection = new GMapLib.PointCollection(points, options);
1706
+ t.morepoints.push({
1707
+ id: d.id,
1708
+ value: VotexpointCollection
1709
+ });
1710
+ VotexpointCollection.draw();
1711
+ });
1712
+ } else {
1713
+ if (t.addpointCollectionTimer) {
1714
+ clearTimeout(t.addpointCollectionTimer);
1715
+ }
1716
+ t.addpointCollectionTimer = setTimeout(function () {
1717
+ t.addPointCollection(data);
1718
+ }, 50);
1719
+ }
1720
+ }
1721
+ //更新海量点
1722
+
1723
+ }, {
1724
+ key: 'updatePointCollection',
1725
+ value: function updatePointCollection() {
1726
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1727
+
1728
+ var t = this;
1729
+ var ftp = t.canvasProjectionOverlay.getProjection();
1730
+ if (ftp) {
1731
+ data.map(function (ds, ind) {
1732
+ t.morepoints.map(function (item, index) {
1733
+ if (item.id == ds.id) {
1734
+ var points = (ds.points || []).map(function (d, i) {
1735
+ var p = new google.maps.LatLng(d);
1736
+ p = ftp.fromLatLngToContainerPixel(p);
1737
+ return [p.x, p.y];
1738
+ });
1739
+ var options = {
1740
+ size: ds.size,
1741
+ shape: ds.shape,
1742
+ color: ds.color,
1743
+ width: t.state.gis.getDiv().offsetWidth,
1744
+ height: t.state.gis.getDiv().offsetHeight
1745
+ };
1746
+ item.value.reDraw(points, options);
1747
+ }
1748
+ });
1749
+ });
1750
+ } else {
1751
+ if (t.updatePointCollectionTimer) {
1752
+ clearTimeout(t.updatePointCollectionTimer);
1753
+ }
1754
+ t.updatePointCollectionTimer = setTimeout(function () {
1755
+ t.addPointCollection(data);
1756
+ }, 50);
1757
+ }
1758
+ }
1759
+ //删除海量点
1760
+
1761
+ }, {
1762
+ key: 'clearPointCollection',
1763
+ value: function clearPointCollection() {
1764
+ var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1765
+
1766
+ var t = this;
1767
+ ids.map(function (id, ind) {
1768
+ t.morepoints.map(function (item, index) {
1769
+ if (id == item.id) {
1770
+ item.value.clear();
1771
+ }
1772
+ });
1773
+ });
1774
+ }
1775
+ //删除全部海量点
1776
+
1777
+ }, {
1778
+ key: 'clearAllPointCollection',
1779
+ value: function clearAllPointCollection() {
1780
+ var t = this;
1781
+ t.morepoints.map(function (item, index) {
1782
+ item.value.clear();
1783
+ });
1784
+ }
1785
+ //删除图元
1786
+
1787
+ }, {
1788
+ key: 'removeGraphic',
1789
+ value: function removeGraphic(id, type) {
1790
+ var t = this;
1791
+ var graphic = t.GM.getGraphic(id),
1792
+ gc_label = t.GM.getGraphic(id + '_vtxoMap_label');
1793
+ //删除点聚合效果
1794
+ if (t.clusterIdList.indexOf(id) > -1) {
1795
+ t.removeCluster(id);
1796
+ }
1797
+ if (graphic) {
1798
+ //清除地图中图元
1799
+ graphic.setMap(null);
1800
+ //清除对应id的图元数据缓存
1801
+ t.GM.removeGraphic(id);
1802
+ } else {
1803
+ return false;
1804
+ }
1805
+ //删除点位label
1806
+ if (gc_label) {
1807
+ gc_label.setMap(null);
1808
+ t.GM.removeGraphic(id + '_vtxoMap_label');
1809
+ }
1810
+ for (var i = 0; i < t.movePoints.length; i++) {
1811
+ if (t.movePoints[i].id == id) {
1812
+ t.movePoints.splice(i, 1);
1813
+ continue;
1814
+ }
1815
+ }
1816
+ var ids = [];
1817
+ switch (type) {
1818
+ case 'point':
1819
+ ids = t.state.pointIds;
1820
+ break;
1821
+ case 'line':
1822
+ ids = t.state.lineIds;
1823
+ break;
1824
+ case 'polygon':
1825
+ ids = t.state.polygonIds;
1826
+ break;
1827
+ case 'circle':
1828
+ ids = t.state.circleIds;
1829
+ break;
1830
+ case 'draw':
1831
+ if (t.state.drawIds.point.indexOf(id) > -1) {
1832
+ t.state.drawIds.point.splice(t.state.drawIds.point.indexOf(id), 1);
1833
+ }
1834
+ if (t.state.drawIds.polyline.indexOf(id) > -1) {
1835
+ t.state.drawIds.polyline.splice(t.state.drawIds.polyline.indexOf(id), 1);
1836
+ }
1837
+ if (t.state.drawIds.polygon.indexOf(id) > -1) {
1838
+ t.state.drawIds.polygon.splice(t.state.drawIds.polygon.indexOf(id), 1);
1839
+ }
1840
+ if (t.state.drawIds.circle.indexOf(id) > -1) {
1841
+ t.state.drawIds.circle.splice(t.state.drawIds.circle.indexOf(id), 1);
1842
+ }
1843
+ if (t.state.drawIds.rectangle.indexOf(id) > -1) {
1844
+ t.state.drawIds.rectangle.splice(t.state.drawIds.rectangle.indexOf(id), 1);
1845
+ }
1846
+ break;
1847
+ default:
1848
+ if (t.state.pointIds.indexOf(id) > -1) {
1849
+ t.state.pointIds.splice(t.state.pointIds.indexOf(id), 1);
1850
+ }
1851
+ if (t.state.lineIds.indexOf(id) > -1) {
1852
+ t.state.lineIds.splice(t.state.lineIds.indexOf(id), 1);
1853
+ }
1854
+ if (t.state.polygonIds.indexOf(id) > -1) {
1855
+ t.state.polygonIds.splice(t.state.polygonIds.indexOf(id), 1);
1856
+ }
1857
+ if (t.state.circleIds.indexOf(id) > -1) {
1858
+ t.state.circleIds.splice(t.state.circleIds.indexOf(id), 1);
1859
+ }
1860
+ break;
1861
+ }
1862
+ if (id == t.state.editId) {
1863
+ t.state.editId = '';
1864
+ }
1865
+ if (ids.indexOf(id) != -1) {
1866
+ ids.splice(ids.indexOf(id), 1);
1867
+ }
1868
+ }
1869
+ /*根据图元id,使图元变成可编辑状态*/
1870
+
1871
+ }, {
1872
+ key: 'doEdit',
1873
+ value: function doEdit(id) {
1874
+ var t = this;
1875
+ //获取编辑点的图元和参数
1876
+ var graphic = t.GM.getGraphic(id),
1877
+ gLabel = t.GM.getGraphic(id + '_vtxoMap_label'),
1878
+ gtp = t.GM.getGraphicParam(id);
1879
+ if (!graphic) return false;
1880
+ //关闭先前编辑的图元
1881
+ if (!!t.state.editId) {
1882
+ t.endEdit();
1883
+ }
1884
+ if (!t.editGraphicChange) {
1885
+ //编辑变动后
1886
+ t.editGraphicChange = function (e) {
1887
+ var id = t.state.editId,
1888
+ param = t.getGraphic(id),
1889
+ obj = {
1890
+ param: param, e: e, id: id,
1891
+ geometry: param.geometry
1892
+ };
1893
+ if (param.geometry.type == 'polygon') {
1894
+ if (google.maps.geometry && google.maps.geometry.spherical) {
1895
+ obj.area = google.maps.geometry.spherical.computeArea(param.mapLayer.getPath().getArray());
1896
+ } else {
1897
+ obj.area = 0;
1898
+ }
1899
+ }
1900
+ if (param.geometry.type == 'polyline') {
1901
+ obj.distance = t.calculateDistance(param.geometry.paths);
1902
+ }
1903
+ if (param.geometry.type == 'circle') {
1904
+ obj.area = Math.pow(param.geometry.radius, 2) * Math.PI;
1905
+ if (t.editTimeout) {
1906
+ clearTimeout(t.editTimeout);
1907
+ }
1908
+ t.editTimeout = setTimeout(function () {
1909
+ t.setState({ editGraphic: obj }, function () {
1910
+ t.props.editGraphicChange(obj);
1911
+ });
1912
+ }, 300);
1913
+ } else {
1914
+ t.setState({ editGraphic: obj }, function () {
1915
+ t.props.editGraphicChange(obj);
1916
+ });
1917
+ }
1918
+ };
1919
+ }
1920
+ switch (gtp.geometryType) {
1921
+ case 'point':
1922
+ graphic.setDraggable(true);
1923
+ t.editEvent['dragend'] = graphic.addListener("dragend", t.editGraphicChange);
1924
+ //判断是否是 markerContent 再判断是否有label
1925
+ if (!gtp.attributes.markerContent && gLabel) {
1926
+ //label事件对象 便于删除
1927
+ t.editPointLabel = graphic.addListener("drag", function (event) {
1928
+ gLabel.setPosition(event.latLng);
1929
+ });
1930
+ }
1931
+ break;
1932
+ case 'polyline':
1933
+ case 'polygon':
1934
+ case 'rectangle':
1935
+ graphic.setEditable(true);
1936
+ t.editEvent['mouseup'] = graphic.addListener("mouseup", t.editGraphicChange);
1937
+ break;
1938
+ case 'circle':
1939
+ graphic.setEditable(true);
1940
+ t.editEvent['center_changed'] = graphic.addListener("center_changed", t.editGraphicChange);
1941
+ t.editEvent['radius_changed'] = graphic.addListener("radius_changed", t.editGraphicChange);
1942
+ break;
1943
+ }
1944
+ t.setState({ editId: id });
1945
+ }
1946
+ //关闭编辑
1947
+
1948
+ }, {
1949
+ key: 'endEdit',
1950
+ value: function endEdit() {
1951
+ var t = this;
1952
+ //获取编辑点的图元和参数
1953
+ var graphic = t.GM.getGraphic(t.state.editId);
1954
+ var gtp = t.GM.getGraphicParam(t.state.editId);
1955
+ if (!graphic) return false;
1956
+ switch (gtp.geometryType) {
1957
+ case 'point':
1958
+ graphic.setDraggable(false);
1959
+ if (graphic.removeListener) {
1960
+ graphic.removeListener("dragend", t.editGraphicChange);
1961
+ } else {
1962
+ for (var i in t.editEvent) {
1963
+ if (t.editEvent[i]) {
1964
+ t.editEvent[i].remove();
1965
+ }
1966
+ }
1967
+ if (t.editPointLabel) {
1968
+ t.editPointLabel.remove();
1969
+ t.editPointLabel = null;
1970
+ }
1971
+ }
1972
+ break;
1973
+ case 'polyline':
1974
+ case 'polygon':
1975
+ case 'rectangle':
1976
+ case 'circle':
1977
+ graphic.setEditable(false);
1978
+ for (var _i2 in t.editEvent) {
1979
+ if (t.editEvent[_i2]) {
1980
+ t.editEvent[_i2].remove();
1981
+ }
1982
+ }
1983
+ break;
1984
+ }
1985
+ //事件缓存制空,避免异常
1986
+ t.editEvent = {};
1987
+ var editGraphic = t.state.editGraphic;
1988
+ if (editGraphic) {
1989
+ t.setState({
1990
+ editId: '',
1991
+ editGraphic: ''
1992
+ }, function () {
1993
+ t.props.editGraphicChange(editGraphic);
1994
+ });
1995
+ }
1996
+ }
1997
+ //绘制图元
1998
+
1999
+ }, {
2000
+ key: 'draw',
2001
+ value: function draw(obj) {
2002
+ var t = this,
2003
+ drawParam = {};
2004
+ //先关闭(防止连点)
2005
+ t._drawmanager.setDrawingMode(null);
2006
+ //初始化参数
2007
+ drawParam.geometryType = obj.geometryType || 'point';
2008
+ drawParam.parameter = obj.parameter ? _extends({}, obj.parameter) : {};
2009
+ drawParam.data = obj.data ? _extends({}, obj.data) : {};
2010
+ drawParam.data.id = (obj.data || {}).id || 'draw' + new Date().getTime();
2011
+ //判断id是否存在
2012
+ var len = t.state.drawIds[drawParam.geometryType].indexOf(drawParam.data.id);
2013
+ if (len > -1) {
2014
+ //如果id存在 删除存在的图元,清除drawId中的id数据
2015
+ t.removeGraphic(drawParam.data.id);
2016
+ t.state.drawIds[drawParam.geometryType].splice(len, 1);
2017
+ }
2018
+ var param = {};
2019
+ var paramgcr = {};
2020
+ if (drawParam.geometryType == 'polygon' || drawParam.geometryType == 'circle' || drawParam.geometryType == 'rectangle') {
2021
+ paramgcr.fillColor = drawParam.parameter.color;
2022
+ paramgcr.strokeColor = drawParam.parameter.lineColor;
2023
+ paramgcr.strokeOpacity = drawParam.parameter.lineOpacity;
2024
+ paramgcr.strokeWeight = drawParam.parameter.lineWidth;
2025
+ paramgcr.fillOpacity = drawParam.parameter.pellucidity;
2026
+ paramgcr.strokeStyle = drawParam.parameter.lineType;
2027
+ paramgcr.extData = {
2028
+ id: drawParam.data.id,
2029
+ attributes: {
2030
+ id: drawParam.data.id,
2031
+ config: {
2032
+ color: drawParam.parameter.color,
2033
+ lineColor: drawParam.parameter.lineColor,
2034
+ lineOpacity: drawParam.parameter.lineOpacity,
2035
+ pellucidity: drawParam.parameter.pellucidity,
2036
+ lineWidth: drawParam.parameter.lineWidth
2037
+ }
2038
+ },
2039
+ type: drawParam.geometryType
2040
+ };
2041
+ }
2042
+ switch (drawParam.geometryType) {
2043
+ case 'point':
2044
+ var icon = {
2045
+ anchor: { x: -drawParam.parameter.markerContentX || 15, y: -drawParam.parameter.markerContentY || 30 },
2046
+ size: new t.omap.Size(drawParam.parameter.width || 30, drawParam.parameter.height || 30),
2047
+ scaledSize: new t.omap.Size(drawParam.parameter.width || 30, drawParam.parameter.height || 30),
2048
+ url: drawParam.parameter.url || _default2.default.mapServerURL + '/images/defaultMarker.png'
2049
+ };
2050
+ t._drawmanager.setOptions({
2051
+ drawingControl: false,
2052
+ markerOptions: {
2053
+ icon: icon
2054
+ }
2055
+ });
2056
+ t._drawmanager.setDrawingMode('marker');
2057
+ t._drawmanagerEvent = t._drawmanager.addListener('markercomplete', function (e) {
2058
+ //清楚事件监听
2059
+ t._drawmanagerEvent.remove();
2060
+ //关闭绘制功能
2061
+ t._drawmanager.setDrawingMode(null);
2062
+ t.GM.setGraphic(drawParam.data.id, e);
2063
+ var backobj = {
2064
+ id: drawParam.data.id,
2065
+ attributes: {
2066
+ id: drawParam.data.id,
2067
+ url: icon.url,
2068
+ config: {
2069
+ width: icon.size.width,
2070
+ height: icon.size.height
2071
+ }
2072
+ },
2073
+ geometry: {
2074
+ type: 'point',
2075
+ x: e.getPosition().lng(),
2076
+ y: e.getPosition().lat()
2077
+ },
2078
+ geometryType: 'point',
2079
+ mapLayer: e
2080
+ //点击事件
2081
+ };var mClick = e.addListener('click', function (e) {
2082
+ //避免鼠标在图元上 测距工具不起作用
2083
+ if (t.rangingTool.isRanging) {
2084
+ t.rangingToolFun(e);
2085
+ } else {
2086
+ t.clickGraphic(drawParam.data.id, e);
2087
+ }
2088
+ });
2089
+ //鼠标移入事件
2090
+ var mMouseover = e.addListener('mouseover', function (e) {
2091
+ t.mouseOverGraphic(drawParam.data.id, e);
2092
+ });
2093
+ //鼠标移出事件
2094
+ var mMouseout = e.addListener('mouseout', function (e) {
2095
+ t.mouseOutGraphic(drawParam.data.id, e);
2096
+ });
2097
+ t.GM.setGraphicParam(drawParam.data.id, backobj).setGraphicParam(drawParam.data.id + '_omap_event', {
2098
+ click: mClick,
2099
+ mouseover: mMouseover,
2100
+ mouseout: mMouseout
2101
+ });
2102
+ if ('drawEnd' in t.props) {
2103
+ t.props.drawEnd(backobj);
2104
+ }
2105
+ });
2106
+ break;
2107
+ case 'polyline':
2108
+ param.strokeColor = drawParam.parameter.color;
2109
+ param.strokeOpacity = drawParam.parameter.pellucidity;
2110
+ param.strokeWeight = drawParam.parameter.lineWidth;
2111
+ t._drawmanager.setOptions({
2112
+ drawingControl: false,
2113
+ polylineOptions: param
2114
+ });
2115
+ t._drawmanager.setDrawingMode('polyline');
2116
+ t._drawmanagerEvent = t._drawmanager.addListener('polylinecomplete', function (e) {
2117
+ //清楚事件监听
2118
+ t._drawmanagerEvent.remove();
2119
+ //关闭绘制功能
2120
+ t._drawmanager.setDrawingMode(null);
2121
+ t.GM.setGraphic(drawParam.data.id, e);
2122
+ var paths = [];
2123
+ var lnglatAry = (e.getPath().getArray() || []).map(function (item, index) {
2124
+ paths.push({ lng: item.lng(), lat: item.lat() });
2125
+ return { lngX: item.lng(), latX: item.lat() };
2126
+ });
2127
+ var backobj = {
2128
+ geometryType: 'polyline',
2129
+ distance: t.calculateGraphicDistance(e.getPath().getArray()),
2130
+ id: drawParam.data.id,
2131
+ attributes: {
2132
+ id: drawParam.data.id,
2133
+ config: {
2134
+ color: param.strokeColor,
2135
+ pellucidity: param.strokeOpacity,
2136
+ lineWidth: param.strokeWeight
2137
+ }
2138
+ },
2139
+ mapLayer: e,
2140
+ geometry: {
2141
+ type: 'polyline',
2142
+ lnglatAry: lnglatAry,
2143
+ paths: (0, _MapToolFunction.getMaxMin)(paths).path
2144
+ },
2145
+ lnglatAry: lnglatAry
2146
+ //点击事件
2147
+ };var mClick = e.addListener('click', function (e) {
2148
+ //避免鼠标在图元上 测距工具不起作用
2149
+ if (t.rangingTool.isRanging) {
2150
+ t.rangingToolFun(e);
2151
+ } else {
2152
+ t.clickGraphic(drawParam.data.id, e);
2153
+ }
2154
+ });
2155
+ //鼠标移入事件
2156
+ var mMouseover = e.addListener('mouseover', function (e) {
2157
+ t.mouseOverGraphic(drawParam.data.id, e);
2158
+ });
2159
+ //鼠标移出事件
2160
+ var mMouseout = e.addListener('mouseout', function (e) {
2161
+ t.mouseOutGraphic(drawParam.data.id, e);
2162
+ });
2163
+ t.GM.setGraphicParam(drawParam.data.id, backobj).setGraphicParam(item.id + '_omap_event', {
2164
+ click: mClick,
2165
+ mouseover: mMouseover,
2166
+ mouseout: mMouseout
2167
+ });
2168
+ if ('drawEnd' in t.props) {
2169
+ t.props.drawEnd(backobj);
2170
+ }
2171
+ });
2172
+ break;
2173
+ case 'polygon':
2174
+ t._drawmanager.setOptions({
2175
+ drawingControl: false,
2176
+ polygonOptions: paramgcr
2177
+ });
2178
+ t._drawmanager.setDrawingMode('polygon');
2179
+ t._drawmanagerEvent = t._drawmanager.addListener('polygoncomplete', function (e) {
2180
+ //清楚事件监听
2181
+ t._drawmanagerEvent.remove();
2182
+ //关闭绘制功能
2183
+ t._drawmanager.setDrawingMode(null);
2184
+ t.GM.setGraphic(drawParam.data.id, e);
2185
+ var paths = [],
2186
+ area = t.calculateArea(drawParam.data.id);
2187
+ var lnglatAry = (e.getPath().getArray() || []).map(function (item, index) {
2188
+ paths.push({ lng: item.lng(), lat: item.lat() });
2189
+ return { lngX: item.lng(), latX: item.lat() };
2190
+ });
2191
+ var backobj = {
2192
+ geometryType: 'polygon',
2193
+ id: drawParam.data.id,
2194
+ attributes: {
2195
+ id: drawParam.data.id,
2196
+ config: {
2197
+ color: paramgcr.fillColor,
2198
+ lineColor: paramgcr.strokeColor,
2199
+ lineOpacity: paramgcr.strokeOpacity,
2200
+ pellucidity: paramgcr.fillOpacity,
2201
+ lineWidth: paramgcr.strokeWeight
2202
+ }
2203
+ },
2204
+ mapLayer: e,
2205
+ geometry: {
2206
+ type: 'polygon',
2207
+ lnglatAry: lnglatAry,
2208
+ rings: (0, _MapToolFunction.getMaxMin)(paths).path,
2209
+ _extent: (0, _MapToolFunction.getMaxMin)(paths)._extent,
2210
+ area: area
2211
+ },
2212
+ lnglatAry: lnglatAry,
2213
+ area: area
2214
+ };
2215
+ //点击事件
2216
+ var mClick = e.addListener('click', function (e) {
2217
+ //避免鼠标在图元上 测距工具不起作用
2218
+ if (t.rangingTool.isRanging) {
2219
+ t.rangingToolFun(e);
2220
+ } else {
2221
+ t.clickGraphic(drawParam.data.id, e);
2222
+ }
2223
+ });
2224
+ //鼠标移入事件
2225
+ var mMouseover = e.addListener('mouseover', function (e) {
2226
+ t.mouseOverGraphic(drawParam.data.id, e);
2227
+ });
2228
+ //鼠标移出事件
2229
+ var mMouseout = e.addListener('mouseout', function (e) {
2230
+ t.mouseOutGraphic(drawParam.data.id, e);
2231
+ });
2232
+ t.GM.setGraphicParam(drawParam.data.id, backobj).setGraphicParam(item.id + '_omap_event', {
2233
+ click: mClick,
2234
+ mouseover: mMouseover,
2235
+ mouseout: mMouseout
2236
+ });
2237
+ if ('drawEnd' in t.props) {
2238
+ t.props.drawEnd(backobj);
2239
+ }
2240
+ });
2241
+ break;
2242
+ case 'circle':
2243
+ t._drawmanager.setOptions({
2244
+ drawingControl: false,
2245
+ circleOptions: paramgcr
2246
+ });
2247
+ t._drawmanager.setDrawingMode('circle');
2248
+ t._drawmanagerEvent = t._drawmanager.addListener('circlecomplete', function (e) {
2249
+ //清楚事件监听
2250
+ t._drawmanagerEvent.remove();
2251
+ //关闭绘制功能
2252
+ t._drawmanager.setDrawingMode(null);
2253
+ t.GM.setGraphic(drawParam.data.id, e);
2254
+ var area = Math.PI * Math.pow(e.getRadius(), 2);
2255
+ var backobj = {
2256
+ geometryType: 'circle',
2257
+ id: drawParam.data.id,
2258
+ attributes: {
2259
+ id: drawParam.data.id,
2260
+ config: {
2261
+ color: paramgcr.fillColor,
2262
+ lineColor: paramgcr.strokeColor,
2263
+ lineOpacity: paramgcr.strokeOpacity,
2264
+ pellucidity: paramgcr.fillOpacity,
2265
+ lineWidth: paramgcr.strokeWeight
2266
+ }
2267
+ },
2268
+ mapLayer: e,
2269
+ geometry: {
2270
+ type: 'circle',
2271
+ x: e.getCenter().lng(),
2272
+ y: e.getCenter().lat(),
2273
+ radius: e.getRadius(),
2274
+ area: area
2275
+ },
2276
+ area: area
2277
+ };
2278
+ //点击事件
2279
+ var mClick = e.addListener('click', function (e) {
2280
+ //避免鼠标在图元上 测距工具不起作用
2281
+ if (t.rangingTool.isRanging) {
2282
+ t.rangingToolFun(e);
2283
+ } else {
2284
+ t.clickGraphic(drawParam.data.id, e);
2285
+ }
2286
+ });
2287
+ //鼠标移入事件
2288
+ var mMouseover = e.addListener('mouseover', function (e) {
2289
+ t.mouseOverGraphic(drawParam.data.id, e);
2290
+ });
2291
+ //鼠标移出事件
2292
+ var mMouseout = e.addListener('mouseout', function (e) {
2293
+ t.mouseOutGraphic(drawParam.data.id, e);
2294
+ });
2295
+ t.GM.setGraphicParam(drawParam.data.id, backobj).setGraphicParam(item.id + '_omap_event', {
2296
+ click: mClick,
2297
+ mouseover: mMouseover,
2298
+ mouseout: mMouseout
2299
+ });
2300
+ if ('drawEnd' in t.props) {
2301
+ t.props.drawEnd(backobj);
2302
+ }
2303
+ });
2304
+ break;
2305
+ case 'rectangle':
2306
+ t._drawmanager.setOptions({
2307
+ drawingControl: false,
2308
+ rectangleOptions: paramgcr
2309
+ });
2310
+ t._drawmanager.setDrawingMode('rectangle');
2311
+ t._drawmanagerEvent = t._drawmanager.addListener('rectanglecomplete', function (e) {
2312
+ //清楚事件监听
2313
+ t._drawmanagerEvent.remove();
2314
+ //关闭绘制功能
2315
+ t._drawmanager.setDrawingMode(null);
2316
+ t.GM.setGraphic(drawParam.data.id, e);
2317
+ var lnglatJson = e.getBounds().toJSON();
2318
+ var paths = [{
2319
+ lng: lnglatJson.west,
2320
+ lat: lnglatJson.south
2321
+ }, {
2322
+ lng: lnglatJson.east,
2323
+ lat: lnglatJson.south
2324
+ }, {
2325
+ lng: lnglatJson.east,
2326
+ lat: lnglatJson.north
2327
+ }, {
2328
+ lng: lnglatJson.west,
2329
+ lat: lnglatJson.north
2330
+ }];
2331
+ var lnglatAry = (paths || []).map(function (item, index) {
2332
+ return { lngX: item.lng, latX: item.lat };
2333
+ });
2334
+ var area = t.calculatePointsDistance([lnglatJson.west, lnglatJson.south], [lnglatJson.east, lnglatJson.south]) * t.calculatePointsDistance([lnglatJson.east, lnglatJson.south], [lnglatJson.east, lnglatJson.north]);
2335
+
2336
+ var backobj = {
2337
+ geometryType: 'polygon',
2338
+ id: drawParam.data.id,
2339
+ attributes: {
2340
+ id: drawParam.data.id,
2341
+ config: {
2342
+ color: paramgcr.fillColor,
2343
+ lineColor: paramgcr.strokeColor,
2344
+ lineOpacity: paramgcr.strokeOpacity,
2345
+ pellucidity: paramgcr.fillOpacity,
2346
+ lineWidth: paramgcr.strokeWeight
2347
+ }
2348
+ },
2349
+ mapLayer: e,
2350
+ geometry: {
2351
+ type: 'polygon',
2352
+ lnglatAry: lnglatAry,
2353
+ rings: (0, _MapToolFunction.getMaxMin)(paths).path,
2354
+ _extent: (0, _MapToolFunction.getMaxMin)(paths)._extent,
2355
+ area: area
2356
+ },
2357
+ lnglatAry: lnglatAry,
2358
+ area: area
2359
+ };
2360
+ //点击事件
2361
+ var mClick = e.addListener('click', function (e) {
2362
+ //避免鼠标在图元上 测距工具不起作用
2363
+ if (t.rangingTool.isRanging) {
2364
+ t.rangingToolFun(e);
2365
+ } else {
2366
+ t.clickGraphic(drawParam.data.id, e);
2367
+ }
2368
+ });
2369
+ //鼠标移入事件
2370
+ var mMouseover = e.addListener('mouseover', function (e) {
2371
+ t.mouseOverGraphic(drawParam.data.id, e);
2372
+ });
2373
+ //鼠标移出事件
2374
+ var mMouseout = e.addListener('mouseout', function (e) {
2375
+ t.mouseOutGraphic(drawParam.data.id, e);
2376
+ });
2377
+ t.GM.setGraphicParam(drawParam.data.id, backobj).setGraphicParam(item.id + '_omap_event', {
2378
+ click: mClick,
2379
+ mouseover: mMouseover,
2380
+ mouseout: mMouseout
2381
+ });
2382
+ if ('drawEnd' in t.props) {
2383
+ t.props.drawEnd(backobj);
2384
+ }
2385
+ });
2386
+ break;
2387
+ }
2388
+ //保存绘制图元的id便于后期比对
2389
+ t.state.drawIds[drawParam.geometryType].push(drawParam.data.id);
2390
+ }
2391
+ //关闭绘制图元
2392
+
2393
+ }, {
2394
+ key: 'closeDraw',
2395
+ value: function closeDraw() {
2396
+ var t = this;
2397
+ t._drawmanager.setDrawingMode(null);
2398
+ }
2399
+ /*
2400
+ 事件处理
2401
+ */
2402
+ //点击图元事件
2403
+
2404
+ }, {
2405
+ key: 'clickGraphic',
2406
+ value: function clickGraphic(id, e) {
2407
+ var t = this;
2408
+ //判断是否点击的测距关闭点位
2409
+ if (id && id.indexOf('vtx_g_rang_end') > -1) {
2410
+ var index = t.GM.getGraphicParam(id).attributes.index;
2411
+ var ls = t.rangingTools[index].line,
2412
+ ps = t.rangingTools[index].points;
2413
+ //删除测距线
2414
+ t.removeGraphic(ls.id, 'line');
2415
+ //删除关闭点
2416
+ t.removeGraphic(id, 'point');
2417
+ //删除中间点
2418
+ for (var i = 0; i < ps.length; i++) {
2419
+ t.removeGraphic(ps[i].id, 'point');
2420
+ }
2421
+ //清除测距数据缓存
2422
+ delete t.rangingTools[index];
2423
+ } else {
2424
+ if (id.indexOf('vtx_g_rang_') > -1) {
2425
+ return false;
2426
+ }
2427
+ //编辑中的图元关闭其他事件返回
2428
+ if (t.state.editId == id) return false;
2429
+ if (typeof t.props.clickGraphic === "function") {
2430
+ var param = t.getGraphic(id);
2431
+ var obj = {
2432
+ param: param,
2433
+ type: param.geometry.type, //图元类型
2434
+ attributes: _extends({}, param.attributes.other, { config: param.attributes.config }), //添加时图元信息
2435
+ top: e.va.y - t.mapTop, //当前点所在的位置(屏幕)
2436
+ left: e.va.x - t.mapLeft,
2437
+ e: e
2438
+ };
2439
+ t.props.clickGraphic(obj);
2440
+ }
2441
+ }
2442
+ }
2443
+ //图元鼠标悬浮事件
2444
+
2445
+ }, {
2446
+ key: 'mouseOverGraphic',
2447
+ value: function mouseOverGraphic(id, e) {
2448
+ var t = this;
2449
+ //编辑中的图元关闭其他事件返回
2450
+ if (t.state.editId == id) return false;
2451
+ if (typeof t.props.mouseOverGraphic === 'function') {
2452
+ if (id.indexOf('vtx_g_rang_') > -1) {
2453
+ return false;
2454
+ }
2455
+ var obj = {
2456
+ e: e, id: id,
2457
+ param: t.getGraphic(id),
2458
+ top: e.va.y - t.mapTop, //当前点所在的位置(屏幕)
2459
+ left: e.va.x - t.mapLeft
2460
+ };
2461
+ t.props.mouseOverGraphic(obj);
2462
+ }
2463
+ }
2464
+ //图元鼠标移开事件
2465
+
2466
+ }, {
2467
+ key: 'mouseOutGraphic',
2468
+ value: function mouseOutGraphic(id, e) {
2469
+ var t = this;
2470
+ //编辑中的图元关闭其他事件返回
2471
+ if (t.state.editId == id) return false;
2472
+ if (typeof t.props.mouseOutGraphic === "function") {
2473
+ if (id.indexOf('vtx_g_rang_') > -1) {
2474
+ return false;
2475
+ }
2476
+ var obj = {
2477
+ e: e, id: id,
2478
+ param: t.getGraphic(id),
2479
+ top: e.va.y - t.mapTop, //当前点所在的位置(屏幕)
2480
+ left: e.va.x - t.mapLeft
2481
+ };
2482
+ t.props.mouseOutGraphic(obj);
2483
+ }
2484
+ }
2485
+ /*
2486
+ 地图服务功能
2487
+ */
2488
+ //开启路况
2489
+
2490
+ }, {
2491
+ key: 'openTrafficInfo',
2492
+ value: function openTrafficInfo() {
2493
+ var t = this;
2494
+ if (!t.trafficLayer) {
2495
+ t.trafficLayer = new google.maps.TrafficLayer();
2496
+ }
2497
+ t.trafficLayer.setMap(t.state.gis);
2498
+ }
2499
+ //关闭路况
2500
+
2501
+ }, {
2502
+ key: 'hideTrafficInfo',
2503
+ value: function hideTrafficInfo() {
2504
+ var t = this;
2505
+ if (t.trafficLayer) {
2506
+ t.trafficLayer.setMap(null);
2507
+ }
2508
+ }
2509
+ //测距功能
2510
+
2511
+ }, {
2512
+ key: 'vtxRangingTool',
2513
+ value: function vtxRangingTool(mapRangingTool) {
2514
+ var t = this;
2515
+ var _t$state2 = t.state,
2516
+ lineIds = _t$state2.lineIds,
2517
+ polygonIds = _t$state2.polygonIds,
2518
+ circleIds = _t$state2.circleIds;
2519
+
2520
+ var gids = [].concat(_toConsumableArray(lineIds), _toConsumableArray(polygonIds), _toConsumableArray(circleIds));
2521
+ t.state.gis.disableDoubleClickZoom = true;
2522
+ t.state.gis.draggableCursor = 'crosshair';
2523
+ //开启测距状态
2524
+ if (!t.rangingTool.isRanging) {
2525
+ t.rangingTool.isRanging = true;
2526
+ }
2527
+ //初始测距回调
2528
+ if (!t.rangingTool.mapRangingTool) {
2529
+ t.rangingTool.mapRangingTool = mapRangingTool;
2530
+ }
2531
+ if (!t.rangingToolFun) {
2532
+ /*测距功能*/
2533
+ t.rangingToolFun = function (e, status) {
2534
+ var fun = function fun() {
2535
+ t.rangingTool.isDbclick = false;
2536
+ if (t.rangingTool.isRanging) {
2537
+ //测距开始
2538
+ //点击位置
2539
+ var ftp = t.canvasProjectionOverlay.getProjection(),
2540
+ lnglat = ftp.fromContainerPixelToLatLng(new google.maps.Point(e.va.x - t.mapLeft, e.va.y - t.mapTop)),
2541
+ lnlt = [lnglat.lng(), lnglat.lat()];
2542
+ //2个点以上 计算长度
2543
+ if (t.rangingTool.points.length > 0) {
2544
+ t.rangingTool.distance += t.calculatePointsDistance(lnlt, [t.rangingTool.points[t.rangingTool.points.length - 1].longitude, t.rangingTool.points[t.rangingTool.points.length - 1].latitude]);
2545
+ } else {
2546
+ t.rangingTool.line.paths = [];
2547
+ }
2548
+ t.rangingTool.line.paths.push([].concat(lnlt));
2549
+ //处理距离展示
2550
+ var distext = t.rangingTool.distance > 0 ? t.rangingTool.distance > 1000 ? '\u603B\u957F:' + Math.round(t.rangingTool.distance / 10) / 100 + '\u516C\u91CC' : '\u603B\u957F:' + t.rangingTool.distance + '\u7C73' : '起点';
2551
+ //加点
2552
+ var point = {
2553
+ id: t.rangingTool.points.length + 'vtx_g_rang_p' + Math.random(),
2554
+ longitude: lnlt[0],
2555
+ latitude: lnlt[1],
2556
+ markerContent: '\n <div style=\'z-index:1; height: 0px;\'>\n <div class=\'vtx-g-rangingPoint\'></div>\n <div class=\'vtx-g-rangingDistance\'>' + distext + '</div>\n </div>\n ',
2557
+ config: {
2558
+ markerContentX: -5.5,
2559
+ markerContentY: -12.5
2560
+ }
2561
+ };
2562
+ //用addpoint方法加点
2563
+ t.addPoint([point]);
2564
+ //缓存点信息
2565
+ t.rangingTool.points.push(point);
2566
+ if (t.rangingTool.line.paths.length == 2) {
2567
+ //加线
2568
+ t.rangingTool.line = {
2569
+ id: 'vtx_g_rang_line' + Math.random(),
2570
+ paths: [].concat(_toConsumableArray(t.rangingTool.line.paths)),
2571
+ config: {
2572
+ color: '#108ee9',
2573
+ lineWidth: 2,
2574
+ lineType: 'solid'
2575
+ }
2576
+ };
2577
+ t.addLine([t.rangingTool.line]);
2578
+ } else if (t.rangingTool.line.paths.length > 2) {
2579
+ t.updateLine([_extends({}, t.rangingTool.line, {
2580
+ paths: [].concat(_toConsumableArray(t.rangingTool.line.paths))
2581
+ })]);
2582
+ }
2583
+ //双击 测距结束
2584
+ if (status == 'dbl') {
2585
+ var rangkey = new Date().getTime() + Math.random();
2586
+ //加结束点
2587
+ var end = {
2588
+ id: 'vtx_g_rang_end' + Math.random(),
2589
+ longitude: lnlt[0],
2590
+ latitude: lnlt[1],
2591
+ markerContent: '\n <div>\n <div class=\'vtx-g-rang-exit\'>x</div>\n </div>\n ',
2592
+ config: {
2593
+ width: 13,
2594
+ height: 13,
2595
+ markerContentX: -20,
2596
+ markerContentY: -20
2597
+ },
2598
+ index: rangkey
2599
+ };
2600
+ //用addpoint方法加点
2601
+ t.addPoint([end]);
2602
+ //删除提示框
2603
+ t.removeGraphic('vtx_g_rang_showRangTool', 'point');
2604
+ t.removeGraphic('vtx_g_rang_showRangTool_line', 'line');
2605
+ //缓存当前这一条测距数据
2606
+ t.rangingTools[rangkey] = _extends({}, t.rangingTool);
2607
+ //回调测距参数
2608
+ if (t.rangingTool.mapRangingTool) {
2609
+ t.rangingTool.mapRangingTool({
2610
+ distance: t.rangingTool.distance,
2611
+ lnglats: t.rangingTool.line.paths
2612
+ });
2613
+ }
2614
+ }
2615
+ }
2616
+ };
2617
+ if (status !== 'dbl') {
2618
+ //100毫秒内点击2次 则结束
2619
+ if (!t.rangingTool.isDbclick) {
2620
+ t.rangingTool.isDbclick = true;
2621
+ } else {
2622
+ if (t.rangingTool.dbclickTimer) {
2623
+ clearTimeout(t.rangingTool.dbclickTimer);
2624
+ }
2625
+ t.rangingTool.isDbclick = false;
2626
+ t.rangingToolEndFun(e);
2627
+ }
2628
+ t.rangingTool.dbclickTimer = setTimeout(function () {
2629
+ fun();
2630
+ }, 200);
2631
+ } else {
2632
+ fun();
2633
+ }
2634
+ };
2635
+ }
2636
+ if (!t.rangingToolMoveFun) {
2637
+ t.rangingToolMoveFun = function (e) {
2638
+ //获取测距提示点位
2639
+ var rp = _extends({}, t.GM.getGraphicParam('vtx_g_rang_showRangTool').attributes);
2640
+ //删除多余数据,避免other层级太多
2641
+ delete rp.other;
2642
+ var rcontent = rp.markerContent;
2643
+ if (t.rangingTool.points.length > 0) {
2644
+ var distance = t.calculatePointsDistance([e.latLng.lng(), e.latLng.lat()], [t.rangingTool.points[t.rangingTool.points.length - 1].longitude, t.rangingTool.points[t.rangingTool.points.length - 1].latitude], t.state.gis, t.grwkid);
2645
+ // 实时计算距离
2646
+ distance += t.rangingTool.distance;
2647
+ var distext = distance > 1000 ? '\u603B\u957F:' + Math.round(distance / 10) / 100 + '\u516C\u91CC' : '\u603B\u957F:' + distance + '\u7C73';
2648
+ rcontent = '\n <div class=\'vtx-g-rang-showRangTool\'>\n <div>' + distext + '</div>\n <div>\u5355\u51FB\u786E\u5B9A\u5730\u70B9,\u53CC\u51FB\u7ED3\u675F</div>\n </div>\n ';
2649
+ //测距移动的线
2650
+ var sl = {
2651
+ id: 'vtx_g_rang_showRangTool_line',
2652
+ paths: [[t.rangingTool.points[t.rangingTool.points.length - 1].longitude, t.rangingTool.points[t.rangingTool.points.length - 1].latitude], [e.latLng.lng(), e.latLng.lat()]],
2653
+ config: {
2654
+ color: '#108ee9',
2655
+ lineWidth: 2,
2656
+ lineType: 'dashed',
2657
+ pellucidity: 0.5
2658
+ }
2659
+ };
2660
+ if (!t.GM.getGraphic('vtx_g_rang_showRangTool_line')) {
2661
+ t.addLine([sl]);
2662
+ t.GM.getGraphic('vtx_g_rang_showRangTool_line').addListener('dblclick', function (e) {
2663
+ t.rangingToolEndFun(e);
2664
+ });
2665
+ } else {
2666
+ t.updateLine([sl]);
2667
+ }
2668
+ }
2669
+ rp = _extends({}, rp, {
2670
+ longitude: e.latLng.lng(),
2671
+ latitude: e.latLng.lat(),
2672
+ markerContent: rcontent
2673
+ });
2674
+ t.updatePoint([rp], 'nodeg');
2675
+ };
2676
+ }
2677
+ if (!t.rangingToolEndFun) {
2678
+ t.rangingToolEndFun = function (e) {
2679
+ t.state.gis.disableDoubleClickZoom = false;
2680
+ //测距完结
2681
+ if (t.rangingTool.isRanging) {
2682
+ if (t.rangingTool.points.length > 0) {
2683
+ //处理点击和双击事件逻辑
2684
+ t.rangingToolFun(e, 'dbl');
2685
+ //回调测距参数
2686
+ if (t.rangingTool.mapRangingTool) {
2687
+ t.rangingTool.mapRangingTool({
2688
+ distance: t.rangingTool.distance,
2689
+ lnglats: t.rangingTool.line.paths
2690
+ });
2691
+ }
2692
+ } else {
2693
+ //删除提示框
2694
+ t.removeGraphic('vtx_g_rang_showRangTool', 'point');
2695
+ }
2696
+ //关闭监听事件
2697
+ for (var i in t.rangingTool.eventList) {
2698
+ if (t.rangingTool.eventList[i]) {
2699
+ t.rangingTool.eventList[i].remove();
2700
+ }
2701
+ }
2702
+ t.rangingTool = _extends({}, t.rangingTool, {
2703
+ isRanging: false, //是否开启状态
2704
+ line: {}, //线缓存
2705
+ points: [], //点
2706
+ distance: 0, //测距长度
2707
+ isDbclick: false,
2708
+ dbclickTimer: null
2709
+ });
2710
+ t.rangingToolFun = null;
2711
+ t.rangingToolMoveFun = null;
2712
+ t.state.gis.draggableCursor = 'url("http://maps.gstatic.cn/mapfiles/openhand_8_8.cur"), default';
2713
+ }
2714
+ };
2715
+ }
2716
+ //避免鼠标在图元上 测距工具不起作用
2717
+ gids.forEach(function (item) {
2718
+ t.rangingTool.eventList[item] = t.GM.getGraphic(item).addListener('mousemove', function (e) {
2719
+ if (t.rangingTool.isRanging && t.rangingToolMoveFun) {
2720
+ t.rangingToolMoveFun(e);
2721
+ }
2722
+ });
2723
+ });
2724
+ //地图鼠标移入事件
2725
+ t.rangingTool.eventList['mouseover'] = t.state.gis.addListener('mouseover', function (e) {
2726
+ //鼠标移出地图时,删除测距显示点
2727
+ if (t.rangingTool.isRanging) {
2728
+ var rp = {
2729
+ id: 'vtx_g_rang_showRangTool',
2730
+ longitude: e.latLng.lng(),
2731
+ latitude: e.latLng.lat(),
2732
+ markerContent: '\n <div class=\'vtx-g-rang-showRangTool\'>\u5355\u51FB\u786E\u5B9A\u8D77\u70B9</div>\n ',
2733
+ config: {
2734
+ markerContentX: 20,
2735
+ markerContentY: 20
2736
+ }
2737
+ };
2738
+ t.addPoint([rp], 'nodeg');
2739
+ }
2740
+ });
2741
+ //地图鼠标移出事件
2742
+ t.rangingTool.eventList['mouseout'] = t.state.gis.addListener('mouseout', function (e) {
2743
+ //鼠标移出地图时,删除测距显示点
2744
+ if (t.rangingTool.isRanging) {
2745
+ t.removeGraphic('vtx_g_rang_showRangTool', 'point');
2746
+ }
2747
+ });
2748
+ //地图鼠标移动事件
2749
+ t.rangingTool.eventList['mousemove'] = t.state.gis.addListener('mousemove', function (e) {
2750
+ //鼠标移动地图时,删除测距显示点
2751
+ if (t.rangingTool.isRanging && t.rangingToolMoveFun) {
2752
+ t.rangingToolMoveFun(e);
2753
+ }
2754
+ });
2755
+ //双击事件
2756
+ t.rangingTool.eventList['dblclick'] = t.state.gis.addListener('dblclick', function (e) {
2757
+ t.rangingToolEndFun(e);
2758
+ });
2759
+ }
2760
+ //聚合地图图元(arg为空时聚合全部点)
2761
+
2762
+ }, {
2763
+ key: 'cluster',
2764
+ value: function cluster(arg) {
2765
+ var t = this;
2766
+ var ary = t.clusterToolFunction(arg);
2767
+ t._cluster.addMarkers(ary);
2768
+ }
2769
+ //删除点聚合效果
2770
+
2771
+ }, {
2772
+ key: 'removeCluster',
2773
+ value: function removeCluster(arg) {
2774
+ var t = this;
2775
+ var ary = t.clusterToolFunction(arg);
2776
+ if (ary.length > 0) {
2777
+ t._cluster.removeMarkers(ary);
2778
+ }
2779
+ }
2780
+ //清空聚合效果
2781
+
2782
+ }, {
2783
+ key: 'clearClusters',
2784
+ value: function clearClusters() {
2785
+ var t = this;
2786
+ t._cluster.clearMarkers();
2787
+ }
2788
+ //聚合功能公共方法(获取图元集合)
2789
+
2790
+ }, {
2791
+ key: 'clusterToolFunction',
2792
+ value: function clusterToolFunction(arg) {
2793
+ var t = this;
2794
+ var ary = [];
2795
+ if (!arg) {
2796
+ var pointIds = t.state.pointIds;
2797
+
2798
+ ary = pointIds.filter(function (item, index) {
2799
+ return item.indexOf(vtx_g_rang) == -1;
2800
+ });
2801
+ } else {
2802
+ if (Object.prototype.toString.apply(arg) === '[object Array]') {
2803
+ ary = arg;
2804
+ } else if (typeof arg === 'string') {
2805
+ ary = arg.split(',');
2806
+ }
2807
+ }
2808
+ t.clusterIdList = ary;
2809
+ //过滤moveTo的点位
2810
+ //缓存所有聚合的点位
2811
+ var allps = [];
2812
+ for (var i = 0; i < ary.length; i++) {
2813
+ var gc = t.GM.getGraphic(ary[i]);
2814
+ allps.push(gc);
2815
+ //加入label图元
2816
+ if (gc.ishaveLabel) {
2817
+ allps.push(t.GM.getGraphic(ary[i] + '_vtxoMap_label'));
2818
+ }
2819
+ }
2820
+ return allps;
2821
+ }
2822
+ /*地图事件处理*/
2823
+ //地图点击事件
2824
+
2825
+ }, {
2826
+ key: 'clickMap',
2827
+ value: function clickMap() {
2828
+ var t = this;
2829
+ if (typeof t.props.clickMap === "function") {
2830
+ t.state.gis.addListener('click', function (e) {
2831
+ //测距点击事件
2832
+ if (t.rangingTool.isRanging) {
2833
+ t.rangingToolFun(e);
2834
+ } else {
2835
+ var obj = t.getMapExtent();
2836
+ obj.e = e;
2837
+ obj.clickLngLat = e.point;
2838
+ obj.pixel = {
2839
+ x: e.va.x - t.mapLeft,
2840
+ y: e.va.y - t.mapTop
2841
+ };
2842
+ t.props.clickMap(obj);
2843
+ }
2844
+ });
2845
+ }
2846
+ }
2847
+ //地图拖动之前事件
2848
+
2849
+ }, {
2850
+ key: 'dragMapStart',
2851
+ value: function dragMapStart() {
2852
+ var t = this;
2853
+ if (typeof t.props.dragMapStart === 'function') {
2854
+ t.state.gis.addListener('dragstart', function (e) {
2855
+ var obj = t.getMapExtent();
2856
+ obj.e = e;
2857
+ t.props.dragMapStart(obj);
2858
+ });
2859
+ }
2860
+ }
2861
+ //地图拖动结束后事件
2862
+
2863
+ }, {
2864
+ key: 'dragMapEnd',
2865
+ value: function dragMapEnd() {
2866
+ var t = this;
2867
+ if (typeof t.props.dragMapEnd === 'function') {
2868
+ t.state.gis.addListener('dragend', function (e) {
2869
+ var obj = t.getMapExtent();
2870
+ obj.e = e;
2871
+ t.props.dragMapEnd(obj);
2872
+ });
2873
+ }
2874
+ }
2875
+ //地图移动之前事件
2876
+
2877
+ }, {
2878
+ key: 'moveStart',
2879
+ value: function moveStart() {
2880
+ var t = this;
2881
+ if (typeof t.props.moveStart === 'function') {
2882
+ t.state.gis.addListener('bounds_changed', function (e) {
2883
+ if (t.pointCollectionId) {
2884
+ $('#' + t.pointCollectionId).css({ visibility: 'hidden' });
2885
+ }
2886
+ //区别是否在移动状态
2887
+ if (!t.isZoomming && !t.isMoving) {
2888
+ if (t.oldZoomLevel == t.state.gis.getZoom()) {
2889
+ t.isMoving = true;
2890
+ var obj = t.getMapExtent();
2891
+ obj.e = e;
2892
+ t.props.moveStart(obj);
2893
+ }
2894
+ }
2895
+ });
2896
+ }
2897
+ }
2898
+ //google地图没有move事件和zoomEnd事件,通过模拟实现
2899
+
2900
+ }, {
2901
+ key: 'moveEndAndZoomEnd',
2902
+ value: function moveEndAndZoomEnd() {
2903
+ var t = this;
2904
+ if (typeof t.props.moveEnd === 'function' || typeof t.props.zoomEnd === 'function' || typeof t.props.moveStart === 'function' || typeof t.props.zoomStart === 'function') {
2905
+ t.state.gis.addListener('idle', function (e) {
2906
+ if (t.pointCollectionId) {
2907
+ $('#' + t.pointCollectionId).css({ visibility: 'inherit' });
2908
+ }
2909
+ var obj = t.getMapExtent();
2910
+ obj.e = e;
2911
+ //区别是否在移动状态-同时判断是moveEnd还是zoomEnd
2912
+ if (t.isMoving) {
2913
+ t.isMoving = false;
2914
+ }
2915
+ if (t.isZoomming) {
2916
+ t.isZoomming = false;
2917
+ }
2918
+ if (t.oldZoomLevel != t.state.gis.getZoom()) {
2919
+ t.oldZoomLevel = t.state.gis.getZoom();
2920
+ if (typeof t.props.zoomEnd === 'function') {
2921
+ t.props.zoomEnd(obj);
2922
+ }
2923
+ } else {
2924
+ if (typeof t.props.moveEnd === 'function') {
2925
+ t.props.moveEnd(obj);
2926
+ }
2927
+ }
2928
+ //更新海量点
2929
+ if (t.props.mapPointCollection) {
2930
+ t.updatePointCollection(t.props.mapPointCollection);
2931
+ }
2932
+ });
2933
+ }
2934
+ }
2935
+ //地图更改缩放级别开始时触发触发此事件
2936
+
2937
+ }, {
2938
+ key: 'zoomStart',
2939
+ value: function zoomStart() {
2940
+ var t = this;
2941
+ if (typeof t.props.zoomStart === 'function') {
2942
+ t.state.gis.addListener('zoom_changed', function (e) {
2943
+ if (t.pointCollectionId) {
2944
+ $('#' + t.pointCollectionId).css({ visibility: 'hidden' });
2945
+ }
2946
+ if (!t.isZoomming) {
2947
+ t.isZoomming = true;
2948
+ var obj = t.getMapExtent();
2949
+ obj.e = e;
2950
+ t.props.zoomStart(obj);
2951
+ }
2952
+ });
2953
+ }
2954
+ }
2955
+ //对外使用方法
2956
+ //显示隐藏的图元
2957
+
2958
+ }, {
2959
+ key: 'showGraphicById',
2960
+ value: function showGraphicById(id) {
2961
+ var t = this;
2962
+ if (t.GM.getGraphic(id)) {
2963
+ t.GM.getGraphic(id).setVisible(true);
2964
+ }
2965
+ }
2966
+ //隐藏图元
2967
+
2968
+ }, {
2969
+ key: 'hideGraphicById',
2970
+ value: function hideGraphicById(id) {
2971
+ var t = this;
2972
+ if (t.GM.getGraphic(id)) {
2973
+ t.GM.getGraphic(id).hide(false);
2974
+ }
2975
+ }
2976
+ //内部公共方法区
2977
+ //获取图元数据
2978
+
2979
+ }, {
2980
+ key: 'getGraphic',
2981
+ value: function getGraphic(id) {
2982
+ var t = this;
2983
+ if (!id) {
2984
+ return false;
2985
+ }
2986
+ var gp = t.GM.getGraphicParam(id);
2987
+ var gg = t.GM.getGraphic(id);
2988
+ if (!gg) {
2989
+ return false;
2990
+ }
2991
+ var p = {},
2992
+ pts = [],
2993
+ lng = 0,
2994
+ lat = 0;
2995
+ switch (gp.geometryType) {
2996
+ case 'point':
2997
+ lng = gg.getPosition().lng();
2998
+ lat = gg.getPosition().lat();
2999
+ p = _extends({}, gp, {
3000
+ mapLayer: gg,
3001
+ geometry: _extends({}, gp.geometry, {
3002
+ x: lng,
3003
+ y: lat
3004
+ }),
3005
+ attributes: _extends({}, gp.attributes, {
3006
+ longitude: lng,
3007
+ latitude: lat,
3008
+ other: _extends({}, gp.attributes.other, {
3009
+ longitude: lng,
3010
+ latitude: lat
3011
+ })
3012
+ })
3013
+ });
3014
+ break;
3015
+ case 'polyline':
3016
+ pts = gg.getPath().getArray().map(function (item, index) {
3017
+ return [item.lng(), item.lat()];
3018
+ });
3019
+ p = _extends({}, gp, {
3020
+ mapLayer: gg,
3021
+ geometry: _extends({}, gp.geometry, {
3022
+ paths: pts
3023
+ }),
3024
+ attributes: _extends({}, gp.attributes, {
3025
+ paths: pts,
3026
+ other: _extends({}, gp.attributes.other, {
3027
+ paths: pts
3028
+ })
3029
+ })
3030
+ });
3031
+ break;
3032
+ case 'polygon':
3033
+ pts = gg.getPath().getArray().map(function (item, index) {
3034
+ return [item.lng(), item.lat()];
3035
+ });
3036
+ p = _extends({}, gp, {
3037
+ mapLayer: gg,
3038
+ geometry: _extends({}, gp.geometry, {
3039
+ rings: pts
3040
+ }),
3041
+ attributes: _extends({}, gp.attributes, {
3042
+ rings: pts,
3043
+ other: _extends({}, gp.attributes.other, {
3044
+ rings: pts
3045
+ })
3046
+ })
3047
+ });
3048
+ break;
3049
+ case 'circle':
3050
+ lng = gg.getCenter().lng();
3051
+ lat = gg.getCenter().lat();
3052
+ var radius = gg.getRadius();
3053
+ p = _extends({}, gp, {
3054
+ mapLayer: gg,
3055
+ geometry: _extends({}, gp.geometry, {
3056
+ x: lng,
3057
+ y: lat,
3058
+ radius: radius
3059
+ }),
3060
+ attributes: _extends({}, gp.attributes, {
3061
+ longitude: lng,
3062
+ latitude: lat,
3063
+ radius: radius,
3064
+ other: _extends({}, gp.attributes.other, {
3065
+ longitude: lng,
3066
+ latitude: lat,
3067
+ radius: radius
3068
+ })
3069
+ })
3070
+ });
3071
+ break;
3072
+ }
3073
+ return p;
3074
+ }
3075
+ //获取地图当前的位置状态信息
3076
+
3077
+ }, {
3078
+ key: 'getMapExtent',
3079
+ value: function getMapExtent() {
3080
+ var t = this;
3081
+ var nowBounds = t.state.gis.getBounds();
3082
+ var obj = {};
3083
+ obj.southWest = {
3084
+ lng: nowBounds.getNorthEast().lng(),
3085
+ lat: nowBounds.getNorthEast().lat()
3086
+ };
3087
+ obj.northEast = {
3088
+ lng: nowBounds.getSouthWest().lng(),
3089
+ lat: nowBounds.getSouthWest().lat()
3090
+ };
3091
+ obj.nowCenter = t.state.gis.getCenter();
3092
+ obj.zoom = t.state.gis.getZoom();
3093
+ obj.mapSize = {
3094
+ width: t.state.gis.getDiv().offsetWidth,
3095
+ height: t.state.gis.getDiv().offsetHeight
3096
+ };
3097
+ obj.radius = t.calculatePointsDistance([obj.nowCenter.lng(), obj.nowCenter.lat()], [obj.northEast.lng, obj.northEast.lat]);
3098
+ return obj;
3099
+ }
3100
+ //获取当前比例尺
3101
+
3102
+ }, {
3103
+ key: 'getZoomLevel',
3104
+ value: function getZoomLevel() {
3105
+ var t = this;
3106
+ return t.state.gis.getZoom();
3107
+ }
3108
+ //处理线和面的 经纬度数据
3109
+
3110
+ }, {
3111
+ key: 'dealData',
3112
+ value: function dealData(ms) {
3113
+ //区别点和圆的经纬度数据处理
3114
+ var lnglatAry = [],
3115
+ _extent = { xmax: 0, xmin: 0, ymax: 0, ymin: 0 },
3116
+ path = [];
3117
+ if ('getPath' in ms) {
3118
+ path = ms.getPath().getArray();
3119
+ path = path.map(function (item, index) {
3120
+ var lng = item.lng(),
3121
+ lat = item.lat();
3122
+ if (lng > _extent.xmax) {
3123
+ _extent.xmax = lng;
3124
+ }
3125
+ if (lng < _extent.xmin || _extent.xmin == 0) {
3126
+ _extent.xmin = lng;
3127
+ }
3128
+ if (lat > _extent.ymax) {
3129
+ _extent.ymax = lat;
3130
+ }
3131
+ if (lat < _extent.ymin || _extent.ymin == 0) {
3132
+ _extent.ymin = lat;
3133
+ }
3134
+ lnglatAry.push({
3135
+ lngX: lng,
3136
+ latX: lat
3137
+ });
3138
+ return [lng, lat];
3139
+ });
3140
+ }
3141
+ return { lnglatAry: lnglatAry, _extent: _extent, path: path };
3142
+ }
3143
+ //点位移动动画效果
3144
+
3145
+ }, {
3146
+ key: 'moveAnimation',
3147
+ value: function moveAnimation() {
3148
+ var t = this;
3149
+ if (t.moveToTimer) {
3150
+ clearInterval(t.moveToTimer);
3151
+ }
3152
+ t.moveToTimer = setInterval(function () {
3153
+ for (var i = 0; i < t.movePoints.length; i++) {
3154
+ t.movePoints[i].waitTime += 10;
3155
+ t.movePoints[i].deleteTime -= 10;
3156
+ }
3157
+ t.movePoints.sort(function (x, y) {
3158
+ return y.waitTime - x.waitTime;
3159
+ });
3160
+ var nowMovePoints = t.movePoints.slice(0, 10),
3161
+ deleteIndex = [];
3162
+ for (var _i3 = 0; _i3 < nowMovePoints.length; _i3++) {
3163
+ var _nowMovePoints$_i = nowMovePoints[_i3],
3164
+ id = _nowMovePoints$_i.id,
3165
+ rx = _nowMovePoints$_i.rx,
3166
+ ry = _nowMovePoints$_i.ry,
3167
+ waitTime = _nowMovePoints$_i.waitTime,
3168
+ deleteTime = _nowMovePoints$_i.deleteTime;
3169
+
3170
+ var gc = t.GM.getGraphic(id),
3171
+ gc_label = t.GM.getGraphic(id + '_vtxoMap_label');
3172
+ if (!gc) {
3173
+ clearInterval(t.moveToTimer);
3174
+ } else {
3175
+ if (gc.isAdded) {
3176
+ t._cluster.removeMarker(gc);
3177
+ }
3178
+ if (gc_label && gc_label.isAdded) {
3179
+ t._cluster.removeMarker(gc_label);
3180
+ }
3181
+ var gg = gc.getPosition();
3182
+ var tx = gg.lng() + rx,
3183
+ ty = gg.lat() + ry;
3184
+ gc.setPosition(new t.omap.LatLng({ lng: tx, lat: ty }));
3185
+ if (gc_label) {
3186
+ gc_label.setPosition(new t.omap.LatLng({ lng: tx, lat: ty }));
3187
+ }
3188
+ t.movePoints[_i3].waitTime = 0;
3189
+ if (deleteTime <= 0) {
3190
+ deleteIndex.push(_i3);
3191
+ }
3192
+ }
3193
+ }
3194
+ deleteIndex.sort(function (a, b) {
3195
+ return b - a;
3196
+ });
3197
+ for (var _i4 = 0; _i4 < deleteIndex.length; _i4++) {
3198
+ var _t$movePoints$deleteI = t.movePoints[deleteIndex[_i4]],
3199
+ id = _t$movePoints$deleteI.id,
3200
+ rx = _t$movePoints$deleteI.rx,
3201
+ ry = _t$movePoints$deleteI.ry,
3202
+ waitTime = _t$movePoints$deleteI.waitTime,
3203
+ deleteTime = _t$movePoints$deleteI.deleteTime,
3204
+ _gc = t.GM.getGraphic(id),
3205
+ _gc_label = t.GM.getGraphic(id + '_vtxoMap_label');
3206
+
3207
+ if (t.clusterIdList.indexOf(id) > -1) {
3208
+ t._cluster.addMarker(_gc);
3209
+ if (_gc_label) {
3210
+ t._cluster.addMarker(_gc_label);
3211
+ }
3212
+ }
3213
+ t.movePoints.splice(deleteIndex[_i4], 1);
3214
+ }
3215
+ if (nowMovePoints.length == 0) {
3216
+ clearInterval(t.moveToTimer);
3217
+ }
3218
+ }, 10);
3219
+ }
3220
+ //点位移动逻辑
3221
+
3222
+ }, {
3223
+ key: 'moveTo',
3224
+ value: function moveTo(id, lnglat, delay, autoRotation, urlright, urlleft) {
3225
+ var t = this,
3226
+ timer = 10,
3227
+ gc = t.GM.getGraphic(id);
3228
+ delay = eval(delay || 3) * 1000;
3229
+ var count = delay / timer;
3230
+ var s = gc.getPosition(),
3231
+ e = new t.omap.LatLng({ lng: lnglat[0], lat: lnglat[1] });
3232
+ if (s.equals(e)) {
3233
+ return false;
3234
+ } else {
3235
+ var url = null;
3236
+ //计算角度,旋转
3237
+ if (autoRotation && !gc.isMarkerContent) {
3238
+ var ddeg = t.rotateDeg(s, e);
3239
+ if (urlleft && ddeg < -90 && ddeg > -270) {
3240
+ ddeg += 180;
3241
+ url = urlleft;
3242
+ } else {
3243
+ url = urlright;
3244
+ }
3245
+ var icon = gc.getIcon(),
3246
+ iconUrl = '';
3247
+ // 360deg 不需要旋转
3248
+ if (ddeg % 360 != 0) {
3249
+ iconUrl = new _MapToolFunction.RotateIcon({
3250
+ url: url,
3251
+ width: icon.size.width,
3252
+ height: icon.size.height
3253
+ });
3254
+ }
3255
+ gc.setIcon(_extends({}, icon, { url: iconUrl.setRotation(ddeg).getUrl() }));
3256
+ }
3257
+ //拆分延迟移动定位
3258
+ var rx = (e.lng() - s.lng()) / count,
3259
+ ry = (e.lat() - s.lat()) / count;
3260
+ var isHave = false;
3261
+ for (var i = 0; i < t.movePoints.length; i++) {
3262
+ if (t.movePoints[i].id == id) {
3263
+ t.movePoints.splice(i, 1, {
3264
+ id: id, rx: rx, ry: ry,
3265
+ waitTime: 0,
3266
+ deleteTime: delay
3267
+ });
3268
+ isHave = true;
3269
+ }
3270
+ }
3271
+ if (!isHave) {
3272
+ t.movePoints.push({
3273
+ id: id, rx: rx, ry: ry,
3274
+ waitTime: 0,
3275
+ deleteTime: delay
3276
+ });
3277
+ }
3278
+ }
3279
+ }
3280
+ //点位角度旋转(以指向东(右)为0°)
3281
+
3282
+ }, {
3283
+ key: 'rotateDeg',
3284
+ value: function rotateDeg(sp, ep) {
3285
+ var t = this,
3286
+ deg = 0,
3287
+ ftp = t.canvasProjectionOverlay.getProjection(),
3288
+ spLngLat = sp,
3289
+ epLngLat = ep;
3290
+ if (ftp) {
3291
+ if (Array.isArray(sp)) {
3292
+ spLngLat = new t.omap.LatLng({ lng: sp[0], lat: sp[1] });
3293
+ }
3294
+ if (Array.isArray(ep)) {
3295
+ spLngLat = new t.omap.LatLng({ lng: ep[0], lat: ep[1] });
3296
+ }
3297
+ var s = ftp.fromLatLngToContainerPixel(spLngLat),
3298
+
3299
+ //获取当前点位的经纬度
3300
+ e = ftp.fromLatLngToContainerPixel(epLngLat);
3301
+ if (e.x != s.x) {
3302
+ var tan = (e.y - s.y) / (e.x - s.x),
3303
+ atan = Math.atan(tan);
3304
+ deg = atan * 360 / (2 * Math.PI);
3305
+ //degree correction;
3306
+ if (e.x < s.x) {
3307
+ deg = -deg + 90 + 90;
3308
+ } else {
3309
+ deg = -deg;
3310
+ }
3311
+ deg = -deg;
3312
+ } else {
3313
+ var disy = e.y - s.y;
3314
+ var bias = 0;
3315
+ if (disy > 0) bias = -1;else bias = 1;
3316
+ if (disy == 0) bias = 0;
3317
+ deg = -bias * 90;
3318
+ }
3319
+ }
3320
+ return deg;
3321
+ }
3322
+ /*
3323
+ 匹配控件位置方法
3324
+ (谷歌地图有8个方位,为了统一,只使用左上,左下,右上,右下)
3325
+ */
3326
+
3327
+ }, {
3328
+ key: 'matchControlPosition',
3329
+ value: function matchControlPosition(location) {
3330
+ var position = google.maps.ControlPosition.RIGHT_BOTTOM;
3331
+ switch (location) {
3332
+ case 'tl':
3333
+ position = google.maps.ControlPosition.LEFT_TOP;
3334
+ break;
3335
+ case 'bl':
3336
+ position = google.maps.ControlPosition.LEFT_BOTTOM;
3337
+ break;
3338
+ case 'tr':
3339
+ position = google.maps.ControlPosition.RIGHT_TOP;
3340
+ break;
3341
+ case 'br':
3342
+ position = google.maps.ControlPosition.RIGHT_BOTTOM;
3343
+ break;
3344
+ }
3345
+ return position;
3346
+ }
3347
+ /*
3348
+ 地图内部需要公共方法
3349
+ */
3350
+
3351
+ }, {
3352
+ key: 'calculatePointsDistance',
3353
+ value: function calculatePointsDistance(fp, ep) {
3354
+ if (google.maps.geometry && google.maps.geometry.spherical) {
3355
+ return Math.round(google.maps.geometry.spherical.computeDistanceBetween(new google.maps.LatLng({ lng: fp[0], lat: fp[1] }), new google.maps.LatLng({ lng: ep[0], lat: ep[1] })) * 100) / 100;
3356
+ }
3357
+ return 0;
3358
+ }
3359
+ //计算多个点的距离(常用于线计算)
3360
+
3361
+ }, {
3362
+ key: 'calculateDistance',
3363
+ value: function calculateDistance(ps) {
3364
+ var t = this,
3365
+ totalDistance = 0;
3366
+ if (ps.length < 0) {
3367
+ return false;
3368
+ }
3369
+ for (var i = 0; i < ps.length; i++) {
3370
+ if (i < ps.length - 1) {
3371
+ totalDistance += t.calculatePointsDistance(ps[i], ps[i + 1]);
3372
+ }
3373
+ }
3374
+ return Math.round(totalDistance * 100) / 100;
3375
+ }
3376
+ //计算图元面积(面,圆)
3377
+
3378
+ }, {
3379
+ key: 'calculateArea',
3380
+ value: function calculateArea(id) {
3381
+ var t = this;
3382
+ return google.maps.geometry.spherical.computeArea(t.GM.getGraphic(id).getPath().getArray());
3383
+ }
3384
+ //计算多个点的距离(常用于线计算)[入参是 google 经纬度对象数组]
3385
+
3386
+ }, {
3387
+ key: 'calculateGraphicDistance',
3388
+ value: function calculateGraphicDistance(ary) {
3389
+ var t = this;
3390
+ return google.maps.geometry.spherical.computeLength(ary);
3391
+ }
3392
+ //对比对象数据是否相等
3393
+
3394
+ }, {
3395
+ key: 'deepEqual',
3396
+ value: function deepEqual(a, b) {
3397
+ return _immutable2.default.is(_immutable2.default.fromJS(a), _immutable2.default.fromJS(b));
3398
+ }
3399
+ //数据解析(分析,新增,更新,删除对应的数据)
3400
+
3401
+ }, {
3402
+ key: 'dataMatch',
3403
+ value: function dataMatch(oldData, newData, type) {
3404
+ var onlyOldData = Set(oldData).subtract(Set(newData)).toJS();
3405
+ var onlyNewData = Set(newData).subtract(Set(oldData)).toJS();
3406
+ var onlyOldIDs = onlyOldData.map(function (item) {
3407
+ return item[type];
3408
+ });
3409
+ var onlyNewIDs = onlyNewData.map(function (item) {
3410
+ return item[type];
3411
+ });
3412
+ var updateDataIDs = Set(onlyOldIDs).intersect(Set(onlyNewIDs)).toJS();
3413
+ var updatedData = onlyNewData.filter(function (item) {
3414
+ return updateDataIDs.indexOf(item[type]) > -1;
3415
+ });
3416
+ var replacedData = onlyOldData.filter(function (item) {
3417
+ return updateDataIDs.indexOf(item[type]) > -1;
3418
+ });
3419
+ var deletedDataIDs = onlyOldIDs.filter(function (oldID) {
3420
+ return updateDataIDs.indexOf(oldID) == -1;
3421
+ });
3422
+ var addedData = onlyNewData.filter(function (item) {
3423
+ return updateDataIDs.indexOf(item[type]) == -1;
3424
+ });
3425
+
3426
+ return { deletedDataIDs: deletedDataIDs, addedData: addedData, updatedData: updatedData, replacedData: replacedData };
3427
+ }
3428
+ //处理需要增加图元的数据(避免意外问题)
3429
+
3430
+ }, {
3431
+ key: 'dealAdd',
3432
+ value: function dealAdd(ary, ids) {
3433
+ var ads = [],
3434
+ otherupds = [];
3435
+ for (var i = 0; i < ary.length; i++) {
3436
+ if (ids.indexOf(ary[i].id) > -1) {
3437
+ otherupds.push(ary[i]);
3438
+ } else {
3439
+ ads.push(ary[i]);
3440
+ }
3441
+ }
3442
+ return { ads: ads, otherupds: otherupds };
3443
+ }
3444
+ //处理需要更新图元的数据(避免意外问题)
3445
+
3446
+ }, {
3447
+ key: 'dealUpdate',
3448
+ value: function dealUpdate(ary, ids) {
3449
+ var upds = [],
3450
+ otherads = [];
3451
+ for (var i = 0; i < ary.length; i++) {
3452
+ if (ids.indexOf(ary[i].id) > -1) {
3453
+ upds.push(ary[i]);
3454
+ } else {
3455
+ otherads.push(ary[i]);
3456
+ }
3457
+ }
3458
+ return { upds: upds, otherads: otherads };
3459
+ }
3460
+ //渲染
3461
+
3462
+ }, {
3463
+ key: 'render',
3464
+ value: function render() {
3465
+ var t = this;
3466
+ var _map = this.props;
3467
+ return _react2.default.createElement('div', { id: _map.mapId, style: { width: '100%', height: '100%' } });
3468
+ }
3469
+ //初始化
3470
+
3471
+ }, {
3472
+ key: 'componentDidMount',
3473
+ value: function componentDidMount() {
3474
+ var t = this;
3475
+ t.loadMapComplete.then(function () {
3476
+ t.mapLeft = document.getElementById(t.props.mapId).offsetLeft;
3477
+ t.mapTop = document.getElementById(t.props.mapId).offsetTop;
3478
+ t.init();
3479
+ });
3480
+ }
3481
+ //重新渲染结束
3482
+
3483
+ }, {
3484
+ key: 'componentDidUpdate',
3485
+ value: function componentDidUpdate(prevProps, prevState) {}
3486
+ //已加载组件,收到新的参数时调用
3487
+
3488
+ }, {
3489
+ key: 'componentWillReceiveProps',
3490
+ value: function componentWillReceiveProps(nextProps) {
3491
+ var t = this;
3492
+ //点/线旧数据
3493
+ var _t$state3 = t.state,
3494
+ pointIds = _t$state3.pointIds,
3495
+ lineIds = _t$state3.lineIds,
3496
+ polygonIds = _t$state3.polygonIds,
3497
+ circleIds = _t$state3.circleIds,
3498
+ drawIds = _t$state3.drawIds;
3499
+ var point = drawIds.point,
3500
+ polyline = drawIds.polyline,
3501
+ polygon = drawIds.polygon,
3502
+ circle = drawIds.circle,
3503
+ rectangle = drawIds.rectangle;
3504
+ //点/线新数据
3505
+
3506
+ var _nextProps$mapPoints = nextProps.mapPoints,
3507
+ mapPoints = _nextProps$mapPoints === undefined ? [] : _nextProps$mapPoints,
3508
+ _nextProps$mapLines = nextProps.mapLines,
3509
+ mapLines = _nextProps$mapLines === undefined ? [] : _nextProps$mapLines,
3510
+ _nextProps$mapPolygon = nextProps.mapPolygons,
3511
+ mapPolygons = _nextProps$mapPolygon === undefined ? [] : _nextProps$mapPolygon,
3512
+ _nextProps$mapCircles = nextProps.mapCircles,
3513
+ mapCircles = _nextProps$mapCircles === undefined ? [] : _nextProps$mapCircles,
3514
+ _nextProps$customized = nextProps.customizedBoundary,
3515
+ customizedBoundary = _nextProps$customized === undefined ? [] : _nextProps$customized,
3516
+ isOpenTrafficInfo = nextProps.isOpenTrafficInfo,
3517
+ boundaryName = nextProps.boundaryName,
3518
+ heatMapData = nextProps.heatMapData,
3519
+ mapVisiblePoints = nextProps.mapVisiblePoints,
3520
+ setVisiblePoints = nextProps.setVisiblePoints,
3521
+ setCenter = nextProps.setCenter,
3522
+ mapCenter = nextProps.mapCenter,
3523
+ setZoomLevel = nextProps.setZoomLevel,
3524
+ mapZoomLevel = nextProps.mapZoomLevel,
3525
+ setCluster = nextProps.setCluster,
3526
+ mapCluster = nextProps.mapCluster,
3527
+ isRangingTool = nextProps.isRangingTool,
3528
+ mapRangingTool = nextProps.mapRangingTool,
3529
+ isRemove = nextProps.isRemove,
3530
+ mapRemove = nextProps.mapRemove,
3531
+ mapDraw = nextProps.mapDraw,
3532
+ isDraw = nextProps.isDraw,
3533
+ isCloseDraw = nextProps.isCloseDraw,
3534
+ editGraphicId = nextProps.editGraphicId,
3535
+ isDoEdit = nextProps.isDoEdit,
3536
+ isEndEdit = nextProps.isEndEdit,
3537
+ mapPointCollection = nextProps.mapPointCollection,
3538
+ isclearAllPointCollection = nextProps.isclearAllPointCollection,
3539
+ isSetAreaRestriction = nextProps.isSetAreaRestriction,
3540
+ areaRestriction = nextProps.areaRestriction,
3541
+ isClearAreaRestriction = nextProps.isClearAreaRestriction,
3542
+ isClearAll = nextProps.isClearAll;
3543
+
3544
+ var props = t.props;
3545
+
3546
+ // 等待地图加载
3547
+ if (!t.state.mapCreated) return;
3548
+
3549
+ /*添加海量点*/
3550
+ if (mapPointCollection instanceof Array && props.mapPointCollection instanceof Array && !t.deepEqual(mapPointCollection, props.mapPointCollection)) {
3551
+ var _t$dataMatch = t.dataMatch(props.mapPointCollection, mapPointCollection, 'id'),
3552
+ deletedDataIDs = _t$dataMatch.deletedDataIDs,
3553
+ addedData = _t$dataMatch.addedData,
3554
+ updatedData = _t$dataMatch.updatedData;
3555
+
3556
+ t.clearPointCollection(deletedDataIDs);
3557
+ t.addPointCollection(addedData);
3558
+ t.updatePointCollection(updatedData);
3559
+ }
3560
+ if (typeof isclearAllPointCollection == 'boolean' && isclearAllPointCollection || isclearAllPointCollection && isclearAllPointCollection !== t.props.isclearAllPointCollection) {
3561
+ t.clearAllPointCollection();
3562
+ }
3563
+ /*点数据处理
3564
+ pointData[2]相同的点,执行刷新
3565
+ pointData[1]的数据在idsForGraphicId中不存在的,执行新增
3566
+ pointData[0]数据中多余的id,执行删除
3567
+ */
3568
+ if (mapPoints instanceof Array && props.mapPoints instanceof Array && !t.deepEqual(mapPoints, props.mapPoints)) {
3569
+ var oldMapPoints = props.mapPoints;
3570
+ var newMapPoints = mapPoints;
3571
+ //过滤编辑的图元
3572
+ if (!!t.state.editId) {
3573
+ oldMapPoints = props.mapPoints.filter(function (item) {
3574
+ return item.id !== editGraphicId;
3575
+ });
3576
+ newMapPoints = mapPoints.filter(function (item) {
3577
+ return item.id !== editGraphicId;
3578
+ });
3579
+ }
3580
+
3581
+ var _t$dataMatch2 = t.dataMatch(oldMapPoints, newMapPoints, 'id'),
3582
+ _deletedDataIDs = _t$dataMatch2.deletedDataIDs,
3583
+ _addedData = _t$dataMatch2.addedData,
3584
+ _updatedData = _t$dataMatch2.updatedData;
3585
+
3586
+ var _t$dealAdd = t.dealAdd(_addedData, [].concat(_toConsumableArray(pointIds), _toConsumableArray(point))),
3587
+ ads = _t$dealAdd.ads,
3588
+ otherupds = _t$dealAdd.otherupds;
3589
+
3590
+ var _t$dealUpdate = t.dealUpdate(_updatedData, [].concat(_toConsumableArray(pointIds), _toConsumableArray(point))),
3591
+ upds = _t$dealUpdate.upds,
3592
+ otherads = _t$dealUpdate.otherads;
3593
+ //删在增之前,(因为增加后会刷新pointIds的值,造成多删的问题)
3594
+
3595
+
3596
+ var _iteratorNormalCompletion = true;
3597
+ var _didIteratorError = false;
3598
+ var _iteratorError = undefined;
3599
+
3600
+ try {
3601
+ for (var _iterator = _deletedDataIDs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
3602
+ var id = _step.value;
3603
+
3604
+ t.removeGraphic(id, 'point');
3605
+ }
3606
+ //增加
3607
+ } catch (err) {
3608
+ _didIteratorError = true;
3609
+ _iteratorError = err;
3610
+ } finally {
3611
+ try {
3612
+ if (!_iteratorNormalCompletion && _iterator.return) {
3613
+ _iterator.return();
3614
+ }
3615
+ } finally {
3616
+ if (_didIteratorError) {
3617
+ throw _iteratorError;
3618
+ }
3619
+ }
3620
+ }
3621
+
3622
+ t.addPoint([].concat(_toConsumableArray(ads), _toConsumableArray(otherads)));
3623
+ //更新
3624
+ t.updatePoint([].concat(_toConsumableArray(upds), _toConsumableArray(otherupds)));
3625
+ }
3626
+ /*
3627
+ 面数据处理
3628
+ 先全删除,再新增
3629
+ */
3630
+ if (mapPolygons instanceof Array && props.mapPolygons instanceof Array && !t.deepEqual(mapPolygons, props.mapPolygons)) {
3631
+ var oldMapPolygons = props.mapPolygons;
3632
+ var newMapPolygons = mapPolygons;
3633
+ if (!!t.state.editId) {
3634
+ oldMapPolygons = props.mapPolygons.filter(function (item) {
3635
+ return item.id !== editGraphicId;
3636
+ });
3637
+ newMapPolygons = mapPolygons.filter(function (item) {
3638
+ return item.id !== editGraphicId;
3639
+ });
3640
+ }
3641
+
3642
+ var _t$dataMatch3 = t.dataMatch(oldMapPolygons, newMapPolygons, 'id'),
3643
+ _deletedDataIDs2 = _t$dataMatch3.deletedDataIDs,
3644
+ _addedData2 = _t$dataMatch3.addedData,
3645
+ _updatedData2 = _t$dataMatch3.updatedData;
3646
+
3647
+ var _t$dealAdd2 = t.dealAdd(_addedData2, [].concat(_toConsumableArray(rectangle), _toConsumableArray(polygon), _toConsumableArray(polygonIds))),
3648
+ _ads = _t$dealAdd2.ads,
3649
+ _otherupds = _t$dealAdd2.otherupds;
3650
+
3651
+ var _t$dealUpdate2 = t.dealUpdate(_updatedData2, [].concat(_toConsumableArray(rectangle), _toConsumableArray(polygon), _toConsumableArray(polygonIds))),
3652
+ _upds = _t$dealUpdate2.upds,
3653
+ _otherads = _t$dealUpdate2.otherads;
3654
+ //删在增之前,(因为增加后会刷新pointIds的值,造成多删的问题)
3655
+
3656
+
3657
+ var _iteratorNormalCompletion2 = true;
3658
+ var _didIteratorError2 = false;
3659
+ var _iteratorError2 = undefined;
3660
+
3661
+ try {
3662
+ for (var _iterator2 = _deletedDataIDs2[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
3663
+ var _id = _step2.value;
3664
+
3665
+ t.removeGraphic(_id, 'polygon');
3666
+ }
3667
+ //增加
3668
+ } catch (err) {
3669
+ _didIteratorError2 = true;
3670
+ _iteratorError2 = err;
3671
+ } finally {
3672
+ try {
3673
+ if (!_iteratorNormalCompletion2 && _iterator2.return) {
3674
+ _iterator2.return();
3675
+ }
3676
+ } finally {
3677
+ if (_didIteratorError2) {
3678
+ throw _iteratorError2;
3679
+ }
3680
+ }
3681
+ }
3682
+
3683
+ t.addPolygon([].concat(_toConsumableArray(_ads), _toConsumableArray(_otherads)));
3684
+ //更新
3685
+ t.updatePolygon([].concat(_toConsumableArray(_upds), _toConsumableArray(_otherupds)));
3686
+ }
3687
+ /*
3688
+ 圆数据处理
3689
+ 先全删除,再新增
3690
+ */
3691
+ if (mapCircles instanceof Array && props.mapCircles instanceof Array && !t.deepEqual(mapCircles, props.mapCircles)) {
3692
+ var oldMapCircles = props.mapCircles;
3693
+ var newMapCircles = mapCircles;
3694
+ if (!!t.state.editId) {
3695
+ oldMapCircles = props.mapCircles.filter(function (item) {
3696
+ return item.id !== editGraphicId;
3697
+ });
3698
+ newMapCircles = mapCircles.filter(function (item) {
3699
+ return item.id !== editGraphicId;
3700
+ });
3701
+ }
3702
+
3703
+ var _t$dataMatch4 = t.dataMatch(oldMapCircles, newMapCircles, 'id'),
3704
+ _deletedDataIDs3 = _t$dataMatch4.deletedDataIDs,
3705
+ _addedData3 = _t$dataMatch4.addedData,
3706
+ _updatedData3 = _t$dataMatch4.updatedData;
3707
+
3708
+ var _t$dealAdd3 = t.dealAdd(_addedData3, [].concat(_toConsumableArray(circleIds), _toConsumableArray(circle))),
3709
+ _ads2 = _t$dealAdd3.ads,
3710
+ _otherupds2 = _t$dealAdd3.otherupds;
3711
+
3712
+ var _t$dealUpdate3 = t.dealUpdate(_updatedData3, [].concat(_toConsumableArray(circleIds), _toConsumableArray(circle))),
3713
+ _upds2 = _t$dealUpdate3.upds,
3714
+ _otherads2 = _t$dealUpdate3.otherads;
3715
+ //删在增之前,(因为增加后会刷新pointIds的值,造成多删的问题)
3716
+
3717
+
3718
+ var _iteratorNormalCompletion3 = true;
3719
+ var _didIteratorError3 = false;
3720
+ var _iteratorError3 = undefined;
3721
+
3722
+ try {
3723
+ for (var _iterator3 = _deletedDataIDs3[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
3724
+ var _id2 = _step3.value;
3725
+
3726
+ t.removeGraphic(_id2, 'circle');
3727
+ }
3728
+ //增加
3729
+ } catch (err) {
3730
+ _didIteratorError3 = true;
3731
+ _iteratorError3 = err;
3732
+ } finally {
3733
+ try {
3734
+ if (!_iteratorNormalCompletion3 && _iterator3.return) {
3735
+ _iterator3.return();
3736
+ }
3737
+ } finally {
3738
+ if (_didIteratorError3) {
3739
+ throw _iteratorError3;
3740
+ }
3741
+ }
3742
+ }
3743
+
3744
+ t.addCircle([].concat(_toConsumableArray(_ads2), _toConsumableArray(_otherads2)));
3745
+ //更新
3746
+ t.updateCircle([].concat(_toConsumableArray(_upds2), _toConsumableArray(_otherupds2)));
3747
+ }
3748
+ /*
3749
+ 线数据处理
3750
+ 先全删除,再新增
3751
+ */
3752
+ if (mapLines instanceof Array && props.mapLines instanceof Array && !t.deepEqual(mapLines, props.mapLines)) {
3753
+ var oldMapLines = props.mapLines;
3754
+ var newMapLines = mapLines;
3755
+ if (!!t.state.editId) {
3756
+ oldMapLines = props.mapLines.filter(function (item) {
3757
+ return item.id !== editGraphicId;
3758
+ });
3759
+ newMapLines = mapLines.filter(function (item) {
3760
+ return item.id !== editGraphicId;
3761
+ });
3762
+ }
3763
+
3764
+ var _t$dataMatch5 = t.dataMatch(oldMapLines, newMapLines, 'id'),
3765
+ _deletedDataIDs4 = _t$dataMatch5.deletedDataIDs,
3766
+ _addedData4 = _t$dataMatch5.addedData,
3767
+ _updatedData4 = _t$dataMatch5.updatedData;
3768
+
3769
+ var _t$dealAdd4 = t.dealAdd(_addedData4, [].concat(_toConsumableArray(lineIds), _toConsumableArray(polyline))),
3770
+ _ads3 = _t$dealAdd4.ads,
3771
+ _otherupds3 = _t$dealAdd4.otherupds;
3772
+
3773
+ var _t$dealUpdate4 = t.dealUpdate(_updatedData4, [].concat(_toConsumableArray(lineIds), _toConsumableArray(polyline))),
3774
+ _upds3 = _t$dealUpdate4.upds,
3775
+ _otherads3 = _t$dealUpdate4.otherads;
3776
+ //删在增之前,(因为增加后会刷新pointIds的值,造成多删的问题)
3777
+
3778
+
3779
+ var _iteratorNormalCompletion4 = true;
3780
+ var _didIteratorError4 = false;
3781
+ var _iteratorError4 = undefined;
3782
+
3783
+ try {
3784
+ for (var _iterator4 = _deletedDataIDs4[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
3785
+ var _id3 = _step4.value;
3786
+
3787
+ t.removeGraphic(_id3, 'line');
3788
+ }
3789
+ //增加
3790
+ } catch (err) {
3791
+ _didIteratorError4 = true;
3792
+ _iteratorError4 = err;
3793
+ } finally {
3794
+ try {
3795
+ if (!_iteratorNormalCompletion4 && _iterator4.return) {
3796
+ _iterator4.return();
3797
+ }
3798
+ } finally {
3799
+ if (_didIteratorError4) {
3800
+ throw _iteratorError4;
3801
+ }
3802
+ }
3803
+ }
3804
+
3805
+ t.addLine([].concat(_toConsumableArray(_ads3), _toConsumableArray(_otherads3)));
3806
+ //更新
3807
+ t.updateLine([].concat(_toConsumableArray(_upds3), _toConsumableArray(_otherupds3)));
3808
+ }
3809
+ //画其他特例线专用
3810
+ if (customizedBoundary instanceof Array && props.customizedBoundary instanceof Array && !t.deepEqual(customizedBoundary, props.customizedBoundary)) {
3811
+ var _t$dataMatch6 = t.dataMatch(props.customizedBoundary, customizedBoundary, 'id'),
3812
+ _deletedDataIDs5 = _t$dataMatch6.deletedDataIDs,
3813
+ _addedData5 = _t$dataMatch6.addedData,
3814
+ _updatedData5 = _t$dataMatch6.updatedData;
3815
+ //删在增之前,(因为增加后会刷新pointIds的值,造成多删的问题)
3816
+
3817
+
3818
+ var _iteratorNormalCompletion5 = true;
3819
+ var _didIteratorError5 = false;
3820
+ var _iteratorError5 = undefined;
3821
+
3822
+ try {
3823
+ for (var _iterator5 = _deletedDataIDs5[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
3824
+ var _id4 = _step5.value;
3825
+
3826
+ t.removeGraphic(_id4, 'line');
3827
+ }
3828
+ } catch (err) {
3829
+ _didIteratorError5 = true;
3830
+ _iteratorError5 = err;
3831
+ } finally {
3832
+ try {
3833
+ if (!_iteratorNormalCompletion5 && _iterator5.return) {
3834
+ _iterator5.return();
3835
+ }
3836
+ } finally {
3837
+ if (_didIteratorError5) {
3838
+ throw _iteratorError5;
3839
+ }
3840
+ }
3841
+ }
3842
+
3843
+ t.addLine(_addedData5);
3844
+ t.updateLine(_updatedData5);
3845
+ }
3846
+ // 获取热力图
3847
+ if (heatMapData && !t.deepEqual(heatMapData, props.heatMapData)) {
3848
+ t.heatMapOverlay(heatMapData);
3849
+ }
3850
+ //图元编辑调用
3851
+ if (typeof isDoEdit == 'boolean' && isDoEdit || isDoEdit && isDoEdit !== t.props.isDoEdit) {
3852
+ t.doEdit(editGraphicId);
3853
+ }
3854
+ //关闭图元编辑
3855
+ if (typeof isEndEdit == 'boolean' && isEndEdit || isEndEdit && isEndEdit !== t.props.isEndEdit) {
3856
+ t.endEdit();
3857
+ }
3858
+ //开启图元绘制
3859
+ if (typeof isDraw == 'boolean' && isDraw || isDraw && isDraw !== t.props.isDraw) {
3860
+ t.draw(mapDraw);
3861
+ }
3862
+ //关闭图元绘制
3863
+ if (typeof isCloseDraw == 'boolean' && isCloseDraw || isCloseDraw && isCloseDraw !== t.props.isCloseDraw) {
3864
+ t.closeDraw();
3865
+ }
3866
+ //设置中心点
3867
+ if (typeof setCenter == 'boolean' && setCenter || setCenter && setCenter !== t.props.setCenter) {
3868
+ t.setCenter(mapCenter);
3869
+ }
3870
+ //设置点聚合
3871
+ if (typeof setCluster == 'boolean' && setCluster || setCluster && setCluster !== t.props.setCluster) {
3872
+ t.cluster(mapCluster);
3873
+ }
3874
+ //设置比例尺
3875
+ if (typeof setZoomLevel == 'boolean' && setZoomLevel || setZoomLevel && setZoomLevel !== t.props.setZoomLevel) {
3876
+ t.setZoomLevel(mapZoomLevel);
3877
+ }
3878
+ /*设置指定图元展示*/
3879
+ if (typeof setVisiblePoints == 'boolean' && setVisiblePoints || setVisiblePoints && setVisiblePoints !== t.props.setVisiblePoints) {
3880
+ t.setVisiblePoints(mapVisiblePoints);
3881
+ }
3882
+ //测距工具调用
3883
+ if (typeof isRangingTool == 'boolean' && isRangingTool || isRangingTool && isRangingTool !== t.props.isRangingTool) {
3884
+ t.vtxRangingTool(mapRangingTool);
3885
+ }
3886
+ //开关路况
3887
+ if (isOpenTrafficInfo) {
3888
+ t.openTrafficInfo();
3889
+ } else {
3890
+ t.hideTrafficInfo();
3891
+ }
3892
+ //清空地图
3893
+ if (typeof isClearAll == 'boolean' && isClearAll || isClearAll && isClearAll !== t.props.isClearAll) {
3894
+ t.clearAll();
3895
+ }
3896
+ //删除指定图元
3897
+ if (typeof isRemove == 'boolean' && isRemove || isRemove && isRemove !== t.props.isRemove) {
3898
+ mapRemove.map(function (item, index) {
3899
+ t.removeGraphic(item.id, item.type);
3900
+ });
3901
+ }
3902
+ }
3903
+ }, {
3904
+ key: 'componentWillUnmount',
3905
+ value: function componentWillUnmount() {
3906
+ //关闭moveTo定时
3907
+ var t = this;
3908
+ if (t.loadLabel) {
3909
+ clearInterval(t.loadLabel);
3910
+ }
3911
+ if (t.upPsTimer) {
3912
+ clearTimeout(t.upPsTimer);
3913
+ }
3914
+ if (t.addPsTimer) {
3915
+ clearTimeout(t.addPsTimer);
3916
+ }
3917
+ if (t.state.gis) {
3918
+ t.state.gis.clearOverlays();
3919
+ }
3920
+ t.state.gis = null;
3921
+ if (t.moveToTimer) {
3922
+ clearInterval(t.moveToTimer);
3923
+ }
3924
+ window.VtxMap[t.state.mapId] = null;
3925
+ }
3926
+ }]);
3927
+
3928
+ return Map;
3929
+ }(_react2.default.Component);
3930
+
3931
+ exports.default = Map;
3932
+ module.exports = exports['default'];