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