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