@vtx/map 1.1.15 → 1.1.17

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.
@@ -167,3 +167,63 @@
167
167
  .ol-popup-closer:after {
168
168
  content: "✖";
169
169
  }
170
+ .ol-scale-line {
171
+ background-color: transparent;
172
+ width: 113px;
173
+ height: 30px;
174
+ border-left: 1px solid #000;
175
+ border-right: 1px solid #000;
176
+ border-bottom: 1px solid #000;
177
+ position: absolute !important;
178
+ bottom: 20px !important;
179
+ right: 20px !important;
180
+ text-align: center;
181
+ }
182
+ .ol-scale-line-tl {
183
+ position: absolute;
184
+ top: 20px;
185
+ left: 20px;
186
+ background-color: transparent;
187
+ width: 113px;
188
+ height: 30px;
189
+ border-left: 1px solid #000;
190
+ border-right: 1px solid #000;
191
+ border-bottom: 1px solid #000;
192
+ text-align: center;
193
+ }
194
+ .ol-scale-line-bl {
195
+ position: absolute;
196
+ bottom: 20px;
197
+ left: 20px;
198
+ background-color: transparent;
199
+ width: 113px;
200
+ height: 30px;
201
+ border-left: 1px solid #000;
202
+ border-right: 1px solid #000;
203
+ border-bottom: 1px solid #000;
204
+ text-align: center;
205
+ }
206
+ .ol-scale-line-tr {
207
+ position: absolute;
208
+ top: 20px;
209
+ right: 20px;
210
+ background-color: transparent;
211
+ width: 113px;
212
+ height: 30px;
213
+ border-left: 1px solid #000;
214
+ border-right: 1px solid #000;
215
+ border-bottom: 1px solid #000;
216
+ text-align: center;
217
+ }
218
+ .ol-scale-line-bl {
219
+ position: absolute;
220
+ bottom: 20px;
221
+ right: 20px;
222
+ background-color: transparent;
223
+ width: 113px;
224
+ height: 30px;
225
+ border-left: 1px solid #000;
226
+ border-right: 1px solid #000;
227
+ border-bottom: 1px solid #000;
228
+ text-align: center;
229
+ }
@@ -120,6 +120,7 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
120
120
  sketch: null,
121
121
  listener: null
122
122
  };
123
+ _this.scaleControl = null;
123
124
  _this.pointLayers = [];
124
125
  _this.mouseNowPosition = {
125
126
  x: 0,
@@ -295,7 +296,7 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
295
296
 
296
297
 
297
298
  if (t.props.showControl) {
298
- t.showControl();
299
+ t.showControl(t.props);
299
300
  } // 画热力图
300
301
 
301
302
 
@@ -555,6 +556,19 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
555
556
  duration: 2000
556
557
  });
557
558
  }
559
+ } //设置地图缩放层级
560
+
561
+ }, {
562
+ key: "setZoomLevel",
563
+ value: function setZoomLevel(zoom) {
564
+ var t = this;
565
+ var z = t.state.gis.getView().getZoom();
566
+
567
+ if (z == zoom) {
568
+ return false;
569
+ }
570
+
571
+ t.state.gis.getView().setZoom(zoom);
558
572
  } //获取当前中心点
559
573
 
560
574
  }, {
@@ -1791,7 +1805,13 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1791
1805
  var myImage = new Image(cg.width, cg.height);
1792
1806
 
1793
1807
  if (!!item.markerContent) {
1794
- var nodes = t.parseDom(item.markerContent)[0]; // 创建地图自定义覆盖物
1808
+ var nodes = t.parseDom(item.markerContent)[0]; // 自定义图层需要把事件加在dom上
1809
+
1810
+ nodes.addEventListener("click", function (e) {
1811
+ t.clickGraphic(item.id, _objectSpread(_objectSpread({}, e), {}, {
1812
+ pixel: [e.clientX, e.clientY]
1813
+ }));
1814
+ }); // 创建地图自定义覆盖物
1795
1815
 
1796
1816
  var pop = new ol.Overlay({
1797
1817
  id: item.id,
@@ -1827,7 +1847,43 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1827
1847
  }
1828
1848
 
1829
1849
  if (!!item.canShowLabel && item.canShowLabel) {
1830
- // 创建地图要素图标样式
1850
+ var textStyle = _objectSpread({
1851
+ textAlign: 'center',
1852
+ //对齐方式
1853
+ textBaseline: 'middle',
1854
+ //文本基线
1855
+ font: 'normal 12px 微软雅黑',
1856
+ //字体样式
1857
+ text: cg.labelContent,
1858
+ //文本内容
1859
+ offsetX: cg.labelPixelX,
1860
+ // x轴偏置
1861
+ offsetY: cg.labelPixelY,
1862
+ // Y轴偏置
1863
+ fill: new ol.style.Fill({
1864
+ //填充样式
1865
+ color: '#1890ff'
1866
+ }),
1867
+ backgroundFill: new ol.style.Fill({
1868
+ // 填充背景
1869
+ color: 'rgba(255, 255, 255, 1)'
1870
+ }),
1871
+ padding: [2, 5, 2, 5]
1872
+ }, cg.labelStyle || {});
1873
+
1874
+ if (cg.labelStyle && cg.labelStyle.fill) {
1875
+ textStyle['fill'] = new ol.style.Fill({
1876
+ color: cg.labelStyle.fill
1877
+ });
1878
+ }
1879
+
1880
+ if (cg.labelStyle && cg.labelStyle.backgroundFill) {
1881
+ textStyle['backgroundFill'] = new ol.style.Fill({
1882
+ color: cg.labelStyle.backgroundFill
1883
+ });
1884
+ } // 创建地图要素图标样式
1885
+
1886
+
1831
1887
  style = new ol.style.Style({
1832
1888
  image: new ol.style.Icon({
1833
1889
  anchor: [-cg.markerContentX, -cg.markerContentY],
@@ -1840,29 +1896,7 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1840
1896
  scale: cg.scale || 1
1841
1897
  }),
1842
1898
  // 创建地图要素文字样式
1843
- text: new ol.style.Text({
1844
- textAlign: 'center',
1845
- //对齐方式
1846
- textBaseline: 'middle',
1847
- //文本基线
1848
- font: 'normal 12px 微软雅黑',
1849
- //字体样式
1850
- text: cg.labelContent,
1851
- //文本内容
1852
- offsetX: cg.labelPixelX,
1853
- // x轴偏置
1854
- offsetY: cg.labelPixelY,
1855
- // Y轴偏置
1856
- fill: new ol.style.Fill({
1857
- //填充样式
1858
- color: 'rgba(0,0,0,0.8)'
1859
- }),
1860
- backgroundFill: new ol.style.Fill({
1861
- // 填充背景
1862
- color: 'rgba(255, 255, 255, 0.3)'
1863
- }),
1864
- padding: [2, 5, 2, 5]
1865
- })
1899
+ text: new ol.style.Text(textStyle)
1866
1900
  });
1867
1901
  }
1868
1902
 
@@ -1957,6 +1991,11 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1957
1991
  if (item.markerContent) {
1958
1992
  var overlay = t.state.gis.getOverlayById(item.id);
1959
1993
  var nodes = t.parseDom(item.markerContent)[0];
1994
+ nodes.addEventListener("click", function (e) {
1995
+ t.clickGraphic(item.id, _objectSpread(_objectSpread({}, e), {}, {
1996
+ pixel: [e.clientX, e.clientY]
1997
+ }));
1998
+ });
1960
1999
  overlay.setElement(nodes);
1961
2000
  overlay.setPosition([parseFloat(item.longitude), parseFloat(item.latitude)]);
1962
2001
  t.state.gis.changed();
@@ -1980,7 +2019,7 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1980
2019
  });
1981
2020
 
1982
2021
  if (item.canShowLabel) {
1983
- text = new ol.style.Text({
2022
+ var textStyle = _objectSpread({
1984
2023
  textAlign: 'center',
1985
2024
  //对齐方式
1986
2025
  textBaseline: 'middle',
@@ -1995,14 +2034,28 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1995
2034
  // Y轴偏置
1996
2035
  fill: new ol.style.Fill({
1997
2036
  //填充样式
1998
- color: 'rgba(0,0,0,0.8)'
2037
+ color: '#1890ff'
1999
2038
  }),
2000
2039
  backgroundFill: new ol.style.Fill({
2001
2040
  // 填充背景
2002
- color: 'rgba(255, 255, 255, 0.3)'
2041
+ color: 'rgba(255, 255, 255, 1)'
2003
2042
  }),
2004
2043
  padding: [2, 5, 2, 5]
2005
- });
2044
+ }, cg.labelStyle || {});
2045
+
2046
+ if (cg.labelStyle && cg.labelStyle.fill) {
2047
+ textStyle['fill'] = new ol.style.Fill({
2048
+ color: cg.labelStyle.fill
2049
+ });
2050
+ }
2051
+
2052
+ if (cg.labelStyle && cg.labelStyle.backgroundFill) {
2053
+ textStyle['backgroundFill'] = new ol.style.Fill({
2054
+ color: cg.labelStyle.backgroundFill
2055
+ });
2056
+ }
2057
+
2058
+ text = new ol.style.Text(textStyle);
2006
2059
  }
2007
2060
 
2008
2061
  if (text) {
@@ -2540,6 +2593,11 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
2540
2593
  //清除对应id的图元数据缓存
2541
2594
 
2542
2595
  t.GM.removeGraphic(id);
2596
+ t.GM.removeGraphicParam(id);
2597
+
2598
+ if (t.state.gis.getOverlayById(id)) {
2599
+ t.state.gis.removeOverlay(t.state.gis.getOverlayById(id));
2600
+ }
2543
2601
  } else {
2544
2602
  return false;
2545
2603
  }
@@ -2723,33 +2781,52 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
2723
2781
 
2724
2782
  }, {
2725
2783
  key: "showControl",
2726
- value: function showControl() {
2727
- var t = this,
2728
- type = '',
2729
- location = {
2730
- top: 20,
2731
- left: 20
2732
- },
2733
- ls = {
2734
- top: 20,
2735
- left: 60
2736
- };
2784
+ value: function showControl(props) {
2785
+ var t = this;
2737
2786
  var gis = t.state.gis;
2787
+ var config = props.showControl;
2738
2788
 
2739
- var _gis$getSize3 = gis.getSize(),
2740
- _gis$getSize4 = _slicedToArray(_gis$getSize3, 2),
2741
- w = _gis$getSize4[0],
2742
- h = _gis$getSize4[1];
2743
-
2744
- var scaleControl = new ol.control.ScaleLine({
2745
- units: 'metric' //设置度量单位
2789
+ if (t.scaleControl) {
2790
+ gis.removeControl(t.scaleControl);
2791
+ }
2746
2792
 
2793
+ t.scaleControl = new ol.control.ScaleLine({
2794
+ units: 'metric',
2795
+ //设置度量单位
2796
+ className: "ol-scale-line-".concat(config.location)
2747
2797
  });
2748
- var zoomControl = new ol.control.Zoom({});
2749
- var ZoomSliderControl = new ol.control.ZoomSlider({});
2750
- gis.addControl(scaleControl);
2751
- gis.addControl(zoomControl);
2752
- gis.addControl(ZoomSliderControl);
2798
+ gis.addControl(t.scaleControl);
2799
+ setTimeout(function () {
2800
+ if (config.location == 'tl') {
2801
+ $("div.ol-scale-line-".concat(config.location)).css({
2802
+ position: 'absolute',
2803
+ left: config.offset ? config.offset[0] : 0 + 65,
2804
+ top: config.offset ? config.offset[1] : 0,
2805
+ textAlign: 'center'
2806
+ });
2807
+ } else if (config.location == 'bl') {
2808
+ $("div.ol-scale-line-".concat(config.location)).css({
2809
+ position: 'absolute',
2810
+ left: config.offset ? config.offset[0] : 0 + 65,
2811
+ bottom: config.offset ? config.offset[1] : 0,
2812
+ textAlign: 'center'
2813
+ });
2814
+ } else if (config.location == 'tr') {
2815
+ $("div.ol-scale-line-".concat(config.location)).css({
2816
+ position: 'absolute',
2817
+ right: config.offset ? config.offset[0] : 0 + 65,
2818
+ top: config.offset ? config.offset[1] : 0,
2819
+ textAlign: 'center'
2820
+ });
2821
+ } else if (config.location == 'br') {
2822
+ $("div.ol-scale-line-".concat(config.location)).css({
2823
+ position: 'absolute',
2824
+ right: config.offset ? config.offset[0] : 0 + 65,
2825
+ bottom: config.offset ? config.offset[1] : 0,
2826
+ textAlign: 'center'
2827
+ });
2828
+ }
2829
+ }, 20);
2753
2830
  } //设置区域限制
2754
2831
 
2755
2832
  }, {
@@ -3020,7 +3097,10 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
3020
3097
  }, {
3021
3098
  key: "calculatePointsDistance",
3022
3099
  value: function calculatePointsDistance(fp, ep) {
3023
- return Math.round(new ol.sphere.getDistance(fp, ep));
3100
+ console.log(fp, ep);
3101
+ var distance = ol.sphere.getDistance(fp, ep);
3102
+ console.log(distance);
3103
+ return Math.round(distance);
3024
3104
  } //计算多个点的距离(常用于线计算)
3025
3105
 
3026
3106
  }, {
@@ -3035,10 +3115,13 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
3035
3115
 
3036
3116
  for (var i = 0; i < ps.length; i++) {
3037
3117
  if (i < ps.length - 1) {
3038
- totalDistance += t.calculatePointsDistance(ps[i], ps[i + 1]);
3118
+ var distance = t.calculatePointsDistance(ps[i], ps[i + 1]);
3119
+ console.log(distance);
3120
+ totalDistance += distance;
3039
3121
  }
3040
3122
  }
3041
3123
 
3124
+ console.log(totalDistance);
3042
3125
  return Math.round(totalDistance * 100) / 100;
3043
3126
  } //处理线和面的 经纬度数据
3044
3127
 
@@ -3772,6 +3855,16 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
3772
3855
 
3773
3856
  if (typeof isClearAreaRestriction == 'boolean' && isClearAreaRestriction || isClearAreaRestriction && isClearAreaRestriction !== t.props.isClearAreaRestriction) {
3774
3857
  t.clearAreaRestriction();
3858
+ } // 设置地图层级
3859
+
3860
+
3861
+ if (typeof setZoomLevel == 'boolean' && setZoomLevel || setZoomLevel && setZoomLevel !== t.props.setZoomLevel) {
3862
+ t.setZoomLevel(mapZoomLevel);
3863
+ } // 比例尺控件位置改变
3864
+
3865
+
3866
+ if (nextProps.showControl && JSON.stringify(nextProps.showControl) != JSON.stringify(t.props.showControl)) {
3867
+ t.showControl(nextProps);
3775
3868
  }
3776
3869
  } // 地图事件
3777
3870
  //地图点击事件