@antv/l7-component 2.9.34 → 2.9.36-alpha.1

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.
Files changed (110) hide show
  1. package/es/assets/iconfont/iconfont.js +53 -0
  2. package/es/constants/index.d.ts +60 -0
  3. package/es/constants/index.js +60 -0
  4. package/es/control/baseControl/buttonControl.d.ts +59 -0
  5. package/es/control/baseControl/buttonControl.js +191 -0
  6. package/es/control/baseControl/control.d.ts +106 -0
  7. package/es/control/baseControl/control.js +301 -0
  8. package/es/control/baseControl/index.d.ts +4 -0
  9. package/es/control/baseControl/index.js +4 -0
  10. package/es/control/baseControl/popperControl.d.ts +26 -0
  11. package/es/control/baseControl/popperControl.js +131 -0
  12. package/es/control/baseControl/selectControl.d.ts +46 -0
  13. package/es/control/baseControl/selectControl.js +232 -0
  14. package/es/control/exportImage.d.ts +18 -0
  15. package/es/control/exportImage.js +163 -0
  16. package/es/control/fullscreen.d.ts +19 -0
  17. package/es/control/fullscreen.js +151 -0
  18. package/es/control/geoLocate.d.ts +16 -0
  19. package/es/control/geoLocate.js +139 -0
  20. package/es/control/layerControl.d.ts +21 -0
  21. package/es/control/layerControl.js +172 -0
  22. package/es/control/logo.d.ts +10 -6
  23. package/es/control/logo.js +41 -11
  24. package/es/control/mapTheme.d.ts +10 -0
  25. package/es/control/mapTheme.js +135 -0
  26. package/es/control/mouseLocation.d.ts +15 -0
  27. package/es/control/mouseLocation.js +104 -0
  28. package/es/control/scale.d.ts +20 -10
  29. package/es/control/scale.js +77 -53
  30. package/es/control/zoom.d.ts +21 -10
  31. package/es/control/zoom.js +76 -49
  32. package/es/css/button.less +70 -0
  33. package/es/css/control.less +71 -0
  34. package/es/css/index.css +567 -0
  35. package/es/css/index.less +12 -0
  36. package/es/css/l7.less +60 -0
  37. package/es/css/layerPopup.less +8 -0
  38. package/es/css/logo.less +18 -0
  39. package/es/css/mouseLocation.less +9 -0
  40. package/es/css/popper.less +64 -0
  41. package/es/css/popup.less +169 -0
  42. package/es/css/scale.less +34 -0
  43. package/es/css/select.less +86 -0
  44. package/es/css/variables.less +28 -0
  45. package/es/css/zoom.less +21 -0
  46. package/es/images/logo.png +0 -0
  47. package/es/images/quanping.svg +12 -0
  48. package/es/index.d.ts +15 -8
  49. package/es/index.js +15 -9
  50. package/es/interface.d.ts +1 -20
  51. package/es/popup/layerPopup.d.ts +78 -0
  52. package/es/popup/layerPopup.js +308 -0
  53. package/es/popup/popup.d.ts +147 -0
  54. package/es/popup/popup.js +636 -0
  55. package/es/utils/icon.d.ts +1 -0
  56. package/es/utils/icon.js +9 -0
  57. package/es/utils/popper.d.ts +75 -0
  58. package/es/utils/popper.js +286 -0
  59. package/es/utils/screenfull.d.ts +2 -0
  60. package/es/utils/screenfull.js +157 -0
  61. package/lib/assets/iconfont/iconfont.js +55 -0
  62. package/lib/constants/index.js +68 -0
  63. package/lib/control/baseControl/buttonControl.js +207 -0
  64. package/lib/control/baseControl/control.js +333 -0
  65. package/lib/control/baseControl/index.js +57 -0
  66. package/lib/control/baseControl/popperControl.js +142 -0
  67. package/lib/control/baseControl/selectControl.js +253 -0
  68. package/lib/control/exportImage.js +177 -0
  69. package/lib/control/fullscreen.js +164 -0
  70. package/lib/control/geoLocate.js +154 -0
  71. package/lib/control/layerControl.js +182 -0
  72. package/lib/control/logo.js +50 -23
  73. package/lib/control/mapTheme.js +151 -0
  74. package/lib/control/mouseLocation.js +120 -0
  75. package/lib/control/scale.js +82 -62
  76. package/lib/control/zoom.js +78 -59
  77. package/lib/css/button.less +70 -0
  78. package/lib/css/control.less +71 -0
  79. package/lib/css/index.css +567 -0
  80. package/lib/css/index.less +12 -0
  81. package/lib/css/l7.less +60 -0
  82. package/lib/css/layerPopup.less +8 -0
  83. package/lib/css/logo.less +18 -0
  84. package/lib/css/mouseLocation.less +9 -0
  85. package/lib/css/popper.less +64 -0
  86. package/lib/css/popup.less +169 -0
  87. package/lib/css/scale.less +34 -0
  88. package/lib/css/select.less +86 -0
  89. package/lib/css/variables.less +28 -0
  90. package/lib/css/zoom.less +21 -0
  91. package/lib/images/logo.png +0 -0
  92. package/lib/images/quanping.svg +12 -0
  93. package/lib/index.js +165 -50
  94. package/lib/popup/layerPopup.js +317 -0
  95. package/lib/popup/popup.js +651 -0
  96. package/lib/utils/icon.js +18 -0
  97. package/lib/utils/popper.js +297 -0
  98. package/lib/utils/screenfull.js +167 -0
  99. package/package.json +8 -5
  100. package/es/control/BaseControl.d.ts +0 -27
  101. package/es/control/BaseControl.js +0 -134
  102. package/es/control/layer.d.ts +0 -38
  103. package/es/control/layer.js +0 -340
  104. package/es/css/l7.css +0 -502
  105. package/es/popup.d.ts +0 -35
  106. package/es/popup.js +0 -300
  107. package/lib/control/BaseControl.js +0 -160
  108. package/lib/control/layer.js +0 -362
  109. package/lib/css/l7.css +0 -502
  110. package/lib/popup.js +0 -317
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = exports.MapTheme = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
19
+
20
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
21
+
22
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
23
+
24
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
25
+
26
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
27
+
28
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
29
+
30
+ var _constants = require("../constants");
31
+
32
+ var _icon = require("../utils/icon");
33
+
34
+ var _selectControl = _interopRequireDefault(require("./baseControl/selectControl"));
35
+
36
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
37
+
38
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
39
+
40
+ var MapTheme = /*#__PURE__*/function (_SelectControl) {
41
+ (0, _inherits2.default)(MapTheme, _SelectControl);
42
+
43
+ var _super = _createSuper(MapTheme);
44
+
45
+ function MapTheme() {
46
+ var _this;
47
+
48
+ (0, _classCallCheck2.default)(this, MapTheme);
49
+
50
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
51
+ args[_key] = arguments[_key];
52
+ }
53
+
54
+ _this = _super.call.apply(_super, [this].concat(args));
55
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMapThemeChange", function () {
56
+ _this.mapsService.setMapStyle(_this.selectValue[0]);
57
+ });
58
+ return _this;
59
+ }
60
+
61
+ (0, _createClass2.default)(MapTheme, [{
62
+ key: "getDefault",
63
+ value: function getDefault(option) {
64
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(MapTheme.prototype), "getDefault", this).call(this, option)), {}, {
65
+ title: '地图样式',
66
+ btnIcon: (0, _icon.createL7Icon)('l7-icon-color'),
67
+ options: []
68
+ });
69
+ }
70
+ }, {
71
+ key: "getStyleOptions",
72
+ value: function getStyleOptions() {
73
+ var mapStyleConfig = this.mapsService.getType() === 'mapbox' ? _constants.MapboxMapStyleConfig : _constants.GaodeMapStyleConfig;
74
+ return Object.entries(this.mapsService.getMapStyleConfig()).filter(function (_ref) {
75
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
76
+ key = _ref2[0],
77
+ value = _ref2[1];
78
+
79
+ return typeof value === 'string' && key !== 'blank';
80
+ }).map(function (_ref3) {
81
+ var _mapStyleConfig$key;
82
+
83
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
84
+ key = _ref4[0],
85
+ value = _ref4[1];
86
+
87
+ // @ts-ignore
88
+ var _ref5 = (_mapStyleConfig$key = mapStyleConfig[key]) !== null && _mapStyleConfig$key !== void 0 ? _mapStyleConfig$key : {},
89
+ text = _ref5.text,
90
+ img = _ref5.img;
91
+
92
+ return {
93
+ text: text !== null && text !== void 0 ? text : key,
94
+ value: value,
95
+ img: img,
96
+ key: key
97
+ };
98
+ });
99
+ }
100
+ }, {
101
+ key: "getMapStyle",
102
+ value: function getMapStyle() {
103
+ return this.mapsService.getMapStyle();
104
+ }
105
+ }, {
106
+ key: "onAdd",
107
+ value: function onAdd() {
108
+ var _this$controlOption$o,
109
+ _this2 = this;
110
+
111
+ if (!((_this$controlOption$o = this.controlOption.options) !== null && _this$controlOption$o !== void 0 && _this$controlOption$o.length)) {
112
+ this.controlOption.options = this.getStyleOptions();
113
+ }
114
+
115
+ if (this.controlOption.defaultValue) {
116
+ var _this$controlOption$o2, _this$controlOption$o3;
117
+
118
+ var defaultValue = this.controlOption.defaultValue;
119
+ this.controlOption.defaultValue = (_this$controlOption$o2 = (_this$controlOption$o3 = this.controlOption.options.find(function (item) {
120
+ return item.key === defaultValue;
121
+ })) === null || _this$controlOption$o3 === void 0 ? void 0 : _this$controlOption$o3.value) !== null && _this$controlOption$o2 !== void 0 ? _this$controlOption$o2 : defaultValue;
122
+ } else {
123
+ var defaultStyle = this.getMapStyle();
124
+
125
+ if (defaultStyle) {
126
+ this.controlOption.defaultValue = defaultStyle;
127
+ } else {
128
+ // @ts-ignore
129
+ this.mapsService.map.once('styledata', function () {
130
+ var mapboxStyle = _this2.mapsService.getMapStyle();
131
+
132
+ _this2.controlOption.defaultValue = mapboxStyle;
133
+
134
+ _this2.setSelectValue(mapboxStyle, false);
135
+ });
136
+ }
137
+ }
138
+
139
+ this.on('selectChange', this.onMapThemeChange);
140
+ return (0, _get2.default)((0, _getPrototypeOf2.default)(MapTheme.prototype), "onAdd", this).call(this);
141
+ }
142
+ }, {
143
+ key: "getIsMultiple",
144
+ value: function getIsMultiple() {
145
+ return false;
146
+ }
147
+ }]);
148
+ return MapTheme;
149
+ }(_selectControl.default);
150
+
151
+ exports.default = exports.MapTheme = MapTheme;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = exports.MouseLocation = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
19
+
20
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
21
+
22
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
23
+
24
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
25
+
26
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
27
+
28
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
29
+
30
+ var _l7Core = require("@antv/l7-core");
31
+
32
+ var _l7Utils = require("@antv/l7-utils");
33
+
34
+ var _control = _interopRequireDefault(require("./baseControl/control"));
35
+
36
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
37
+
38
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
39
+
40
+ var MouseLocation = /*#__PURE__*/function (_Control) {
41
+ (0, _inherits2.default)(MouseLocation, _Control);
42
+
43
+ var _super = _createSuper(MouseLocation);
44
+
45
+ function MouseLocation() {
46
+ var _this;
47
+
48
+ (0, _classCallCheck2.default)(this, MouseLocation);
49
+
50
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
51
+ args[_key] = arguments[_key];
52
+ }
53
+
54
+ _this = _super.call.apply(_super, [this].concat(args));
55
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "location", [0, 0]);
56
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMouseMove", function (e) {
57
+ var position = _this.location;
58
+ var lngLat = e.lngLat || e.lnglat;
59
+ var transform = _this.controlOption.transform;
60
+
61
+ if (lngLat) {
62
+ position = [lngLat.lng, lngLat.lat];
63
+ }
64
+
65
+ _this.location = position;
66
+
67
+ if (transform) {
68
+ position = transform(position);
69
+ }
70
+
71
+ _this.insertLocation2HTML(position);
72
+
73
+ _this.emit('locationChange', position);
74
+ });
75
+ return _this;
76
+ }
77
+
78
+ (0, _createClass2.default)(MouseLocation, [{
79
+ key: "getLocation",
80
+ value: function getLocation() {
81
+ return this.location;
82
+ }
83
+ }, {
84
+ key: "getDefault",
85
+ value: function getDefault(option) {
86
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(MouseLocation.prototype), "getDefault", this).call(this, option)), {}, {
87
+ position: _l7Core.PositionType.BOTTOMLEFT,
88
+ transform: function transform(_ref) {
89
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
90
+ lng = _ref2[0],
91
+ lat = _ref2[1];
92
+
93
+ return [+(+lng).toFixed(6), +(+lat).toFixed(6)];
94
+ }
95
+ });
96
+ }
97
+ }, {
98
+ key: "onAdd",
99
+ value: function onAdd() {
100
+ var container = _l7Utils.DOM.create('div', 'l7-control-mouse-location');
101
+
102
+ container.innerHTML = '&nbsp;';
103
+ this.mapsService.on('mousemove', this.onMouseMove);
104
+ return container;
105
+ }
106
+ }, {
107
+ key: "onRemove",
108
+ value: function onRemove() {
109
+ this.mapsService.off('mousemove', this.onMouseMove);
110
+ }
111
+ }, {
112
+ key: "insertLocation2HTML",
113
+ value: function insertLocation2HTML(position) {
114
+ this.container.innerText = position.join(', ');
115
+ }
116
+ }]);
117
+ return MouseLocation;
118
+ }(_control.default);
119
+
120
+ exports.default = exports.MouseLocation = MouseLocation;
@@ -2,12 +2,12 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
- exports.default = void 0;
8
+ exports.default = exports.Scale = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
11
 
12
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
13
 
@@ -15,19 +15,19 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
15
15
 
16
16
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
17
 
18
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
19
+
18
20
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
21
 
20
22
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
23
 
22
24
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
25
 
24
- var _l7Utils = require("@antv/l7-utils");
25
-
26
- var _BaseControl = _interopRequireWildcard(require("./BaseControl"));
26
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
27
27
 
28
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
28
+ var _l7Utils = require("@antv/l7-utils");
29
29
 
30
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
30
+ var _baseControl = require("./baseControl");
31
31
 
32
32
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
33
33
 
@@ -38,26 +38,41 @@ var Scale = /*#__PURE__*/function (_Control) {
38
38
 
39
39
  var _super = _createSuper(Scale);
40
40
 
41
- function Scale(cfg) {
41
+ function Scale() {
42
42
  var _this;
43
43
 
44
44
  (0, _classCallCheck2.default)(this, Scale);
45
- _this = _super.call(this, cfg);
46
- (0, _l7Utils.bindAll)(['update'], (0, _assertThisInitialized2.default)(_this));
45
+
46
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
47
+ args[_key] = arguments[_key];
48
+ }
49
+
50
+ _this = _super.call.apply(_super, [this].concat(args));
51
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "update", function () {
52
+ var mapsService = _this.mapsService;
53
+ var maxWidth = _this.controlOption.maxWidth;
54
+ var y = mapsService.getSize()[1] / 2;
55
+ var p1 = mapsService.containerToLngLat([0, y]);
56
+ var p2 = mapsService.containerToLngLat([maxWidth, y]);
57
+ var maxMeters = (0, _l7Utils.lnglatDistance)([p1.lng, p1.lat], [p2.lng, p2.lat]);
58
+
59
+ _this.updateScales(maxMeters);
60
+ });
47
61
  return _this;
48
62
  }
49
63
 
50
64
  (0, _createClass2.default)(Scale, [{
51
65
  key: "getDefault",
52
- value: function getDefault() {
53
- return {
54
- position: _BaseControl.PositionType.BOTTOMLEFT,
66
+ value: function getDefault(option) {
67
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(Scale.prototype), "getDefault", this).call(this, option)), {}, {
68
+ name: 'scale',
69
+ position: _baseControl.PositionType.BOTTOMLEFT,
55
70
  maxWidth: 100,
56
71
  metric: true,
57
72
  updateWhenIdle: false,
58
73
  imperial: false,
59
- name: 'scale'
60
- };
74
+ lockWidth: true
75
+ });
61
76
  }
62
77
  }, {
63
78
  key: "onAdd",
@@ -66,13 +81,10 @@ var Scale = /*#__PURE__*/function (_Control) {
66
81
 
67
82
  var container = _l7Utils.DOM.create('div', className);
68
83
 
69
- this.addScales(className + '-line', container);
70
- var updateWhenIdle = this.controlOption.updateWhenIdle; // TODO: 高德地图和MapBox地图事件不一致问题
71
- // 高德zoomchange
72
-
84
+ this.resetScaleLines(container);
85
+ var updateWhenIdle = this.controlOption.updateWhenIdle;
73
86
  this.mapsService.on(updateWhenIdle ? 'moveend' : 'mapmove', this.update);
74
87
  this.mapsService.on(updateWhenIdle ? 'zoomend' : 'zoomchange', this.update);
75
- this.update();
76
88
  return container;
77
89
  }
78
90
  }, {
@@ -83,15 +95,13 @@ var Scale = /*#__PURE__*/function (_Control) {
83
95
  this.mapsService.off(updateWhenIdle ? 'moveend' : 'mapmove', this.update);
84
96
  }
85
97
  }, {
86
- key: "update",
87
- value: function update() {
88
- var mapsService = this.mapsService;
89
- var maxWidth = this.controlOption.maxWidth;
90
- var y = mapsService.getSize()[1] / 2;
91
- var p1 = mapsService.containerToLngLat([0, y]);
92
- var p2 = mapsService.containerToLngLat([maxWidth, y]);
93
- var maxMeters = (0, _l7Utils.lnglatDistance)([p1.lng, p1.lat], [p2.lng, p2.lat]);
94
- this.updateScales(maxMeters);
98
+ key: "setOptions",
99
+ value: function setOptions(newOption) {
100
+ (0, _get2.default)((0, _getPrototypeOf2.default)(Scale.prototype), "setOptions", this).call(this, newOption);
101
+
102
+ if (this.checkUpdateOption(newOption, ['lockWidth', 'maxWidth', 'metric', 'updateWhenIdle', 'imperial'])) {
103
+ this.resetScaleLines(this.container);
104
+ }
95
105
  }
96
106
  }, {
97
107
  key: "updateScales",
@@ -108,6 +118,46 @@ var Scale = /*#__PURE__*/function (_Control) {
108
118
  this.updateImperial(maxMeters);
109
119
  }
110
120
  }
121
+ }, {
122
+ key: "resetScaleLines",
123
+ value: function resetScaleLines(container) {
124
+ _l7Utils.DOM.clearChildren(container);
125
+
126
+ var _this$controlOption2 = this.controlOption,
127
+ metric = _this$controlOption2.metric,
128
+ imperial = _this$controlOption2.imperial,
129
+ maxWidth = _this$controlOption2.maxWidth,
130
+ lockWidth = _this$controlOption2.lockWidth;
131
+
132
+ if (lockWidth) {
133
+ _l7Utils.DOM.addStyle(container, "width: ".concat(maxWidth, "px"));
134
+ }
135
+
136
+ if (metric) {
137
+ this.mScale = _l7Utils.DOM.create('div', 'l7-control-scale-line', container);
138
+ }
139
+
140
+ if (imperial) {
141
+ this.iScale = _l7Utils.DOM.create('div', 'l7-control-scale-line', container);
142
+ }
143
+
144
+ this.update();
145
+ }
146
+ }, {
147
+ key: "updateScale",
148
+ value: function updateScale(scale, text, ratio) {
149
+ var maxWidth = this.controlOption.maxWidth;
150
+ scale.style.width = Math.round(maxWidth * ratio) + 'px';
151
+ scale.innerHTML = text;
152
+ }
153
+ }, {
154
+ key: "getRoundNum",
155
+ value: function getRoundNum(num) {
156
+ var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1);
157
+ var d = num / pow10;
158
+ d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
159
+ return pow10 * d;
160
+ }
111
161
  }, {
112
162
  key: "updateMetric",
113
163
  value: function updateMetric(maxMeters) {
@@ -132,38 +182,8 @@ var Scale = /*#__PURE__*/function (_Control) {
132
182
  this.updateScale(this.iScale, feet + ' ft', feet / maxFeet);
133
183
  }
134
184
  }
135
- }, {
136
- key: "updateScale",
137
- value: function updateScale(scale, text, ratio) {
138
- var maxWidth = this.controlOption.maxWidth;
139
- scale.style.width = Math.round(maxWidth * ratio) + 'px';
140
- scale.innerHTML = text;
141
- }
142
- }, {
143
- key: "getRoundNum",
144
- value: function getRoundNum(num) {
145
- var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1);
146
- var d = num / pow10;
147
- d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
148
- return pow10 * d;
149
- }
150
- }, {
151
- key: "addScales",
152
- value: function addScales(className, container) {
153
- var _this$controlOption2 = this.controlOption,
154
- metric = _this$controlOption2.metric,
155
- imperial = _this$controlOption2.imperial;
156
-
157
- if (metric) {
158
- this.mScale = _l7Utils.DOM.create('div', className, container);
159
- }
160
-
161
- if (imperial) {
162
- this.iScale = _l7Utils.DOM.create('div', className, container);
163
- }
164
- }
165
185
  }]);
166
186
  return Scale;
167
- }(_BaseControl.default);
187
+ }(_baseControl.Control);
168
188
 
169
- exports.default = Scale;
189
+ exports.default = exports.Scale = Scale;