@vtx/map 1.0.4 → 1.0.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.
package/README.md CHANGED
@@ -1,44 +1,44 @@
1
- # map
2
-
3
- > 地图控件
4
-
5
- ## 安装
6
-
7
- ```bash
8
- # Install
9
- $ npm install @vtx/map
10
- #或者
11
- $ yarn add @vtx/map
12
- ```
13
-
14
- ## 文档
15
-
16
- - [VtxMap](/docs/VtxMap.md)
17
- - [MapPlayer](/docs/MapPlayer.md)
18
- - [VtxSearchMap](/docs/VtxSearchMap.md)
19
- - [VtxOptMap](/docs/VtxOptMap.md)
20
-
21
- ### 全量导入引用方式(==不推荐==):
22
-
23
- ```js
24
- # 地图组件(地图组件的ref函数现在改为getMapInstance)
25
- $ import { VtxMap, VtxOptMap, VtxZoomMap } from '@vtx/map';
26
-
27
- # 地图弹出框组件
28
- $ import { VtxSearchMap } from '@vtx/map';
29
- ```
30
-
31
- ### 使用 babel-plugin-import 动态加载引用方式(==推荐==):
32
-
33
- ```js
34
- # 地图组件(地图组件的ref函数现在改为getMapInstance)
35
- $ import { VtxMap } from '@vtx/map';
36
- $ const { VtxOptMap, VtxZoomMap, MapPlayer } = VtxMap;
37
-
38
- # 地图弹出框组件
39
- $ import { VtxSearchMap } from '@vtx/map';
40
- ```
41
-
42
- ## License
43
-
44
- [MIT](https://tldrlegal.com/license/mit-license)
1
+ # map
2
+
3
+ > 地图控件
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ # Install
9
+ $ npm install @vtx/map
10
+ #或者
11
+ $ yarn add @vtx/map
12
+ ```
13
+
14
+ ## 文档
15
+
16
+ - [VtxMap](/docs/VtxMap.md)
17
+ - [MapPlayer](/docs/MapPlayer.md)
18
+ - [VtxSearchMap](/docs/VtxSearchMap.md)
19
+ - [VtxOptMap](/docs/VtxOptMap.md)
20
+
21
+ ### 全量导入引用方式(==不推荐==):
22
+
23
+ ```js
24
+ # 地图组件(地图组件的ref函数现在改为getMapInstance)
25
+ $ import { VtxMap, VtxOptMap, VtxZoomMap } from '@vtx/map';
26
+
27
+ # 地图弹出框组件
28
+ $ import { VtxSearchMap } from '@vtx/map';
29
+ ```
30
+
31
+ ### 使用 babel-plugin-import 动态加载引用方式(==推荐==):
32
+
33
+ ```js
34
+ # 地图组件(地图组件的ref函数现在改为getMapInstance)
35
+ $ import { VtxMap } from '@vtx/map';
36
+ $ const { VtxOptMap, VtxZoomMap, MapPlayer } = VtxMap;
37
+
38
+ # 地图弹出框组件
39
+ $ import { VtxSearchMap } from '@vtx/map';
40
+ ```
41
+
42
+ ## License
43
+
44
+ [MIT](https://tldrlegal.com/license/mit-license)
@@ -744,44 +744,88 @@ var VortexAMap = function (_React$Component) {
744
744
 
745
745
  }, {
746
746
  key: 'showControl',
747
- value: function showControl() {
747
+ value: function showControl(props) {
748
748
  var t = this,
749
749
  location = 'RT',
750
750
  offset = null;
751
-
752
- if (t.props.showControl.location) {
753
- location = t.AnchorConstant[t.props.showControl.location];
751
+ var config = props || t.props;
752
+ if (t.scaleControl) {
753
+ t.state.gis.removeControl(t.scaleControl);
754
+ }
755
+ if (t.navigationControl) {
756
+ t.state.gis.removeControl(t.navigationControl);
754
757
  }
755
- if (t.props.showControl.offset && t.props.showControl.offset.length > 0) {
756
- offset = new AMap.Pixel(t.props.showControl.offset[0], t.props.showControl.offset[1]);
757
- scaleOffset = new AMap.Pixel(t.props.showControl.offset[0] + 70, t.props.showControl.offset[1]);
758
+ if (config.showControl.location) {
759
+ location = t.AnchorConstant[config.showControl.location];
760
+ }
761
+ if (config.showControl.offset && config.showControl.offset.length > 0) {
762
+ offset = new AMap.Pixel(config.showControl.offset[0], config.showControl.offset[1]);
763
+ scaleOffset = new AMap.Pixel(config.showControl.offset[0] + 70, config.showControl.offset[1]);
758
764
  }
759
765
  // 添加比例尺
760
766
  var control = new AMap.Scale({ position: location, offset: scaleOffset });
761
767
  t.state.gis.addControl(control);
762
-
768
+ t.scaleControl = control;
763
769
  // 包含平移和缩放按钮
764
770
  var navigation = new AMap.ToolBar({ position: location, offset: offset });
765
771
  t.state.gis.addControl(navigation);
772
+ t.navigationControl = navigation;
766
773
  }
767
774
  //展示地图切换控件
768
775
 
769
776
  }, {
770
777
  key: 'showMapTypeControl',
771
- value: function showMapTypeControl() {
778
+ value: function showMapTypeControl(props) {
772
779
  var t = this,
773
780
  location = 'RT',
774
781
  offset = null;
775
- // TODO,MapType没有这些属性,所以下面定位和偏移不生效
776
- if (t.props.satelliteSwitch.location) {
777
- location = t.AnchorConstant[t.props.showControl.location];
782
+ var config = props || t.props;
783
+ if (t.mapTypeControl) {
784
+ t.state.gis.removeControl(t.mapTypeControl);
778
785
  }
779
- if (t.props.satelliteSwitch.offset && t.props.satelliteSwitch.offset.length > 0) {
780
- offset = new AMap.Pixel(t.props.satelliteSwitch.offset[0], t.props.satelliteSwitch.offset[1]);
786
+ if (config.satelliteSwitch.location) {
787
+ location = t.AnchorConstant[config.satelliteSwitch.location];
781
788
  }
789
+
782
790
  // 地图切换控件
783
791
  var control = new AMap.MapType({ position: location, offset: offset });
784
792
  t.state.gis.addControl(control);
793
+ t.mapTypeControl = control;
794
+
795
+ // TODO,MapType没有这些属性,所以下面定位和偏移不生效,手动修改
796
+ function reloaction() {
797
+ if (location == 'RT') {
798
+ $('div.amap-maptypecontrol').css({ right: 0, top: 0, left: 'inherit', bottom: 'inherit' });
799
+ } else if (location == 'LT') {
800
+ $('div.amap-maptypecontrol').css({ left: 0 + 64, top: 0, right: 'inherit', bottom: 'inherit' });
801
+ } else if (location == 'LB') {
802
+ $('div.amap-maptypecontrol').css({ left: 0 + 64, bottom: 0 + 84, right: 'inherit', top: 'inherit' });
803
+ } else if (location == 'RB') {
804
+ $('div.amap-maptypecontrol').css({ right: 0, bottom: 0 + 84, left: 'inherit', top: 'inherit' });
805
+ }
806
+ if (config.satelliteSwitch.offset && config.satelliteSwitch.offset.length > 0) {
807
+ if (location == 'RT') {
808
+ $('div.amap-maptypecontrol').css({ right: config.satelliteSwitch.offset[0], top: config.satelliteSwitch.offset[1], left: 'inherit', bottom: 'inherit' });
809
+ } else if (location == 'LT') {
810
+ $('div.amap-maptypecontrol').css({ left: config.satelliteSwitch.offset[0] + 64, top: config.satelliteSwitch.offset[1], right: 'inherit', bottom: 'inherit' });
811
+ } else if (location == 'LB') {
812
+ $('div.amap-maptypecontrol').css({ left: config.satelliteSwitch.offset[0] + 64, bottom: config.satelliteSwitch.offset[1] + 84, right: 'inherit', top: 'inherit' });
813
+ } else if (location == 'RB') {
814
+ $('div.amap-maptypecontrol').css({ right: config.satelliteSwitch.offset[0], bottom: config.satelliteSwitch.offset[1] + 84, left: 'inherit', top: 'inherit' });
815
+ }
816
+ }
817
+ }
818
+ if ($('div.amap-maptypecontrol').length > 0) {
819
+ reloaction();
820
+ } else {
821
+ var timer = setInterval(function () {
822
+ console.log(123);
823
+ if ($('div.amap-maptypecontrol').length > 0) {
824
+ clearInterval(timer);
825
+ reloaction();
826
+ }
827
+ }, 500);
828
+ }
785
829
  }
786
830
  //获取图元数据
787
831
 
@@ -2958,6 +3002,15 @@ var VortexAMap = function (_React$Component) {
2958
3002
  if (typeof isClearAreaRestriction == 'boolean' && isClearAreaRestriction || isClearAreaRestriction && isClearAreaRestriction !== t.props.isClearAreaRestriction) {
2959
3003
  t.clearAreaRestriction();
2960
3004
  }
3005
+
3006
+ // 比例尺控件位置改变
3007
+ if (nextProps.showControl && JSON.stringify(nextProps.showControl) != JSON.stringify(t.props.showControl)) {
3008
+ t.showControl(nextProps);
3009
+ }
3010
+ // 地图类型控件位置改变
3011
+ if (nextProps.satelliteSwitch && JSON.stringify(nextProps.satelliteSwitch) != JSON.stringify(t.props.satelliteSwitch)) {
3012
+ t.showMapTypeControl(nextProps);
3013
+ }
2961
3014
  }
2962
3015
  }, {
2963
3016
  key: 'componentWillUnmount',
@@ -1633,16 +1633,28 @@ var BaiduMap = function (_React$Component) {
1633
1633
  break;
1634
1634
  }
1635
1635
 
1636
+ /**
1637
+ * 用法
1638
+ * map.setVisiblePoints('lng,lat;lng,lat')
1639
+ */
1636
1640
  if (typeof arg === 'string') {
1637
1641
  ary = arg.split(',');
1638
1642
  obj = t.getFitView(ary);
1639
1643
  } else if (arg instanceof Array) {
1640
- if (ary[0] instanceof Array) {
1644
+ /**
1645
+ * 用法
1646
+ * map.setVisiblePoints([[lng,lat],[lng,lat]])
1647
+ */
1648
+ if (arg[0] instanceof Array) {
1641
1649
  var a = [];
1642
- for (var i = 0; i < ary.length; i++) {
1643
- a = new BMap.Point(ary[i][0], ary[i][1]);
1650
+ for (var i = 0; i < arg.length; i++) {
1651
+ a.push(new BMap.Point(arg[i][0], arg[i][1]));
1644
1652
  }
1645
1653
  obj = t.state.gis.getViewport(a);
1654
+ /**
1655
+ * 用法
1656
+ * map.setVisiblePoints(['lng,lat','lng,lat'])
1657
+ */
1646
1658
  } else {
1647
1659
  obj = t.getFitView(arg);
1648
1660
  }
@@ -2222,48 +2234,63 @@ var BaiduMap = function (_React$Component) {
2222
2234
 
2223
2235
  }, {
2224
2236
  key: 'showControl',
2225
- value: function showControl() {
2237
+ value: function showControl(props) {
2226
2238
  var t = this,
2227
2239
  location = t.AnchorConstant['tr'],
2228
2240
  type = '',
2229
2241
  offset = null,
2230
2242
  scaleOffset = null;
2231
- if (t.props.showControl.location) {
2232
- location = t.AnchorConstant[t.props.showControl.location];
2243
+ var config = props || t.props;
2244
+ if (t.scaleControl) {
2245
+ t.state.gis.removeControl(t.scaleControl);
2233
2246
  }
2234
- if (t.props.showControl.type) {
2235
- type = t.NavigationConstant[t.props.showControl.type];
2247
+ if (t.navigationControl) {
2248
+ t.state.gis.removeControl(t.navigationControl);
2236
2249
  }
2237
- if (t.props.showControl.offset && t.props.showControl.offset.length > 0) {
2238
- offset = new BMap.Size(t.props.showControl.offset[0], t.props.showControl.offset[1]);
2239
- scaleOffset = new BMap.Size(t.props.showControl.offset[0] + 70, t.props.showControl.offset[1]);
2250
+ if (config.showControl.location) {
2251
+ location = t.AnchorConstant[config.showControl.location];
2252
+ }
2253
+ if (config.showControl.type) {
2254
+ type = t.NavigationConstant[config.showControl.type];
2255
+ }
2256
+ if (config.showControl.offset && config.showControl.offset.length > 0) {
2257
+ offset = new BMap.Size(config.showControl.offset[0], config.showControl.offset[1]);
2258
+ scaleOffset = new BMap.Size(config.showControl.offset[0] + 70, config.showControl.offset[1]);
2240
2259
  }
2241
2260
  // 左上角,添加比例尺
2242
2261
  var control = new BMap.ScaleControl({ anchor: location, offset: scaleOffset });
2243
2262
  t.state.gis.addControl(control);
2263
+ t.scaleControl = control;
2244
2264
  if (type !== 'null') {
2245
2265
  //右上角,仅包含平移和缩放按钮
2246
2266
  var navigation = new BMap.NavigationControl({ anchor: location, type: type, offset: offset });
2247
2267
  t.state.gis.addControl(navigation);
2268
+ t.navigationControl = navigation;
2248
2269
  }
2249
2270
  }
2250
2271
  //展示地图切换控件
2251
2272
 
2252
2273
  }, {
2253
2274
  key: 'showMapTypeControl',
2254
- value: function showMapTypeControl() {
2275
+ value: function showMapTypeControl(props) {
2255
2276
  var t = this,
2256
2277
  location = t.AnchorConstant['br'],
2257
2278
  offset = null;
2258
- if (t.props.satelliteSwitch.location) {
2259
- location = t.AnchorConstant[t.props.satelliteSwitch.location];
2279
+ var config = props || t.props;
2280
+ if (t.mapTypeControl) {
2281
+ t.state.gis.removeControl(t.mapTypeControl);
2282
+ }
2283
+ if (config.satelliteSwitch.location) {
2284
+ location = t.AnchorConstant[config.satelliteSwitch.location];
2260
2285
  }
2261
- if (t.props.satelliteSwitch.offset && t.props.satelliteSwitch.offset.length > 0) {
2262
- offset = new BMap.Size(t.props.satelliteSwitch.offset[0], t.props.satelliteSwitch.offset[1]);
2286
+ if (config.satelliteSwitch.offset && config.satelliteSwitch.offset.length > 0) {
2287
+ offset = new BMap.Size(config.satelliteSwitch.offset[0], config.satelliteSwitch.offset[1]);
2263
2288
  }
2289
+ var mapTypes = [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP];
2264
2290
  // 地图切换控件
2265
- var control = new BMap.MapTypeControl({ anchor: location, type: BMAP_MAPTYPE_CONTROL_MAP, offset: offset });
2291
+ var control = new BMap.MapTypeControl({ mapTypes: mapTypes, anchor: location, type: BMAP_MAPTYPE_CONTROL_HORIZONTAL, offset: offset });
2266
2292
  t.state.gis.addControl(control);
2293
+ t.mapTypeControl = control;
2267
2294
  }
2268
2295
  /*设置显示区域*/
2269
2296
 
@@ -3119,6 +3146,14 @@ var BaiduMap = function (_React$Component) {
3119
3146
  t.removeGraphic(item.id, item.type);
3120
3147
  });
3121
3148
  }
3149
+ // 比例尺控件位置改变
3150
+ if (nextProps.showControl && JSON.stringify(nextProps.showControl) != JSON.stringify(t.props.showControl)) {
3151
+ t.showControl(nextProps);
3152
+ }
3153
+ // 地图类型控件位置改变
3154
+ if (nextProps.satelliteSwitch && JSON.stringify(nextProps.satelliteSwitch) != JSON.stringify(t.props.satelliteSwitch)) {
3155
+ t.showMapTypeControl(nextProps);
3156
+ }
3122
3157
  }
3123
3158
  }, {
3124
3159
  key: 'componentWillUnmount',
@@ -3132,7 +3167,7 @@ var BaiduMap = function (_React$Component) {
3132
3167
  if (t.moveToTimer) {
3133
3168
  clearInterval(t.moveToTimer);
3134
3169
  }
3135
- window.VtxMap[t.state.mapId] = null;
3170
+ window.VtxMap && (window.VtxMap[t.state.mapId] = null);
3136
3171
  }
3137
3172
  }]);
3138
3173
 
@@ -301,8 +301,8 @@ var Map = function (_React$Component) {
301
301
  }
302
302
  });
303
303
  /*=================================start========================================*/
304
- /*
305
- draw对象声明, 绘制返回方法实现
304
+ /*
305
+ draw对象声明, 绘制返回方法实现
306
306
  */
307
307
  if (!t._drawmanager) {
308
308
  t._drawmanager = new google.maps.drawing.DrawingManager({
@@ -316,9 +316,9 @@ var Map = function (_React$Component) {
316
316
  t._cluster = new OMapLib.MarkerClusterer(map, [], { maxZoom: options.maxZoom });
317
317
  }
318
318
  /*=================================start========================================*/
319
- /*
320
- 声明OverlayView 类
321
- 用于切换lnglat和 pixel
319
+ /*
320
+ 声明OverlayView 类
321
+ 用于切换lnglat和 pixel
322
322
  */
323
323
  function CanvasProjectionOverlay() {}
324
324
  CanvasProjectionOverlay.prototype = new google.maps.OverlayView();
@@ -329,9 +329,9 @@ var Map = function (_React$Component) {
329
329
  this.canvasProjectionOverlay = new CanvasProjectionOverlay();
330
330
  this.canvasProjectionOverlay.setMap(map);
331
331
  /*=================================start========================================*/
332
- /*
333
- 重写marker对象,支持html
334
- 要使用google对象,所以在creatMap中声明
332
+ /*
333
+ 重写marker对象,支持html
334
+ 要使用google对象,所以在creatMap中声明
335
335
  */
336
336
  var MyLabel = t.MyLabel = function (map) {
337
337
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -725,7 +725,7 @@ var Map = function (_React$Component) {
725
725
  var position = new t.omap.LatLng({ lng: item.longitude, lat: item.latitude });
726
726
  var marker = null;
727
727
  if (item.markerContent) {
728
- /*自定义html加点
728
+ /*自定义html加点
729
729
  用Label来实现,无法再添加label(高德有判断,实现不同)*/
730
730
  //覆盖物参数
731
731
  marker = new t.MyLabel(t.state.gis, {
@@ -747,9 +747,9 @@ var Map = function (_React$Component) {
747
747
  isLabel: true,
748
748
  labelClass: labelClass,
749
749
  labelContent: cg.labelContent,
750
- /*
751
- 为和百度等地图相同的参数 加上g.markerContentY值
752
- label是使用OverlayView手动实现,与marker没有关联的原因
750
+ /*
751
+ 为和百度等地图相同的参数 加上g.markerContentY值
752
+ label是使用OverlayView手动实现,与marker没有关联的原因
753
753
  */
754
754
  labelOffset: { x: cg.labelPixelX, y: cg.labelPixelY + cg.markerContentY }
755
755
  });
@@ -904,9 +904,9 @@ var Map = function (_React$Component) {
904
904
  var oldPosition = gc.getPosition();
905
905
  //前后点位类型都是markerContent
906
906
  if (gc.isMarkerContent && gc.isMarkerContent() && item.markerContent) {
907
- /*
908
- 自定义html加点
909
- 用Label来实现,无法再添加label(高德有判断,实现不同)
907
+ /*
908
+ 自定义html加点
909
+ 用Label来实现,无法再添加label(高德有判断,实现不同)
910
910
  */
911
911
  //覆盖物参数
912
912
  gc.setOptions({
@@ -960,9 +960,9 @@ var Map = function (_React$Component) {
960
960
  gc_label.setOptions({
961
961
  labelClass: labelClass,
962
962
  labelContent: cg.labelContent,
963
- /*
964
- 为和百度等地图相同的参数 加上g.markerContentY值
965
- label是使用OverlayView手动实现,与marker没有关联的原因
963
+ /*
964
+ 为和百度等地图相同的参数 加上g.markerContentY值
965
+ label是使用OverlayView手动实现,与marker没有关联的原因
966
966
  */
967
967
  labelOffset: { x: cg.labelPixelX, y: cg.labelPixelY + cg.markerContentY }
968
968
  });
@@ -1072,9 +1072,9 @@ var Map = function (_React$Component) {
1072
1072
  gc_label.setOptions({
1073
1073
  labelClass: _labelClass,
1074
1074
  labelContent: cg.labelContent,
1075
- /*
1076
- 为和百度等地图相同的参数 加上g.markerContentY值
1077
- label是使用OverlayView手动实现,与marker没有关联的原因
1075
+ /*
1076
+ 为和百度等地图相同的参数 加上g.markerContentY值
1077
+ label是使用OverlayView手动实现,与marker没有关联的原因
1078
1078
  */
1079
1079
  labelOffset: { x: cg.labelPixelX, y: cg.labelPixelY + cg.markerContentY }
1080
1080
  });
@@ -2396,8 +2396,8 @@ var Map = function (_React$Component) {
2396
2396
  var t = this;
2397
2397
  t._drawmanager.setDrawingMode(null);
2398
2398
  }
2399
- /*
2400
- 事件处理
2399
+ /*
2400
+ 事件处理
2401
2401
  */
2402
2402
  //点击图元事件
2403
2403
 
@@ -2482,8 +2482,8 @@ var Map = function (_React$Component) {
2482
2482
  t.props.mouseOutGraphic(obj);
2483
2483
  }
2484
2484
  }
2485
- /*
2486
- 地图服务功能
2485
+ /*
2486
+ 地图服务功能
2487
2487
  */
2488
2488
  //开启路况
2489
2489
 
@@ -3319,9 +3319,9 @@ var Map = function (_React$Component) {
3319
3319
  }
3320
3320
  return deg;
3321
3321
  }
3322
- /*
3323
- 匹配控件位置方法
3324
- (谷歌地图有8个方位,为了统一,只使用左上,左下,右上,右下)
3322
+ /*
3323
+ 匹配控件位置方法
3324
+ (谷歌地图有8个方位,为了统一,只使用左上,左下,右上,右下)
3325
3325
  */
3326
3326
 
3327
3327
  }, {
@@ -3344,8 +3344,8 @@ var Map = function (_React$Component) {
3344
3344
  }
3345
3345
  return position;
3346
3346
  }
3347
- /*
3348
- 地图内部需要公共方法
3347
+ /*
3348
+ 地图内部需要公共方法
3349
3349
  */
3350
3350
 
3351
3351
  }, {
@@ -3560,10 +3560,10 @@ var Map = function (_React$Component) {
3560
3560
  if (typeof isclearAllPointCollection == 'boolean' && isclearAllPointCollection || isclearAllPointCollection && isclearAllPointCollection !== t.props.isclearAllPointCollection) {
3561
3561
  t.clearAllPointCollection();
3562
3562
  }
3563
- /*点数据处理
3564
- pointData[2]相同的点,执行刷新
3565
- pointData[1]的数据在idsForGraphicId中不存在的,执行新增
3566
- pointData[0]数据中多余的id,执行删除
3563
+ /*点数据处理
3564
+ pointData[2]相同的点,执行刷新
3565
+ pointData[1]的数据在idsForGraphicId中不存在的,执行新增
3566
+ pointData[0]数据中多余的id,执行删除
3567
3567
  */
3568
3568
  if (mapPoints instanceof Array && props.mapPoints instanceof Array && !t.deepEqual(mapPoints, props.mapPoints)) {
3569
3569
  var oldMapPoints = props.mapPoints;
@@ -3623,9 +3623,9 @@ var Map = function (_React$Component) {
3623
3623
  //更新
3624
3624
  t.updatePoint([].concat(_toConsumableArray(upds), _toConsumableArray(otherupds)));
3625
3625
  }
3626
- /*
3627
- 面数据处理
3628
- 先全删除,再新增
3626
+ /*
3627
+ 面数据处理
3628
+ 先全删除,再新增
3629
3629
  */
3630
3630
  if (mapPolygons instanceof Array && props.mapPolygons instanceof Array && !t.deepEqual(mapPolygons, props.mapPolygons)) {
3631
3631
  var oldMapPolygons = props.mapPolygons;
@@ -3684,9 +3684,9 @@ var Map = function (_React$Component) {
3684
3684
  //更新
3685
3685
  t.updatePolygon([].concat(_toConsumableArray(_upds), _toConsumableArray(_otherupds)));
3686
3686
  }
3687
- /*
3688
- 圆数据处理
3689
- 先全删除,再新增
3687
+ /*
3688
+ 圆数据处理
3689
+ 先全删除,再新增
3690
3690
  */
3691
3691
  if (mapCircles instanceof Array && props.mapCircles instanceof Array && !t.deepEqual(mapCircles, props.mapCircles)) {
3692
3692
  var oldMapCircles = props.mapCircles;
@@ -3745,9 +3745,9 @@ var Map = function (_React$Component) {
3745
3745
  //更新
3746
3746
  t.updateCircle([].concat(_toConsumableArray(_upds2), _toConsumableArray(_otherupds2)));
3747
3747
  }
3748
- /*
3749
- 线数据处理
3750
- 先全删除,再新增
3748
+ /*
3749
+ 线数据处理
3750
+ 先全删除,再新增
3751
3751
  */
3752
3752
  if (mapLines instanceof Array && props.mapLines instanceof Array && !t.deepEqual(mapLines, props.mapLines)) {
3753
3753
  var oldMapLines = props.mapLines;
@@ -1,70 +1,70 @@
1
- .label-content{
2
- display: inline-block;
3
- padding: 5px;
4
- line-height: 22px;
5
- text-align: center;
6
- border-radius: 5px;
7
- background-color: #fff;
8
- opacity: 1;
9
- color: #5DD0EE;
10
- transform: translate(-50%);
11
- -ms-transform: translate(-50%);
12
- }
13
- .noselect {
14
- -webkit-touch-callout: none; /* iOS Safari */
15
- -webkit-user-select: none; /* Chrome/Safari/Opera */
16
- -khtml-user-select: none; /* Konqueror */
17
- -moz-user-select: none; /* Firefox */
18
- -ms-user-select: none; /* Internet Explorer/Edge */
19
- user-select: none; /* Non-prefixed version, currently
20
- not supported by any browser */
21
- }
22
- .vtx_gmap_html_pointCollection_a{
23
- position: absolute;
24
- canvas{
25
- z-index: 111;
26
- }
27
- }
28
- .vtx-g-rangingPoint{
29
- width: 8px;
30
- height: 8px;
31
- background-color: #fff;
32
- border: 2px solid #108ee9;
33
- display: inline-block;
34
- border-radius: 8px;
35
- position: relative;
36
- top: 5px;
37
- left: 1px;
38
- }
39
- .vtx-g-rangingDistance{
40
- position: relative;
41
- top: -36px;
42
- left: 15px;
43
- height: 30px;
44
- line-height: 28px;
45
- background-color: #fff;
46
- border: 1px solid #108ee9;
47
- font-size: 12px;
48
- word-break: keep-all;
49
- padding: 0px 3px;
50
- color: #108ee9;
51
- }
52
- .vtx-g-rang-exit{
53
- width: 12px;
54
- height: 12px;
55
- background-color: #fff;
56
- border: 2px solid #108ee9;
57
- color: #108ee9;
58
- line-height: 7px;
59
- text-align: center;
60
- font-size: 12px;
61
- cursor: pointer;
62
- }
63
- .vtx-g-rang-showRangTool{
64
- line-height: 18px;
65
- font-size: 12px;
66
- border: 1px solid #108ee9;
67
- word-break: keep-all;
68
- background-color: #fff;
69
- padding: 0px 5px;
70
- }
1
+ .label-content{
2
+ display: inline-block;
3
+ padding: 5px;
4
+ line-height: 22px;
5
+ text-align: center;
6
+ border-radius: 5px;
7
+ background-color: #fff;
8
+ opacity: 1;
9
+ color: #5DD0EE;
10
+ transform: translate(-50%);
11
+ -ms-transform: translate(-50%);
12
+ }
13
+ .noselect {
14
+ -webkit-touch-callout: none; /* iOS Safari */
15
+ -webkit-user-select: none; /* Chrome/Safari/Opera */
16
+ -khtml-user-select: none; /* Konqueror */
17
+ -moz-user-select: none; /* Firefox */
18
+ -ms-user-select: none; /* Internet Explorer/Edge */
19
+ user-select: none; /* Non-prefixed version, currently
20
+ not supported by any browser */
21
+ }
22
+ .vtx_gmap_html_pointCollection_a{
23
+ position: absolute;
24
+ canvas{
25
+ z-index: 111;
26
+ }
27
+ }
28
+ .vtx-g-rangingPoint{
29
+ width: 8px;
30
+ height: 8px;
31
+ background-color: #fff;
32
+ border: 2px solid #108ee9;
33
+ display: inline-block;
34
+ border-radius: 8px;
35
+ position: relative;
36
+ top: 5px;
37
+ left: 1px;
38
+ }
39
+ .vtx-g-rangingDistance{
40
+ position: relative;
41
+ top: -36px;
42
+ left: 15px;
43
+ height: 30px;
44
+ line-height: 28px;
45
+ background-color: #fff;
46
+ border: 1px solid #108ee9;
47
+ font-size: 12px;
48
+ word-break: keep-all;
49
+ padding: 0px 3px;
50
+ color: #108ee9;
51
+ }
52
+ .vtx-g-rang-exit{
53
+ width: 12px;
54
+ height: 12px;
55
+ background-color: #fff;
56
+ border: 2px solid #108ee9;
57
+ color: #108ee9;
58
+ line-height: 7px;
59
+ text-align: center;
60
+ font-size: 12px;
61
+ cursor: pointer;
62
+ }
63
+ .vtx-g-rang-showRangTool{
64
+ line-height: 18px;
65
+ font-size: 12px;
66
+ border: 1px solid #108ee9;
67
+ word-break: keep-all;
68
+ background-color: #fff;
69
+ padding: 0px 5px;
70
+ }
@@ -565,41 +565,75 @@ var TMap = function (_React$Component) {
565
565
 
566
566
  }, {
567
567
  key: 'showControl',
568
- value: function showControl() {
568
+ value: function showControl(props) {
569
569
  var t = this,
570
570
  location = t.AnchorConstant['tr'],
571
571
  offset = null,
572
572
  scaleOffset = null;
573
- if (t.props.showControl.location) {
574
- location = t.AnchorConstant[t.props.showControl.location];
573
+ var config = props || t.props;
574
+ if (t.scaleControl) {
575
+ t.state.gis.removeControl(t.scaleControl);
576
+ }
577
+ if (t.navigationControl) {
578
+ t.state.gis.removeControl(t.navigationControl);
579
+ }
580
+ if (config.showControl.location) {
581
+ location = t.AnchorConstant[config.showControl.location];
575
582
  }
576
- if (t.props.showControl.offset && t.props.showControl.offset.length > 0) {}
577
- // TODO不支持偏移
578
-
579
583
  // 添加比例尺
580
584
  var control = new T.Control.Scale({ position: location, offset: scaleOffset });
581
585
  t.state.gis.addControl(control);
586
+ t.scaleControl = control;
582
587
  // 缩放地图
583
588
  var navigation = new T.Control.Zoom({ position: location, offset: offset });
584
589
  t.state.gis.addControl(navigation);
590
+ t.navigationControl = navigation;
591
+
592
+ // TODO不支持偏移,手动偏移
593
+ if (config.showControl.offset && config.showControl.offset.length > 0) {
594
+ if (location == "topright") {
595
+ $('div.tdt-top.tdt-right').css({ right: config.showControl.offset[0], top: config.showControl.offset[1] });
596
+ } else if (location == "topleft") {
597
+ $('div.tdt-top.tdt-left').css({ left: config.showControl.offset[0], top: config.showControl.offset[1] });
598
+ } else if (location == "bottomleft") {
599
+ $('div.tdt-bottom.tdt-left').css({ left: config.showControl.offset[0], bottom: config.showControl.offset[1] });
600
+ } else if (location == "bottomright") {
601
+ $('div.tdt-bottom.tdt-right').css({ right: config.showControl.offset[0], bottom: config.showControl.offset[1] });
602
+ }
603
+ }
585
604
  }
586
605
  //展示地图切换控件
587
606
 
588
607
  }, {
589
608
  key: 'showMapTypeControl',
590
- value: function showMapTypeControl() {
609
+ value: function showMapTypeControl(props) {
591
610
  var t = this,
592
611
  location = t.AnchorConstant['br'],
593
612
  offset = null;
594
- if (t.props.satelliteSwitch.location) {
595
- location = t.AnchorConstant[t.props.satelliteSwitch.location];
613
+ var config = props || t.props;
614
+ if (t.mapTypeControl) {
615
+ t.state.gis.removeControl(t.mapTypeControl);
616
+ }
617
+ if (config.satelliteSwitch.location) {
618
+ location = t.AnchorConstant[config.satelliteSwitch.location];
596
619
  }
597
- if (t.props.satelliteSwitch.offset && t.props.satelliteSwitch.offset.length > 0) {}
598
- // TODO不支持偏移
599
-
600
620
  // 地图切换控件
601
621
  var control = new T.Control.MapType({ position: location, offset: offset });
602
622
  t.state.gis.addControl(control);
623
+ t.mapTypeControl = control;
624
+
625
+ // TODO不支持偏移,手动偏移
626
+ if (config.satelliteSwitch.offset && config.satelliteSwitch.offset.length > 0) {
627
+ if (location == "topright") {
628
+ $('div.tdt-top.tdt-right').css({ right: config.satelliteSwitch.offset[0], top: config.satelliteSwitch.offset[1] });
629
+ } else if (location == "topleft") {
630
+ $('div.tdt-top.tdt-left').css({ left: config.satelliteSwitch.offset[0], top: config.satelliteSwitch.offset[1] });
631
+ } else if (location == "bottomleft") {
632
+ $('div.tdt-bottom.tdt-left').css({ left: config.satelliteSwitch.offset[0], bottom: config.satelliteSwitch.offset[1] });
633
+ } else if (location == "bottomright") {
634
+ $('div.tdt-bottom.tdt-right').css({ right: config.satelliteSwitch.offset[0], bottom: config.satelliteSwitch.offset[1] });
635
+ }
636
+ }
603
637
  }
604
638
  //测距
605
639
 
@@ -1517,11 +1551,11 @@ var TMap = function (_React$Component) {
1517
1551
  t.heatmap.hide();
1518
1552
  }
1519
1553
  }
1520
- /*
1521
- 参数
1522
- geometryType:point/polyline/polygon/circle/rectangle 默认point
1523
- parameter 样式 默认null 对象{}写入方式跟add方法一样(对应点线圆面)
1524
- data //初始化数据 默认{id:'add'}
1554
+ /*
1555
+ 参数
1556
+ geometryType:point/polyline/polygon/circle/rectangle 默认point
1557
+ parameter 样式 默认null 对象{}写入方式跟add方法一样(对应点线圆面)
1558
+ data //初始化数据 默认{id:'add'}
1525
1559
  */
1526
1560
 
1527
1561
  }, {
@@ -2727,10 +2761,10 @@ var TMap = function (_React$Component) {
2727
2761
  t.clearAllPointCollection();
2728
2762
  }
2729
2763
 
2730
- /*点数据处理
2731
- pointData[2]相同的点,执行刷新
2732
- pointData[1]的数据在idsForGraphicId中不存在的,执行新增
2733
- pointData[0]数据中多余的id,执行删除
2764
+ /*点数据处理
2765
+ pointData[2]相同的点,执行刷新
2766
+ pointData[1]的数据在idsForGraphicId中不存在的,执行新增
2767
+ pointData[0]数据中多余的id,执行删除
2734
2768
  */
2735
2769
  if (mapPoints instanceof Array && t.props.mapPoints instanceof Array && !t.deepEqual(mapPoints, t.props.mapPoints)) {
2736
2770
  var oldMapPoints = t.props.mapPoints;
@@ -2790,9 +2824,9 @@ var TMap = function (_React$Component) {
2790
2824
  //更新
2791
2825
  t.updatePoint([].concat(_toConsumableArray(upds), _toConsumableArray(otherupds)));
2792
2826
  }
2793
- /*
2794
- 面数据处理
2795
- 先全删除,再新增
2827
+ /*
2828
+ 面数据处理
2829
+ 先全删除,再新增
2796
2830
  */
2797
2831
  if (mapPolygons instanceof Array && t.props.mapPolygons instanceof Array && !t.deepEqual(mapPolygons, t.props.mapPolygons)) {
2798
2832
  var oldMapPolygons = t.props.mapPolygons;
@@ -2851,9 +2885,9 @@ var TMap = function (_React$Component) {
2851
2885
  //更新
2852
2886
  t.updatePolygon([].concat(_toConsumableArray(_upds), _toConsumableArray(_otherupds)));
2853
2887
  }
2854
- /*
2855
- 圆数据处理
2856
- 先全删除,再新增
2888
+ /*
2889
+ 圆数据处理
2890
+ 先全删除,再新增
2857
2891
  */
2858
2892
  if (mapCircles instanceof Array && t.props.mapCircles instanceof Array && !t.deepEqual(mapCircles, t.props.mapCircles)) {
2859
2893
  var oldMapCircles = t.props.mapCircles;
@@ -2912,9 +2946,9 @@ var TMap = function (_React$Component) {
2912
2946
  //更新
2913
2947
  t.updateCircle([].concat(_toConsumableArray(_upds2), _toConsumableArray(_otherupds2)));
2914
2948
  }
2915
- /*
2916
- 线数据处理
2917
- 先全删除,再新增
2949
+ /*
2950
+ 线数据处理
2951
+ 先全删除,再新增
2918
2952
  */
2919
2953
  if (mapLines instanceof Array && t.props.mapLines instanceof Array && !t.deepEqual(mapLines, t.props.mapLines)) {
2920
2954
  var oldMapLines = t.props.mapLines;
@@ -3106,6 +3140,15 @@ var TMap = function (_React$Component) {
3106
3140
  }
3107
3141
  }, 100);
3108
3142
  }
3143
+
3144
+ // 比例尺控件位置改变
3145
+ if (nextProps.showControl && JSON.stringify(nextProps.showControl) != JSON.stringify(t.props.showControl)) {
3146
+ t.showControl(nextProps);
3147
+ }
3148
+ // 地图类型控件位置改变
3149
+ if (nextProps.satelliteSwitch && JSON.stringify(nextProps.satelliteSwitch) != JSON.stringify(t.props.satelliteSwitch)) {
3150
+ t.showMapTypeControl(nextProps);
3151
+ }
3109
3152
  }
3110
3153
  }, {
3111
3154
  key: 'componentWillUnmount',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtx/map",
3
- "version": "1.0.4",
3
+ "version": "1.0.8",
4
4
  "description": "@vtx/map",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {