@vtx/map 1.2.17 → 1.2.19
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.
- package/lib/VtxMap/OlMap/Map.js +272 -3
- package/lib/VtxMap/OlMap/Map.js.map +1 -1
- package/lib/VtxSearchMap/VtxSearchMap.css +11 -0
- package/lib/VtxSearchMap/VtxSearchMap.js +75 -7
- package/lib/VtxSearchMap/VtxSearchMap.js.map +1 -1
- package/lib/VtxSearchMap/VtxSearchMap.less +9 -0
- package/lib/utils/util.js +11 -1
- package/lib/utils/util.js.map +1 -1
- package/package.json +1 -1
package/lib/VtxMap/OlMap/Map.js
CHANGED
|
@@ -69,6 +69,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
69
69
|
|
|
70
70
|
var Set = _immutable["default"].Set;
|
|
71
71
|
|
|
72
|
+
var defaultMarker = require("../images/defaultMarker.png");
|
|
73
|
+
|
|
72
74
|
var OlMap = /*#__PURE__*/function (_React$Component) {
|
|
73
75
|
_inherits(OlMap, _React$Component);
|
|
74
76
|
|
|
@@ -307,6 +309,8 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
|
|
|
307
309
|
}
|
|
308
310
|
};
|
|
309
311
|
_this.frameSelectProps = {};
|
|
312
|
+
_this.pointFeatureLayer = null;
|
|
313
|
+
_this.imgCache = new ImgCache();
|
|
310
314
|
|
|
311
315
|
_this.loadMapJs();
|
|
312
316
|
|
|
@@ -372,10 +376,16 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
|
|
|
372
376
|
mapCluster = _t$props.mapCluster,
|
|
373
377
|
mapPointCollection = _t$props.mapPointCollection,
|
|
374
378
|
areaRestriction = _t$props.areaRestriction,
|
|
375
|
-
heatMapData = _t$props.heatMapData
|
|
379
|
+
heatMapData = _t$props.heatMapData,
|
|
380
|
+
pointsFeature = _t$props.pointsFeature; // 初始化中心点
|
|
376
381
|
|
|
377
382
|
t.setCenter(); // 添加点
|
|
378
383
|
|
|
384
|
+
if (pointsFeature instanceof Array) {
|
|
385
|
+
t.addPointLayer(pointsFeature);
|
|
386
|
+
} // 添加点
|
|
387
|
+
|
|
388
|
+
|
|
379
389
|
if (mapPoints instanceof Array) {
|
|
380
390
|
t.addPoint(mapPoints);
|
|
381
391
|
} //添加线
|
|
@@ -2580,6 +2590,224 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
|
|
|
2580
2590
|
return dealPoint(mapPoints[index]);
|
|
2581
2591
|
});
|
|
2582
2592
|
}
|
|
2593
|
+
} // 点位样式
|
|
2594
|
+
|
|
2595
|
+
}, {
|
|
2596
|
+
key: "getPointStyle",
|
|
2597
|
+
value: function getPointStyle(item) {
|
|
2598
|
+
var t = this;
|
|
2599
|
+
var cg = {
|
|
2600
|
+
width: 30,
|
|
2601
|
+
height: 30,
|
|
2602
|
+
labelContent: '',
|
|
2603
|
+
labelPixelX: 0,
|
|
2604
|
+
labelPixelY: 34,
|
|
2605
|
+
markerContentX: -13,
|
|
2606
|
+
markerContentY: -42,
|
|
2607
|
+
zIndex: 100,
|
|
2608
|
+
deg: 0,
|
|
2609
|
+
scale: 1
|
|
2610
|
+
}; //初始化默认数据
|
|
2611
|
+
|
|
2612
|
+
if (item.config) {
|
|
2613
|
+
cg = _objectSpread(_objectSpread({}, cg), item.config);
|
|
2614
|
+
} // 覆盖物样式参数
|
|
2615
|
+
|
|
2616
|
+
|
|
2617
|
+
var style, icon, txt;
|
|
2618
|
+
var myImage = new Image(cg.width, cg.height);
|
|
2619
|
+
|
|
2620
|
+
if (!!item.markerContent) {
|
|
2621
|
+
var nodes = t.parseDom(item.markerContent)[0]; // 自定义图层需要把事件加在dom上
|
|
2622
|
+
|
|
2623
|
+
nodes.addEventListener("click", function (e) {
|
|
2624
|
+
t.clickGraphic(item.id, _objectSpread(_objectSpread({}, e), {}, {
|
|
2625
|
+
pixel: [e.clientX, e.clientY],
|
|
2626
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
2627
|
+
other: item
|
|
2628
|
+
})
|
|
2629
|
+
}));
|
|
2630
|
+
}); // 创建地图自定义覆盖物
|
|
2631
|
+
|
|
2632
|
+
var pop = new ol.Overlay({
|
|
2633
|
+
id: item.id,
|
|
2634
|
+
position: [parseFloat(item.longitude), parseFloat(item.latitude)],
|
|
2635
|
+
positioning: 'center-center',
|
|
2636
|
+
element: nodes,
|
|
2637
|
+
autoPanMargin: 20,
|
|
2638
|
+
autoPan: true,
|
|
2639
|
+
offset: [0, -20],
|
|
2640
|
+
insertFirst: true
|
|
2641
|
+
});
|
|
2642
|
+
t.state.gis.addOverlay(pop);
|
|
2643
|
+
} else {
|
|
2644
|
+
var url = item.url || defaultMarker;
|
|
2645
|
+
var temp = t.imgCache.get(url);
|
|
2646
|
+
|
|
2647
|
+
if (temp) {
|
|
2648
|
+
console.log(item.id);
|
|
2649
|
+
myImage.src = temp;
|
|
2650
|
+
} else {
|
|
2651
|
+
// myImage.src = url;
|
|
2652
|
+
// t.imgCache.set(url, url);
|
|
2653
|
+
canvasDataURL(url, {
|
|
2654
|
+
width: cg.width,
|
|
2655
|
+
height: cg.height
|
|
2656
|
+
}, function (base64) {
|
|
2657
|
+
myImage.src = base64;
|
|
2658
|
+
t.imgCache.set(url, base64);
|
|
2659
|
+
});
|
|
2660
|
+
} // 创建地图要素图标样式
|
|
2661
|
+
|
|
2662
|
+
|
|
2663
|
+
style = new ol.style.Style({
|
|
2664
|
+
image: new ol.style.Icon({
|
|
2665
|
+
anchor: [-cg.markerContentX, -cg.markerContentY],
|
|
2666
|
+
anchorXUnits: 'pixels',
|
|
2667
|
+
anchorYUnits: 'pixels',
|
|
2668
|
+
img: myImage,
|
|
2669
|
+
imgSize: [cg.width, cg.height],
|
|
2670
|
+
opacity: cg.opacity,
|
|
2671
|
+
scale: cg.scale || 1
|
|
2672
|
+
})
|
|
2673
|
+
});
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
if (!!item.canShowLabel && item.canShowLabel) {
|
|
2677
|
+
var textStyle = _objectSpread({
|
|
2678
|
+
textAlign: 'center',
|
|
2679
|
+
//对齐方式
|
|
2680
|
+
textBaseline: 'middle',
|
|
2681
|
+
//文本基线
|
|
2682
|
+
font: 'normal 12px 微软雅黑',
|
|
2683
|
+
//字体样式
|
|
2684
|
+
text: cg.labelContent,
|
|
2685
|
+
//文本内容
|
|
2686
|
+
offsetX: cg.labelPixelX,
|
|
2687
|
+
// x轴偏置
|
|
2688
|
+
offsetY: cg.labelPixelY,
|
|
2689
|
+
// Y轴偏置
|
|
2690
|
+
fill: new ol.style.Fill({
|
|
2691
|
+
//填充样式
|
|
2692
|
+
color: '#1890ff'
|
|
2693
|
+
}),
|
|
2694
|
+
backgroundFill: new ol.style.Fill({
|
|
2695
|
+
// 填充背景
|
|
2696
|
+
color: 'rgba(255, 255, 255, 1)'
|
|
2697
|
+
}),
|
|
2698
|
+
padding: [2, 5, 2, 5]
|
|
2699
|
+
}, cg.labelStyle || {});
|
|
2700
|
+
|
|
2701
|
+
if (cg.labelStyle && cg.labelStyle.fill) {
|
|
2702
|
+
textStyle['fill'] = new ol.style.Fill({
|
|
2703
|
+
color: cg.labelStyle.fill
|
|
2704
|
+
});
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
if (cg.labelStyle && cg.labelStyle.backgroundFill) {
|
|
2708
|
+
textStyle['backgroundFill'] = new ol.style.Fill({
|
|
2709
|
+
color: cg.labelStyle.backgroundFill
|
|
2710
|
+
});
|
|
2711
|
+
} // 创建地图要素图标样式
|
|
2712
|
+
|
|
2713
|
+
|
|
2714
|
+
style = new ol.style.Style({
|
|
2715
|
+
image: new ol.style.Icon({
|
|
2716
|
+
anchor: [-cg.markerContentX, -cg.markerContentY],
|
|
2717
|
+
anchorXUnits: 'pixels',
|
|
2718
|
+
anchorYUnits: 'pixels',
|
|
2719
|
+
// src: item.url || require("../images/defaultMarker.png"),
|
|
2720
|
+
img: myImage,
|
|
2721
|
+
imgSize: [cg.width, cg.height],
|
|
2722
|
+
opacity: cg.opacity,
|
|
2723
|
+
scale: cg.scale || 1
|
|
2724
|
+
}),
|
|
2725
|
+
// 创建地图要素文字样式
|
|
2726
|
+
text: new ol.style.Text(textStyle)
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
return style;
|
|
2731
|
+
} // 添加点位图层
|
|
2732
|
+
|
|
2733
|
+
}, {
|
|
2734
|
+
key: "addPointLayer",
|
|
2735
|
+
value: function addPointLayer(points) {
|
|
2736
|
+
var t = this;
|
|
2737
|
+
var features = [];
|
|
2738
|
+
points === null || points === void 0 ? void 0 : points.map(function (item) {
|
|
2739
|
+
var feature = new ol.Feature({
|
|
2740
|
+
geometry: new ol.geom.Point([parseFloat(item.longitude), parseFloat(item.latitude)]),
|
|
2741
|
+
name: item.name,
|
|
2742
|
+
id: item.id,
|
|
2743
|
+
params: _objectSpread({}, item)
|
|
2744
|
+
});
|
|
2745
|
+
feature.setId(item.id);
|
|
2746
|
+
var style = t.getPointStyle(item);
|
|
2747
|
+
feature.setStyle(style);
|
|
2748
|
+
features.push(feature);
|
|
2749
|
+
t.GM.setGraphic(item.id, feature).setGraphicParam(item.id, {
|
|
2750
|
+
attributes: _objectSpread(_objectSpread({}, item), {}, {
|
|
2751
|
+
other: item
|
|
2752
|
+
}),
|
|
2753
|
+
geometryType: 'point',
|
|
2754
|
+
geometry: {
|
|
2755
|
+
type: 'point',
|
|
2756
|
+
x: parseFloat(item.longitude),
|
|
2757
|
+
y: parseFloat(item.latitude)
|
|
2758
|
+
}
|
|
2759
|
+
});
|
|
2760
|
+
});
|
|
2761
|
+
|
|
2762
|
+
if (t.pointFeatureLayer) {
|
|
2763
|
+
var source = t.pointFeatureLayer.getSource();
|
|
2764
|
+
console.log(source);
|
|
2765
|
+
var oldFeatures = source.getFeatures();
|
|
2766
|
+
var newFeatures = [],
|
|
2767
|
+
updateFeatureIds = [];
|
|
2768
|
+
oldFeatures.map(function (feat) {
|
|
2769
|
+
var obj = features.find(function (p) {
|
|
2770
|
+
return p.getId() == feat.getId();
|
|
2771
|
+
});
|
|
2772
|
+
|
|
2773
|
+
if (obj) {
|
|
2774
|
+
if (JSON.stringify(obj.getStyle()) !== JSON.stringify(feat.getStyle())) {
|
|
2775
|
+
feat.setStyle(obj.getStyle());
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
if (JSON.stringify(obj.getGeometry()) !== JSON.stringify(feat.getGeometry())) {
|
|
2779
|
+
feat.setGeometry(obj.getGeometry());
|
|
2780
|
+
}
|
|
2781
|
+
|
|
2782
|
+
updateFeatureIds.push(feat.getId());
|
|
2783
|
+
} else {
|
|
2784
|
+
source.removeFeature(feat);
|
|
2785
|
+
}
|
|
2786
|
+
});
|
|
2787
|
+
newFeatures = features.filter(function (p) {
|
|
2788
|
+
return !updateFeatureIds.includes(p.getId());
|
|
2789
|
+
});
|
|
2790
|
+
|
|
2791
|
+
if (newFeatures.length > 0) {
|
|
2792
|
+
t.pointFeatureLayer.getSource().addFeatures(newFeatures);
|
|
2793
|
+
} // t.pointFeatureLayer.getSource().clear();
|
|
2794
|
+
// t.pointFeatureLayer.getSource().addFeatures(features);
|
|
2795
|
+
|
|
2796
|
+
} else {
|
|
2797
|
+
var _source = new ol.source.Vector({
|
|
2798
|
+
features: features
|
|
2799
|
+
});
|
|
2800
|
+
|
|
2801
|
+
var pointLayer = new ol.layer.Vector({
|
|
2802
|
+
name: 'point_layer',
|
|
2803
|
+
source: _source,
|
|
2804
|
+
id: 'point_layer'
|
|
2805
|
+
});
|
|
2806
|
+
t.state.gis.addLayer(pointLayer);
|
|
2807
|
+
t.pointFeatureLayer = pointLayer;
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
t.refresh();
|
|
2583
2811
|
} // 更新图层
|
|
2584
2812
|
|
|
2585
2813
|
}, {
|
|
@@ -4073,7 +4301,9 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
|
|
|
4073
4301
|
areaRestriction = nextProps.areaRestriction,
|
|
4074
4302
|
isClearAreaRestriction = nextProps.isClearAreaRestriction,
|
|
4075
4303
|
isClearAll = nextProps.isClearAll,
|
|
4076
|
-
olProps = nextProps.olProps
|
|
4304
|
+
olProps = nextProps.olProps,
|
|
4305
|
+
_nextProps$pointsFeat = nextProps.pointsFeature,
|
|
4306
|
+
pointsFeature = _nextProps$pointsFeat === void 0 ? [] : _nextProps$pointsFeat; // 等待地图加载
|
|
4077
4307
|
|
|
4078
4308
|
if (!t.mapCreated) return;
|
|
4079
4309
|
/*点数据处理
|
|
@@ -4082,6 +4312,10 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
|
|
|
4082
4312
|
pointData[0]数据中多余的id,执行删除
|
|
4083
4313
|
*/
|
|
4084
4314
|
|
|
4315
|
+
if (pointsFeature instanceof Array && !t.deepEqual(pointsFeature, t.props.pointsFeature)) {
|
|
4316
|
+
t.addPointLayer(pointsFeature);
|
|
4317
|
+
}
|
|
4318
|
+
|
|
4085
4319
|
if (mapPoints instanceof Array && t.props.mapPoints instanceof Array && !t.deepEqual(mapPoints, t.props.mapPoints)) {
|
|
4086
4320
|
var oldMapPoints = t.props.mapPoints;
|
|
4087
4321
|
var newMapPoints = mapPoints; //过滤编辑的图元
|
|
@@ -4675,7 +4909,7 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
|
|
|
4675
4909
|
//图元类型
|
|
4676
4910
|
attributes: param ? _objectSpread(_objectSpread({}, param.attributes.other), {
|
|
4677
4911
|
config: param.attributes.config
|
|
4678
|
-
}) : null,
|
|
4912
|
+
}) : e.attributes || null,
|
|
4679
4913
|
//添加时图元信息
|
|
4680
4914
|
top: clientY,
|
|
4681
4915
|
//当前点所在的位置(屏幕)
|
|
@@ -4865,5 +5099,40 @@ function canvasDataURL(path, obj, callback) {
|
|
|
4865
5099
|
};
|
|
4866
5100
|
}
|
|
4867
5101
|
|
|
5102
|
+
var ImgCache = /*#__PURE__*/function () {
|
|
5103
|
+
function ImgCache(props) {
|
|
5104
|
+
_classCallCheck(this, ImgCache);
|
|
5105
|
+
|
|
5106
|
+
this.imgs = {};
|
|
5107
|
+
}
|
|
5108
|
+
|
|
5109
|
+
_createClass(ImgCache, [{
|
|
5110
|
+
key: "set",
|
|
5111
|
+
value: function set(key, value) {
|
|
5112
|
+
this.imgs[key] = value;
|
|
5113
|
+
}
|
|
5114
|
+
}, {
|
|
5115
|
+
key: "get",
|
|
5116
|
+
value: function get(key) {
|
|
5117
|
+
return this.imgs[key];
|
|
5118
|
+
}
|
|
5119
|
+
}, {
|
|
5120
|
+
key: "remove",
|
|
5121
|
+
value: function remove(key) {
|
|
5122
|
+
var obj = _objectSpread({}, this.imgs);
|
|
5123
|
+
|
|
5124
|
+
delete obj[key];
|
|
5125
|
+
this.imgs = obj;
|
|
5126
|
+
}
|
|
5127
|
+
}, {
|
|
5128
|
+
key: "clear",
|
|
5129
|
+
value: function clear() {
|
|
5130
|
+
this.imgs = {};
|
|
5131
|
+
}
|
|
5132
|
+
}]);
|
|
5133
|
+
|
|
5134
|
+
return ImgCache;
|
|
5135
|
+
}();
|
|
5136
|
+
|
|
4868
5137
|
module.exports = exports["default"];
|
|
4869
5138
|
//# sourceMappingURL=Map.js.map
|