@vtx/map 1.1.15 → 1.1.16

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.showControl);
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
  }, {
@@ -1827,7 +1841,43 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1827
1841
  }
1828
1842
 
1829
1843
  if (!!item.canShowLabel && item.canShowLabel) {
1830
- // 创建地图要素图标样式
1844
+ var textStyle = _objectSpread({
1845
+ textAlign: 'center',
1846
+ //对齐方式
1847
+ textBaseline: 'middle',
1848
+ //文本基线
1849
+ font: 'normal 12px 微软雅黑',
1850
+ //字体样式
1851
+ text: cg.labelContent,
1852
+ //文本内容
1853
+ offsetX: cg.labelPixelX,
1854
+ // x轴偏置
1855
+ offsetY: cg.labelPixelY,
1856
+ // Y轴偏置
1857
+ fill: new ol.style.Fill({
1858
+ //填充样式
1859
+ color: '#1890ff'
1860
+ }),
1861
+ backgroundFill: new ol.style.Fill({
1862
+ // 填充背景
1863
+ color: 'rgba(255, 255, 255, 1)'
1864
+ }),
1865
+ padding: [2, 5, 2, 5]
1866
+ }, cg.labelStyle || {});
1867
+
1868
+ if (cg.labelStyle && cg.labelStyle.fill) {
1869
+ textStyle['fill'] = new ol.style.Fill({
1870
+ color: cg.labelStyle.fill
1871
+ });
1872
+ }
1873
+
1874
+ if (cg.labelStyle && cg.labelStyle.backgroundFill) {
1875
+ textStyle['backgroundFill'] = new ol.style.Fill({
1876
+ color: cg.labelStyle.backgroundFill
1877
+ });
1878
+ } // 创建地图要素图标样式
1879
+
1880
+
1831
1881
  style = new ol.style.Style({
1832
1882
  image: new ol.style.Icon({
1833
1883
  anchor: [-cg.markerContentX, -cg.markerContentY],
@@ -1840,29 +1890,7 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1840
1890
  scale: cg.scale || 1
1841
1891
  }),
1842
1892
  // 创建地图要素文字样式
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
- })
1893
+ text: new ol.style.Text(textStyle)
1866
1894
  });
1867
1895
  }
1868
1896
 
@@ -1980,7 +2008,7 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1980
2008
  });
1981
2009
 
1982
2010
  if (item.canShowLabel) {
1983
- text = new ol.style.Text({
2011
+ var textStyle = _objectSpread({
1984
2012
  textAlign: 'center',
1985
2013
  //对齐方式
1986
2014
  textBaseline: 'middle',
@@ -1995,14 +2023,28 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
1995
2023
  // Y轴偏置
1996
2024
  fill: new ol.style.Fill({
1997
2025
  //填充样式
1998
- color: 'rgba(0,0,0,0.8)'
2026
+ color: '#1890ff'
1999
2027
  }),
2000
2028
  backgroundFill: new ol.style.Fill({
2001
2029
  // 填充背景
2002
- color: 'rgba(255, 255, 255, 0.3)'
2030
+ color: 'rgba(255, 255, 255, 1)'
2003
2031
  }),
2004
2032
  padding: [2, 5, 2, 5]
2005
- });
2033
+ }, cg.labelStyle || {});
2034
+
2035
+ if (cg.labelStyle && cg.labelStyle.fill) {
2036
+ textStyle['fill'] = new ol.style.Fill({
2037
+ color: cg.labelStyle.fill
2038
+ });
2039
+ }
2040
+
2041
+ if (cg.labelStyle && cg.labelStyle.backgroundFill) {
2042
+ textStyle['backgroundFill'] = new ol.style.Fill({
2043
+ color: cg.labelStyle.backgroundFill
2044
+ });
2045
+ }
2046
+
2047
+ text = new ol.style.Text(textStyle);
2006
2048
  }
2007
2049
 
2008
2050
  if (text) {
@@ -2723,33 +2765,52 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
2723
2765
 
2724
2766
  }, {
2725
2767
  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
- };
2768
+ value: function showControl(props) {
2769
+ var t = this;
2737
2770
  var gis = t.state.gis;
2771
+ var config = props.showControl;
2738
2772
 
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' //设置度量单位
2773
+ if (t.scaleControl) {
2774
+ gis.removeControl(t.scaleControl);
2775
+ }
2746
2776
 
2777
+ t.scaleControl = new ol.control.ScaleLine({
2778
+ units: 'metric',
2779
+ //设置度量单位
2780
+ className: "ol-scale-line-".concat(config.location)
2747
2781
  });
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);
2782
+ gis.addControl(t.scaleControl);
2783
+ setTimeout(function () {
2784
+ if (config.location == 'tl') {
2785
+ $("div.ol-scale-line-".concat(config.location)).css({
2786
+ position: 'absolute',
2787
+ left: config.offset[0] + 65,
2788
+ top: config.offset[1],
2789
+ textAlign: 'center'
2790
+ });
2791
+ } else if (config.location == 'bl') {
2792
+ $("div.ol-scale-line-".concat(config.location)).css({
2793
+ position: 'absolute',
2794
+ left: config.offset[0] + 65,
2795
+ bottom: config.offset[1],
2796
+ textAlign: 'center'
2797
+ });
2798
+ } else if (config.location == 'tr') {
2799
+ $("div.ol-scale-line-".concat(config.location)).css({
2800
+ position: 'absolute',
2801
+ right: config.offset[0] + 65,
2802
+ top: config.offset[1],
2803
+ textAlign: 'center'
2804
+ });
2805
+ } else if (config.location == 'br') {
2806
+ $("div.ol-scale-line-".concat(config.location)).css({
2807
+ position: 'absolute',
2808
+ right: config.offset[0] + 65,
2809
+ bottom: config.offset[1],
2810
+ textAlign: 'center'
2811
+ });
2812
+ }
2813
+ }, 20);
2753
2814
  } //设置区域限制
2754
2815
 
2755
2816
  }, {
@@ -3020,7 +3081,10 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
3020
3081
  }, {
3021
3082
  key: "calculatePointsDistance",
3022
3083
  value: function calculatePointsDistance(fp, ep) {
3023
- return Math.round(new ol.sphere.getDistance(fp, ep));
3084
+ console.log(fp, ep);
3085
+ var distance = ol.sphere.getDistance(fp, ep);
3086
+ console.log(distance);
3087
+ return Math.round(distance);
3024
3088
  } //计算多个点的距离(常用于线计算)
3025
3089
 
3026
3090
  }, {
@@ -3035,10 +3099,13 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
3035
3099
 
3036
3100
  for (var i = 0; i < ps.length; i++) {
3037
3101
  if (i < ps.length - 1) {
3038
- totalDistance += t.calculatePointsDistance(ps[i], ps[i + 1]);
3102
+ var distance = t.calculatePointsDistance(ps[i], ps[i + 1]);
3103
+ console.log(distance);
3104
+ totalDistance += distance;
3039
3105
  }
3040
3106
  }
3041
3107
 
3108
+ console.log(totalDistance);
3042
3109
  return Math.round(totalDistance * 100) / 100;
3043
3110
  } //处理线和面的 经纬度数据
3044
3111
 
@@ -3772,6 +3839,16 @@ var OlMap = /*#__PURE__*/function (_React$Component) {
3772
3839
 
3773
3840
  if (typeof isClearAreaRestriction == 'boolean' && isClearAreaRestriction || isClearAreaRestriction && isClearAreaRestriction !== t.props.isClearAreaRestriction) {
3774
3841
  t.clearAreaRestriction();
3842
+ } // 设置地图层级
3843
+
3844
+
3845
+ if (typeof setZoomLevel == 'boolean' && setZoomLevel || setZoomLevel && setZoomLevel !== t.props.setZoomLevel) {
3846
+ t.setZoomLevel(mapZoomLevel);
3847
+ } // 比例尺控件位置改变
3848
+
3849
+
3850
+ if (nextProps.showControl && JSON.stringify(nextProps.showControl) != JSON.stringify(t.props.showControl)) {
3851
+ t.showControl(nextProps);
3775
3852
  }
3776
3853
  } // 地图事件
3777
3854
  //地图点击事件