@vtx/map 1.1.7 → 1.1.8

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.
@@ -75,6 +75,7 @@ var OlMap = function (_React$Component) {
75
75
  sketch: null,
76
76
  listener: null
77
77
  };
78
+ _this.pointLayers = [];
78
79
  _this.mouseNowPosition = { x: 0, y: 0, px: 0, py: 0, isCount: false };
79
80
  _this.heatmap = null; //热力图对象
80
81
  _this.clusterMarkers = []; //聚合点位id数组
@@ -156,7 +157,7 @@ var OlMap = function (_React$Component) {
156
157
  });
157
158
  });
158
159
  var Client9 = new Promise(function (resolve, reject) {
159
- $.getScript(_default2.default.openlayerServerURL + '/iclient9-openlayers.js', function () {
160
+ $.getScript(_default2.default.openlayerServerURL + '/iclient-openlayers.min.js', function () {
160
161
  resolve();
161
162
  });
162
163
  });
@@ -1117,8 +1118,18 @@ var OlMap = function (_React$Component) {
1117
1118
  key: 'formatLength',
1118
1119
  value: function formatLength(line) {
1119
1120
  var flatCoordinates = line.flatCoordinates;
1121
+ // const length = new ol.sphere.getDistance([flatCoordinates[0], flatCoordinates[1]],[flatCoordinates[2], flatCoordinates[3]]);
1120
1122
 
1121
- var length = new ol.sphere.getDistance([flatCoordinates[0], flatCoordinates[1]], [flatCoordinates[2], flatCoordinates[3]]);
1123
+ var paths = [];
1124
+ for (var n = 0; n < flatCoordinates.length; n += 2) {
1125
+ paths.push([flatCoordinates[n], flatCoordinates[n + 1]]);
1126
+ }
1127
+ var length = 0;
1128
+ if (paths.length >= 2) paths.map(function (item, index) {
1129
+ if (index <= paths.length - 2) {
1130
+ length += ol.sphere.getDistance(paths[index], paths[index + 1]);
1131
+ }
1132
+ });
1122
1133
  var output = '';
1123
1134
  if (length > 100) {
1124
1135
  output = Math.round(length / 1000 * 100) / 100 + ' ' + 'km';
@@ -1481,7 +1492,6 @@ var OlMap = function (_React$Component) {
1481
1492
  var t = this;
1482
1493
  var ps = [];
1483
1494
  var psids = [].concat(_toConsumableArray(t.state.pointIds));
1484
- console.log('addPoint', mapPoints);
1485
1495
  mapPoints.map(function (item, index) {
1486
1496
  //如果id重复,直接跳过不执行.
1487
1497
  if (_this2.GM.isRepetition(item.id)) {
@@ -1535,28 +1545,38 @@ var OlMap = function (_React$Component) {
1535
1545
  });
1536
1546
  t.state.gis.addOverlay(pop);
1537
1547
  } else {
1548
+ var myImage = new Image(cg.width, cg.height);
1549
+ canvasDataURL(item.url || _default2.default.mapServerURL + '/images/defaultMarker.png', { width: cg.width, height: cg.height }, function (base64) {
1550
+ myImage.src = base64;
1551
+ });
1538
1552
  // 创建地图要素图标样式
1539
1553
  style = new ol.style.Style({
1540
1554
  image: new ol.style.Icon({
1541
1555
  anchor: [-cg.markerContentX, -cg.markerContentY],
1542
1556
  anchorXUnits: 'pixels',
1543
1557
  anchorYUnits: 'pixels',
1544
- src: item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
1545
- // imgSize: [cg.width, cg.height],
1558
+ // src: item.url || `${configUrl.mapServerURL}/images/defaultMarker.png`,
1559
+ img: myImage,
1560
+ imgSize: [cg.width, cg.height],
1546
1561
  opacity: cg.opacity,
1547
1562
  scale: cg.scale || 1
1548
1563
  })
1549
1564
  });
1550
1565
  }
1551
1566
  if (!!item.canShowLabel && item.canShowLabel) {
1567
+ var _myImage = new Image(cg.width, cg.height);
1568
+ canvasDataURL(item.url || _default2.default.mapServerURL + '/images/defaultMarker.png', { width: cg.width, height: cg.height }, function (base64) {
1569
+ _myImage.src = base64;
1570
+ });
1552
1571
  // 创建地图要素图标样式
1553
1572
  style = new ol.style.Style({
1554
1573
  image: new ol.style.Icon({
1555
1574
  anchor: [-cg.markerContentX, -cg.markerContentY],
1556
1575
  anchorXUnits: 'pixels',
1557
1576
  anchorYUnits: 'pixels',
1558
- src: item.url || _default2.default.mapServerURL + '/images/defaultMarker.png',
1559
- // imgSize: [cg.width, cg.height],
1577
+ // src: item.url || `${configUrl.mapServerURL}/images/defaultMarker.png`,
1578
+ img: _myImage,
1579
+ imgSize: [cg.width, cg.height],
1560
1580
  opacity: cg.opacity,
1561
1581
  scale: cg.scale || 1
1562
1582
  }),
@@ -1592,6 +1612,10 @@ var OlMap = function (_React$Component) {
1592
1612
  source: source,
1593
1613
  id: item.id
1594
1614
  });
1615
+ t.pointLayers.push({
1616
+ id: item.id,
1617
+ layer: pointLayer
1618
+ });
1595
1619
  //添加点位图层
1596
1620
  t.state.gis.addLayer(pointLayer);
1597
1621
  if (!item.markerContent && cg.BAnimationType == 0) {
@@ -1613,7 +1637,10 @@ var OlMap = function (_React$Component) {
1613
1637
  });
1614
1638
  });
1615
1639
  if (type !== 'defined') {
1616
- t.state.pointIds = psids;
1640
+ // t.state.pointIds = psids;
1641
+ t.setState({
1642
+ pointIds: psids
1643
+ });
1617
1644
  }
1618
1645
  }
1619
1646
  //更新点
@@ -2263,10 +2290,13 @@ var OlMap = function (_React$Component) {
2263
2290
  }
2264
2291
  t.heatmap = null;
2265
2292
  t.movePoints = [];
2293
+
2294
+ t.state.pointIds = [];
2266
2295
  t.pointLayers.map(function (item) {
2267
- gis.removeLayer(item);
2296
+ gis.removeLayer(item.layer);
2268
2297
  t.pointLayers = [];
2269
2298
  });
2299
+
2270
2300
  t.clearAllPointCollection();
2271
2301
  t.closeDraw();
2272
2302
  if (t.clusterInfo.clusterHulls || t.clusterInfo.clusters || t.clusterInfo.clusterCircles) {
@@ -2430,6 +2460,7 @@ var OlMap = function (_React$Component) {
2430
2460
  ary = arg.split(',');
2431
2461
  }
2432
2462
  }
2463
+ t.state.pointIds = [];
2433
2464
  t.pointLayers.map(function (item) {
2434
2465
  t.state.gis.removeLayer(item.layer);
2435
2466
  t.pointLayers = [];
@@ -2558,6 +2589,33 @@ var OlMap = function (_React$Component) {
2558
2589
  }
2559
2590
  }
2560
2591
  }
2592
+ }, {
2593
+ key: 'clearCluster',
2594
+ value: function clearCluster() {
2595
+ var t = this;
2596
+ if (t.clusterInfo.clusterHulls) {
2597
+ t.state.gis.removeLayer(t.clusterInfo.clusterHulls);
2598
+ t.clusterInfo.clusterHulls = null;
2599
+ }
2600
+ if (t.clusterInfo.clusters) {
2601
+ t.state.gis.removeLayer(t.clusterInfo.clusters);
2602
+ t.clusterInfo.clusters = null;
2603
+ }
2604
+ if (t.clusterInfo.clusterCircles) {
2605
+ t.state.gis.removeLayer(t.clusterInfo.clusterCircles);
2606
+ t.clusterInfo.clusterCircles = null;
2607
+ }
2608
+ t.props.mapPoints.map(function (item) {
2609
+ if (t.GM.getGraphic(item.id)) {
2610
+ t.GM.removeGraphic(item.id);
2611
+ }
2612
+ });
2613
+ t.addPoint(t.props.mapPoints);
2614
+ // 临时处理下
2615
+ var view = t.state.gis.getView();
2616
+ var zoom = view.getZoom();
2617
+ view.setZoom(zoom - 0.5);
2618
+ }
2561
2619
  /*公共方法*/
2562
2620
  //判断extent1是否在extent2内部
2563
2621
 
@@ -3009,8 +3067,6 @@ var OlMap = function (_React$Component) {
3009
3067
  pointData[1]的数据在idsForGraphicId中不存在的,执行新增
3010
3068
  pointData[0]数据中多余的id,执行删除
3011
3069
  */
3012
- console.log(mapPoints, t.props.mapPoints);
3013
- console.log(!t.deepEqual(mapPoints, t.props.mapPoints));
3014
3070
  if (mapPoints instanceof Array && t.props.mapPoints instanceof Array && !t.deepEqual(mapPoints, t.props.mapPoints)) {
3015
3071
  var oldMapPoints = t.props.mapPoints;
3016
3072
  var newMapPoints = mapPoints;
@@ -3257,8 +3313,10 @@ var OlMap = function (_React$Component) {
3257
3313
  t.doEdit(editGraphicId);
3258
3314
  }
3259
3315
  // 获取热力图
3260
- if (heatMapData && !t.deepEqual(heatMapData, t.props.heatMapData)) {
3316
+ if (heatMapData && heatMapData.data && !t.deepEqual(heatMapData, t.props.heatMapData)) {
3261
3317
  t.heatMapOverlay(heatMapData);
3318
+ } else if (!t.deepEqual(heatMapData, t.props.heatMapData)) {
3319
+ t.clearHeatMap(heatMapData);
3262
3320
  }
3263
3321
  //清空地图
3264
3322
  if (typeof isClearAll == 'boolean' && isClearAll || isClearAll && isClearAll !== t.props.isClearAll) {
@@ -3284,6 +3342,8 @@ var OlMap = function (_React$Component) {
3284
3342
  //设置点聚合
3285
3343
  if (typeof setCluster == 'boolean' && setCluster || setCluster && setCluster !== t.props.setCluster) {
3286
3344
  t.cluster(mapCluster);
3345
+ } else if (setCluster !== t.props.setCluster) {
3346
+ t.clearCluster();
3287
3347
  }
3288
3348
  //图元编辑调用
3289
3349
  if (typeof isDoEdit == 'boolean' && isDoEdit || isDoEdit && isDoEdit !== t.props.isDoEdit) {
@@ -3423,6 +3483,13 @@ var OlMap = function (_React$Component) {
3423
3483
  }
3424
3484
  cg.gradient = gradient;
3425
3485
  }
3486
+ // if(d.data){
3487
+ // t.state.pointIds = [];
3488
+ // t.pointLayers.map(item => {
3489
+ // t.state.gis.removeLayer(item.layer);
3490
+ // t.pointLayers=[];
3491
+ // })
3492
+ // }
3426
3493
  var heatData = {
3427
3494
  type: 'FeatureCollection',
3428
3495
  features: (d.data || []).map(function (item) {
@@ -3454,6 +3521,13 @@ var OlMap = function (_React$Component) {
3454
3521
  });
3455
3522
  t.state.gis.addLayer(t.heatmap);
3456
3523
  }
3524
+ }, {
3525
+ key: 'clearHeatMap',
3526
+ value: function clearHeatMap() {
3527
+ var t = this;
3528
+ if (t.heatmap) t.state.gis.removeLayer(t.heatmap);
3529
+ t.heatmap = null;
3530
+ }
3457
3531
  //地图移动之前事件
3458
3532
 
3459
3533
  }, {
@@ -3574,4 +3648,40 @@ function getRgbColor(color, opacity) {
3574
3648
  }
3575
3649
  return 'rgba(' + arr.join(',') + ',' + opacity + ')';
3576
3650
  }
3651
+
3652
+ // 压缩图片的方法
3653
+ function canvasDataURL(path, obj, callback) {
3654
+ var img = new Image();
3655
+ img.src = path;
3656
+ img.setAttribute("crossOrigin", 'Anonymous');
3657
+ img.onload = function () {
3658
+ var that = this;
3659
+ // 默认按比例压缩
3660
+ var w = that.width,
3661
+ h = that.height,
3662
+ scale = w / h;
3663
+ w = obj.width || w;
3664
+ h = obj.height || w / scale;
3665
+ var quality = 0.7; // 默认图片质量为0.7
3666
+ //生成canvas
3667
+ var canvas = document.createElement('canvas');
3668
+ var ctx = canvas.getContext('2d');
3669
+ // 创建属性节点
3670
+ var anw = document.createAttribute("width");
3671
+ anw.nodeValue = w;
3672
+ var anh = document.createAttribute("height");
3673
+ anh.nodeValue = h;
3674
+ canvas.setAttributeNode(anw);
3675
+ canvas.setAttributeNode(anh);
3676
+ ctx.drawImage(that, 0, 0, w, h);
3677
+ // 图像质量
3678
+ if (obj.quality && obj.quality <= 1 && obj.quality > 0) {
3679
+ quality = obj.quality;
3680
+ }
3681
+ // quality值越小,所绘制出的图像越模糊
3682
+ var base64 = canvas.toDataURL('image/jpeg', quality);
3683
+ // 回调函数返回base64的值
3684
+ callback(base64);
3685
+ };
3686
+ }
3577
3687
  module.exports = exports['default'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtx/map",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "@vtx/map",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {