@antv/l7-component 2.5.37-mini3 → 2.5.40
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/CHANGELOG.md +325 -0
- package/LICENSE.md +21 -0
- package/es/control/BaseControl.d.ts +27 -0
- package/es/control/BaseControl.js +155 -0
- package/es/control/BaseControl.js.map +1 -0
- package/es/control/layer.d.ts +44 -0
- package/es/control/layer.js +355 -0
- package/es/control/layer.js.map +1 -0
- package/es/control/logo.d.ts +9 -0
- package/es/control/logo.js +58 -0
- package/es/control/logo.js.map +1 -0
- package/es/control/scale.d.ts +30 -0
- package/es/control/scale.js +153 -0
- package/es/control/scale.js.map +1 -0
- package/es/control/zoom.d.ts +30 -0
- package/es/control/zoom.js +128 -0
- package/es/control/zoom.js.map +1 -0
- package/es/index.d.ts +10 -0
- package/es/index.js +52 -0
- package/es/index.js.map +1 -0
- package/es/marker.d.ts +47 -0
- package/es/marker.js +427 -0
- package/es/marker.js.map +1 -0
- package/es/markerlayer.d.ts +68 -0
- package/es/markerlayer.js +309 -0
- package/es/markerlayer.js.map +1 -0
- package/es/popup.d.ts +35 -0
- package/es/popup.js +316 -0
- package/es/popup.js.map +1 -0
- package/es/utils/anchor.d.ts +22 -0
- package/es/utils/anchor.js +36 -0
- package/es/utils/anchor.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
|
|
9
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
+
|
|
11
|
+
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; } }
|
|
12
|
+
|
|
13
|
+
import { PositionType } from '@antv/l7-core';
|
|
14
|
+
import { bindAll, DOM } from '@antv/l7-utils';
|
|
15
|
+
import Control from './BaseControl';
|
|
16
|
+
|
|
17
|
+
var Layers = function (_Control) {
|
|
18
|
+
_inherits(Layers, _Control);
|
|
19
|
+
|
|
20
|
+
var _super = _createSuper(Layers);
|
|
21
|
+
|
|
22
|
+
function Layers(cfg) {
|
|
23
|
+
var _this;
|
|
24
|
+
|
|
25
|
+
_classCallCheck(this, Layers);
|
|
26
|
+
|
|
27
|
+
_this = _super.call(this, cfg);
|
|
28
|
+
|
|
29
|
+
_defineProperty(_assertThisInitialized(_this), "layerControlInputs", void 0);
|
|
30
|
+
|
|
31
|
+
_defineProperty(_assertThisInitialized(_this), "layers", void 0);
|
|
32
|
+
|
|
33
|
+
_defineProperty(_assertThisInitialized(_this), "lastZIndex", void 0);
|
|
34
|
+
|
|
35
|
+
_defineProperty(_assertThisInitialized(_this), "handlingClick", void 0);
|
|
36
|
+
|
|
37
|
+
_defineProperty(_assertThisInitialized(_this), "layersLink", void 0);
|
|
38
|
+
|
|
39
|
+
_defineProperty(_assertThisInitialized(_this), "baseLayersList", void 0);
|
|
40
|
+
|
|
41
|
+
_defineProperty(_assertThisInitialized(_this), "separator", void 0);
|
|
42
|
+
|
|
43
|
+
_defineProperty(_assertThisInitialized(_this), "overlaysList", void 0);
|
|
44
|
+
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "form", void 0);
|
|
46
|
+
|
|
47
|
+
_this.layerControlInputs = [];
|
|
48
|
+
_this.layers = [];
|
|
49
|
+
_this.lastZIndex = 0;
|
|
50
|
+
_this.handlingClick = false;
|
|
51
|
+
|
|
52
|
+
_this.initLayers();
|
|
53
|
+
|
|
54
|
+
bindAll(['checkDisabledLayers', 'onLayerChange', 'collapse', 'extend', 'expand', 'onInputClick'], _assertThisInitialized(_this));
|
|
55
|
+
return _this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_createClass(Layers, [{
|
|
59
|
+
key: "getDefault",
|
|
60
|
+
value: function getDefault() {
|
|
61
|
+
return {
|
|
62
|
+
collapsed: true,
|
|
63
|
+
position: PositionType.TOPRIGHT,
|
|
64
|
+
autoZIndex: true,
|
|
65
|
+
hideSingleBase: false,
|
|
66
|
+
sortLayers: false,
|
|
67
|
+
name: 'layers'
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "onAdd",
|
|
72
|
+
value: function onAdd() {
|
|
73
|
+
var _this2 = this;
|
|
74
|
+
|
|
75
|
+
this.initLayout();
|
|
76
|
+
this.update();
|
|
77
|
+
this.mapsService.on('zoomend', this.checkDisabledLayers);
|
|
78
|
+
this.layers.forEach(function (layerItem) {
|
|
79
|
+
layerItem.layer.on('remove', _this2.onLayerChange);
|
|
80
|
+
layerItem.layer.on('add', _this2.onLayerChange);
|
|
81
|
+
});
|
|
82
|
+
return this.container;
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "addVisualLayer",
|
|
86
|
+
value: function addVisualLayer(layer, name) {
|
|
87
|
+
this.addLayer(layer, name, true);
|
|
88
|
+
return this.mapsService ? this.update() : this;
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "expand",
|
|
92
|
+
value: function expand() {
|
|
93
|
+
var _this$renderService$g = this.renderService.getViewportSize(),
|
|
94
|
+
height = _this$renderService$g.height;
|
|
95
|
+
|
|
96
|
+
DOM.addClass(this.container, 'l7-control-layers-expanded');
|
|
97
|
+
this.form.style.height = 'null';
|
|
98
|
+
var acceptableHeight = height - (this.container.offsetTop + 50);
|
|
99
|
+
|
|
100
|
+
if (acceptableHeight < this.form.clientHeight) {
|
|
101
|
+
DOM.addClass(this.form, 'l7-control-layers-scrollbar');
|
|
102
|
+
this.form.style.height = acceptableHeight + 'px';
|
|
103
|
+
} else {
|
|
104
|
+
DOM.removeClass(this.form, 'l7-control-layers-scrollbar');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.checkDisabledLayers();
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "collapse",
|
|
112
|
+
value: function collapse() {
|
|
113
|
+
DOM.removeClass(this.container, 'l7-control-layers-expanded');
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
key: "onRemove",
|
|
118
|
+
value: function onRemove() {
|
|
119
|
+
var _this3 = this;
|
|
120
|
+
|
|
121
|
+
if (!this.mapsService) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.mapsService.off('click', this.collapse);
|
|
126
|
+
this.layers.forEach(function (layerItem) {
|
|
127
|
+
layerItem.layer.off('remove', _this3.onLayerChange);
|
|
128
|
+
layerItem.layer.off('add', _this3.onLayerChange);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}, {
|
|
132
|
+
key: "initLayout",
|
|
133
|
+
value: function initLayout() {
|
|
134
|
+
var className = 'l7-control-layers';
|
|
135
|
+
var container = this.container = DOM.create('div', className);
|
|
136
|
+
var collapsed = this.controlOption.collapsed;
|
|
137
|
+
container.setAttribute('aria-haspopup', 'true');
|
|
138
|
+
var form = this.form = DOM.create('form', className + '-list');
|
|
139
|
+
|
|
140
|
+
if (collapsed) {
|
|
141
|
+
this.mapsService.on('click', this.collapse);
|
|
142
|
+
container.addEventListener('mouseenter', this.expand);
|
|
143
|
+
container.addEventListener('mouseleave', this.collapse);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this.layersLink = DOM.create('a', className + '-toggle', container);
|
|
147
|
+
var link = this.layersLink;
|
|
148
|
+
link.title = 'Layers';
|
|
149
|
+
|
|
150
|
+
if (!collapsed) {
|
|
151
|
+
this.expand();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.baseLayersList = DOM.create('div', className + '-base', form);
|
|
155
|
+
this.separator = DOM.create('div', className + '-separator', form);
|
|
156
|
+
this.overlaysList = DOM.create('div', className + '-overlays', form);
|
|
157
|
+
container.appendChild(form);
|
|
158
|
+
}
|
|
159
|
+
}, {
|
|
160
|
+
key: "initLayers",
|
|
161
|
+
value: function initLayers() {
|
|
162
|
+
var _this4 = this;
|
|
163
|
+
|
|
164
|
+
var _this$controlOption = this.controlOption,
|
|
165
|
+
_this$controlOption$b = _this$controlOption.baseLayers,
|
|
166
|
+
baseLayers = _this$controlOption$b === void 0 ? {} : _this$controlOption$b,
|
|
167
|
+
_this$controlOption$o = _this$controlOption.overlayers,
|
|
168
|
+
overlayers = _this$controlOption$o === void 0 ? {} : _this$controlOption$o;
|
|
169
|
+
Object.keys(baseLayers).forEach(function (name, index) {
|
|
170
|
+
_this4.addLayer(baseLayers[name], name, false);
|
|
171
|
+
});
|
|
172
|
+
Object.keys(overlayers).forEach(function (name, index) {
|
|
173
|
+
_this4.addLayer(overlayers[name], name, true);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}, {
|
|
177
|
+
key: "update",
|
|
178
|
+
value: function update() {
|
|
179
|
+
if (!this.container) {
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
DOM.empty(this.baseLayersList);
|
|
184
|
+
DOM.empty(this.overlaysList);
|
|
185
|
+
this.layerControlInputs = [];
|
|
186
|
+
var baseLayersPresent;
|
|
187
|
+
var overlaysPresent;
|
|
188
|
+
var i;
|
|
189
|
+
var obj;
|
|
190
|
+
var baseLayersCount = 0;
|
|
191
|
+
|
|
192
|
+
for (i = 0; i < this.layers.length; i++) {
|
|
193
|
+
obj = this.layers[i];
|
|
194
|
+
this.addItem(obj);
|
|
195
|
+
overlaysPresent = overlaysPresent || obj.overlay;
|
|
196
|
+
baseLayersPresent = baseLayersPresent || !obj.overlay;
|
|
197
|
+
baseLayersCount += !obj.overlay ? 1 : 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (this.controlOption.hideSingleBase) {
|
|
201
|
+
baseLayersPresent = baseLayersPresent && baseLayersCount > 1;
|
|
202
|
+
this.baseLayersList.style.display = baseLayersPresent ? '' : 'none';
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
this.separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
}, {
|
|
209
|
+
key: "checkDisabledLayers",
|
|
210
|
+
value: function checkDisabledLayers() {
|
|
211
|
+
var inputs = this.layerControlInputs;
|
|
212
|
+
var input;
|
|
213
|
+
var layer;
|
|
214
|
+
var zoom = this.mapsService.getZoom();
|
|
215
|
+
|
|
216
|
+
for (var i = inputs.length - 1; i >= 0; i--) {
|
|
217
|
+
input = inputs[i];
|
|
218
|
+
layer = this.layerService.getLayer(input.layerId);
|
|
219
|
+
|
|
220
|
+
if (layer && layer.inited) {
|
|
221
|
+
var minZoom = layer.getMinZoom();
|
|
222
|
+
var maxZoom = layer.getMaxZoom();
|
|
223
|
+
input.disabled = zoom < minZoom || zoom > maxZoom;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
key: "addLayer",
|
|
229
|
+
value: function addLayer(layer, name, overlay) {
|
|
230
|
+
if (this.mapsService) {
|
|
231
|
+
layer.on('add', this.onLayerChange);
|
|
232
|
+
layer.on('remove', this.onLayerChange);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
this.layers.push({
|
|
236
|
+
layer: layer,
|
|
237
|
+
name: name,
|
|
238
|
+
overlay: overlay
|
|
239
|
+
});
|
|
240
|
+
var _this$controlOption2 = this.controlOption,
|
|
241
|
+
sortLayers = _this$controlOption2.sortLayers,
|
|
242
|
+
sortFunction = _this$controlOption2.sortFunction,
|
|
243
|
+
autoZIndex = _this$controlOption2.autoZIndex;
|
|
244
|
+
|
|
245
|
+
if (sortLayers) {
|
|
246
|
+
this.layers.sort(function (a, b) {
|
|
247
|
+
return sortFunction(a.layer, b.layer, a.name, b.name);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (autoZIndex && layer.setZIndex) {
|
|
252
|
+
this.lastZIndex++;
|
|
253
|
+
layer.setZIndex(this.lastZIndex);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
this.expandIfNotCollapsed();
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "expandIfNotCollapsed",
|
|
260
|
+
value: function expandIfNotCollapsed() {
|
|
261
|
+
if (this.mapsService && !this.controlOption.collapsed) {
|
|
262
|
+
this.expand();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
}, {
|
|
268
|
+
key: "onLayerChange",
|
|
269
|
+
value: function onLayerChange(e) {
|
|
270
|
+
if (!this.handlingClick) {
|
|
271
|
+
this.update();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
var obj = this.layerService.getLayer(e.target.layerId);
|
|
275
|
+
var type = obj !== null && obj !== void 0 && obj.overlay ? e.type === 'add' ? 'overlayadd' : 'overlayremove' : e.type === 'add' ? 'baselayerchange' : null;
|
|
276
|
+
|
|
277
|
+
if (type) {
|
|
278
|
+
this.emit(type, obj);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}, {
|
|
282
|
+
key: "createRadioElement",
|
|
283
|
+
value: function createRadioElement(name, checked) {
|
|
284
|
+
var radioHtml = '<input type="radio" class="l7-control-layers-selector" name="' + name + '"' + (checked ? ' checked="checked"' : '') + '/>';
|
|
285
|
+
var radioFragment = document.createElement('div');
|
|
286
|
+
radioFragment.innerHTML = radioHtml;
|
|
287
|
+
return radioFragment.firstChild;
|
|
288
|
+
}
|
|
289
|
+
}, {
|
|
290
|
+
key: "addItem",
|
|
291
|
+
value: function addItem(obj) {
|
|
292
|
+
var label = document.createElement('label');
|
|
293
|
+
var layer = this.layerService.getLayer(obj.layer.id);
|
|
294
|
+
var checked = layer && layer.inited && obj.layer.isVisible();
|
|
295
|
+
var input;
|
|
296
|
+
|
|
297
|
+
if (obj.overlay) {
|
|
298
|
+
input = document.createElement('input');
|
|
299
|
+
input.type = 'checkbox';
|
|
300
|
+
input.className = 'l7-control-layers-selector';
|
|
301
|
+
input.defaultChecked = checked;
|
|
302
|
+
} else {
|
|
303
|
+
input = this.createRadioElement('l7-base-layers', checked);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
this.layerControlInputs.push(input);
|
|
307
|
+
input.layerId = obj.layer.id;
|
|
308
|
+
input.addEventListener('click', this.onInputClick);
|
|
309
|
+
var name = document.createElement('span');
|
|
310
|
+
name.innerHTML = ' ' + obj.name;
|
|
311
|
+
var holder = document.createElement('div');
|
|
312
|
+
label.appendChild(holder);
|
|
313
|
+
holder.appendChild(input);
|
|
314
|
+
holder.appendChild(name);
|
|
315
|
+
var container = obj.overlay ? this.overlaysList : this.baseLayersList;
|
|
316
|
+
container.appendChild(label);
|
|
317
|
+
this.checkDisabledLayers();
|
|
318
|
+
return label;
|
|
319
|
+
}
|
|
320
|
+
}, {
|
|
321
|
+
key: "onInputClick",
|
|
322
|
+
value: function onInputClick() {
|
|
323
|
+
var inputs = this.layerControlInputs;
|
|
324
|
+
var input;
|
|
325
|
+
var layer;
|
|
326
|
+
var addedLayers = [];
|
|
327
|
+
var removedLayers = [];
|
|
328
|
+
this.handlingClick = true;
|
|
329
|
+
|
|
330
|
+
for (var i = inputs.length - 1; i >= 0; i--) {
|
|
331
|
+
input = inputs[i];
|
|
332
|
+
layer = this.layerService.getLayer(input.layerId);
|
|
333
|
+
|
|
334
|
+
if (input.checked) {
|
|
335
|
+
addedLayers.push(layer);
|
|
336
|
+
} else if (!input.checked) {
|
|
337
|
+
removedLayers.push(layer);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
removedLayers.forEach(function (l) {
|
|
342
|
+
l.hide();
|
|
343
|
+
});
|
|
344
|
+
addedLayers.forEach(function (l) {
|
|
345
|
+
l.show();
|
|
346
|
+
});
|
|
347
|
+
this.handlingClick = false;
|
|
348
|
+
}
|
|
349
|
+
}]);
|
|
350
|
+
|
|
351
|
+
return Layers;
|
|
352
|
+
}(Control);
|
|
353
|
+
|
|
354
|
+
export { Layers as default };
|
|
355
|
+
//# sourceMappingURL=layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/control/layer.ts"],"names":["PositionType","bindAll","DOM","Control","Layers","cfg","layerControlInputs","layers","lastZIndex","handlingClick","initLayers","collapsed","position","TOPRIGHT","autoZIndex","hideSingleBase","sortLayers","name","initLayout","update","mapsService","on","checkDisabledLayers","forEach","layerItem","layer","onLayerChange","container","addLayer","renderService","getViewportSize","height","addClass","form","style","acceptableHeight","offsetTop","clientHeight","removeClass","off","collapse","className","create","controlOption","setAttribute","addEventListener","expand","layersLink","link","title","baseLayersList","separator","overlaysList","appendChild","baseLayers","overlayers","Object","keys","index","empty","baseLayersPresent","overlaysPresent","i","obj","baseLayersCount","length","addItem","overlay","display","inputs","input","zoom","getZoom","layerService","getLayer","layerId","inited","minZoom","getMinZoom","maxZoom","getMaxZoom","disabled","push","sortFunction","sort","a","b","setZIndex","expandIfNotCollapsed","e","target","type","emit","checked","radioHtml","radioFragment","document","createElement","innerHTML","firstChild","label","id","isVisible","defaultChecked","createRadioElement","onInputClick","holder","addedLayers","removedLayers","l","hide","show"],"mappings":";;;;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A,KAAK,GAAGD,MAAM,CAACP,CAAD,CAAd;AACArC,QAAAA,KAAK,GAAG,KAAKgD,YAAL,CAAkBC,QAAlB,CAA2BJ,KAAK,CAACK,OAAjC,CAAR;;AACA,YAAIL,KAAK,CAACuB,OAAV,EAAmB;AACjBc,UAAAA,WAAW,CAACzB,IAAZ,CAAiBzD,KAAjB;AACD,SAFD,MAEO,IAAI,CAAC6C,KAAK,CAACuB,OAAX,EAAoB;AACzBe,UAAAA,aAAa,CAAC1B,IAAd,CAAmBzD,KAAnB;AACD;AACF;;AACDmF,MAAAA,aAAa,CAACrF,OAAd,CAAsB,UAACsF,CAAD,EAAY;AAChCA,QAAAA,CAAC,CAACC,IAAF;AACD,OAFD;AAGAH,MAAAA,WAAW,CAACpF,OAAZ,CAAoB,UAACsF,CAAD,EAAY;AAC9BA,QAAAA,CAAC,CAACE,IAAF;AACD,OAFD;AAIA,WAAKtG,aAAL,GAAqB,KAArB;AACD;;;;EAlTiCN,O;;SAAfC,M","sourcesContent":["import { IControlOption, PositionName, PositionType } from '@antv/l7-core';\nimport { bindAll, DOM, lnglatDistance } from '@antv/l7-utils';\nimport Control from './BaseControl';\nexport interface ILayerControlOption extends IControlOption {\n collapsed: boolean;\n autoZIndex: boolean;\n hideSingleBase: boolean;\n sortLayers: boolean;\n\n sortFunction: (...args: any[]) => any;\n}\ninterface IInputItem extends HTMLInputElement {\n layerId: string;\n}\nexport default class Layers extends Control {\n private layerControlInputs: any[];\n private layers: any[];\n private lastZIndex: number;\n private handlingClick: boolean;\n private layersLink: HTMLElement;\n private baseLayersList: HTMLElement;\n private separator: HTMLElement;\n private overlaysList: HTMLElement;\n private form: HTMLElement;\n\n constructor(cfg: Partial<ILayerControlOption>) {\n super(cfg);\n this.layerControlInputs = [];\n this.layers = [];\n this.lastZIndex = 0;\n this.handlingClick = false;\n this.initLayers();\n\n bindAll(\n [\n 'checkDisabledLayers',\n 'onLayerChange',\n 'collapse',\n 'extend',\n 'expand',\n 'onInputClick',\n ],\n this,\n );\n }\n\n public getDefault() {\n return {\n collapsed: true,\n position: PositionType.TOPRIGHT,\n autoZIndex: true,\n hideSingleBase: false,\n sortLayers: false,\n name: 'layers',\n };\n }\n public onAdd() {\n this.initLayout();\n this.update();\n this.mapsService.on('zoomend', this.checkDisabledLayers);\n this.layers.forEach((layerItem) => {\n layerItem.layer.on('remove', this.onLayerChange);\n layerItem.layer.on('add', this.onLayerChange);\n });\n return this.container;\n }\n\n public addVisualLayer(layer: any, name: string | number) {\n this.addLayer(layer, name, true);\n return this.mapsService ? this.update() : this;\n }\n public expand() {\n const { height } = this.renderService.getViewportSize();\n DOM.addClass(this.container, 'l7-control-layers-expanded');\n this.form.style.height = 'null';\n const acceptableHeight = height - (this.container.offsetTop + 50);\n if (acceptableHeight < this.form.clientHeight) {\n DOM.addClass(this.form, 'l7-control-layers-scrollbar');\n this.form.style.height = acceptableHeight + 'px';\n } else {\n DOM.removeClass(this.form, 'l7-control-layers-scrollbar');\n }\n this.checkDisabledLayers();\n return this;\n }\n\n public collapse() {\n DOM.removeClass(this.container, 'l7-control-layers-expanded');\n return this;\n }\n\n public onRemove() {\n if (!this.mapsService) {\n return;\n }\n this.mapsService.off('click', this.collapse);\n this.layers.forEach((layerItem) => {\n layerItem.layer.off('remove', this.onLayerChange);\n layerItem.layer.off('add', this.onLayerChange);\n });\n }\n private initLayout() {\n const className = 'l7-control-layers';\n const container = (this.container = DOM.create('div', className));\n const { collapsed } = this.controlOption;\n // makes this work on IE touch devices by stopping it from firing a mouseout event when the touch is released\n container.setAttribute('aria-haspopup', 'true');\n const form = (this.form = DOM.create(\n 'form',\n className + '-list',\n ) as HTMLElement);\n\n if (collapsed) {\n this.mapsService.on('click', this.collapse);\n container.addEventListener('mouseenter', this.expand);\n container.addEventListener('mouseleave', this.collapse);\n }\n\n this.layersLink = DOM.create('a', className + '-toggle', container);\n const link = this.layersLink;\n // link.href = '#';\n link.title = 'Layers';\n if (!collapsed) {\n this.expand();\n }\n this.baseLayersList = DOM.create('div', className + '-base', form);\n this.separator = DOM.create('div', className + '-separator', form);\n this.overlaysList = DOM.create('div', className + '-overlays', form);\n container.appendChild(form);\n }\n private initLayers() {\n const { baseLayers = {}, overlayers = {} } = this.controlOption;\n Object.keys(baseLayers).forEach((name: string, index: number) => {\n // baseLayers[name].once('inited', this.update);\n this.addLayer(baseLayers[name], name, false);\n });\n Object.keys(overlayers).forEach((name: any, index: number) => {\n // overlayers[name].once('inited', this.update);\n this.addLayer(overlayers[name], name, true);\n });\n }\n\n private update() {\n if (!this.container) {\n return this;\n }\n\n DOM.empty(this.baseLayersList);\n DOM.empty(this.overlaysList);\n\n this.layerControlInputs = [];\n let baseLayersPresent;\n let overlaysPresent;\n let i;\n let obj;\n let baseLayersCount = 0;\n\n for (i = 0; i < this.layers.length; i++) {\n obj = this.layers[i];\n this.addItem(obj);\n overlaysPresent = overlaysPresent || obj.overlay;\n baseLayersPresent = baseLayersPresent || !obj.overlay;\n baseLayersCount += !obj.overlay ? 1 : 0;\n }\n\n // Hide base layers section if there's only one layer.\n if (this.controlOption.hideSingleBase) {\n baseLayersPresent = baseLayersPresent && baseLayersCount > 1;\n this.baseLayersList.style.display = baseLayersPresent ? '' : 'none';\n }\n\n this.separator.style.display =\n overlaysPresent && baseLayersPresent ? '' : 'none';\n\n return this;\n }\n\n private checkDisabledLayers() {\n const inputs = this.layerControlInputs;\n let input: IInputItem;\n let layer;\n const zoom = this.mapsService.getZoom();\n\n for (let i = inputs.length - 1; i >= 0; i--) {\n input = inputs[i];\n layer = this.layerService.getLayer(input.layerId);\n\n if (layer && layer.inited) {\n const minZoom = layer.getMinZoom();\n const maxZoom = layer.getMaxZoom();\n\n input.disabled = zoom < minZoom || zoom > maxZoom;\n }\n }\n }\n\n private addLayer(layer: any, name: string | number, overlay: boolean) {\n if (this.mapsService) {\n layer.on('add', this.onLayerChange);\n layer.on('remove', this.onLayerChange);\n }\n this.layers.push({\n layer,\n name,\n overlay,\n });\n const { sortLayers, sortFunction, autoZIndex } = this.controlOption;\n if (sortLayers) {\n this.layers.sort((a, b) => {\n return sortFunction(a.layer, b.layer, a.name, b.name);\n });\n }\n\n if (autoZIndex && layer.setZIndex) {\n this.lastZIndex++;\n layer.setZIndex(this.lastZIndex);\n }\n\n this.expandIfNotCollapsed();\n }\n\n private expandIfNotCollapsed() {\n if (this.mapsService && !this.controlOption.collapsed) {\n this.expand();\n }\n return this;\n }\n\n private onLayerChange(e: any) {\n if (!this.handlingClick) {\n this.update();\n }\n\n const obj = this.layerService.getLayer(e.target.layerId);\n\n // @ts-ignore\n const type = obj?.overlay\n ? e.type === 'add'\n ? 'overlayadd'\n : 'overlayremove'\n : e.type === 'add'\n ? 'baselayerchange'\n : null;\n\n if (type) {\n this.emit(type, obj);\n }\n }\n\n private createRadioElement(name: string, checked: boolean): ChildNode {\n const radioHtml =\n '<input type=\"radio\" class=\"l7-control-layers-selector\" name=\"' +\n name +\n '\"' +\n (checked ? ' checked=\"checked\"' : '') +\n '/>';\n\n const radioFragment = document.createElement('div');\n radioFragment.innerHTML = radioHtml;\n\n return radioFragment.firstChild as ChildNode;\n }\n\n private addItem(obj: any) {\n const label = document.createElement('label');\n const layer = this.layerService.getLayer(obj.layer.id);\n const checked = layer && layer.inited && obj.layer.isVisible();\n let input: IInputItem;\n if (obj.overlay) {\n input = document.createElement('input') as IInputItem;\n input.type = 'checkbox';\n input.className = 'l7-control-layers-selector';\n input.defaultChecked = checked;\n } else {\n input = this.createRadioElement('l7-base-layers', checked) as IInputItem;\n }\n this.layerControlInputs.push(input);\n input.layerId = obj.layer.id;\n input.addEventListener('click', this.onInputClick);\n\n const name = document.createElement('span');\n name.innerHTML = ' ' + obj.name;\n\n const holder = document.createElement('div');\n\n label.appendChild(holder);\n holder.appendChild(input);\n holder.appendChild(name);\n\n const container = obj.overlay ? this.overlaysList : this.baseLayersList;\n container.appendChild(label);\n\n this.checkDisabledLayers();\n return label;\n }\n\n private onInputClick() {\n const inputs = this.layerControlInputs;\n let input;\n let layer;\n const addedLayers = [];\n const removedLayers = [];\n this.handlingClick = true;\n for (let i = inputs.length - 1; i >= 0; i--) {\n input = inputs[i];\n layer = this.layerService.getLayer(input.layerId);\n if (input.checked) {\n addedLayers.push(layer);\n } else if (!input.checked) {\n removedLayers.push(layer);\n }\n }\n removedLayers.forEach((l: any) => {\n l.hide();\n });\n addedLayers.forEach((l: any) => {\n l.show();\n });\n\n this.handlingClick = false;\n }\n}\n"],"file":"layer.js"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
|
|
7
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
+
|
|
9
|
+
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; } }
|
|
10
|
+
|
|
11
|
+
import { DOM } from '@antv/l7-utils';
|
|
12
|
+
import Control, { PositionType } from './BaseControl';
|
|
13
|
+
|
|
14
|
+
var Logo = function (_Control) {
|
|
15
|
+
_inherits(Logo, _Control);
|
|
16
|
+
|
|
17
|
+
var _super = _createSuper(Logo);
|
|
18
|
+
|
|
19
|
+
function Logo() {
|
|
20
|
+
_classCallCheck(this, Logo);
|
|
21
|
+
|
|
22
|
+
return _super.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
_createClass(Logo, [{
|
|
26
|
+
key: "getDefault",
|
|
27
|
+
value: function getDefault() {
|
|
28
|
+
return {
|
|
29
|
+
position: PositionType.BOTTOMLEFT,
|
|
30
|
+
name: 'logo'
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "onAdd",
|
|
35
|
+
value: function onAdd() {
|
|
36
|
+
var className = 'l7-control-logo';
|
|
37
|
+
var container = DOM.create('div', className);
|
|
38
|
+
var anchor = DOM.create('a', 'l7-ctrl-logo');
|
|
39
|
+
anchor.target = '_blank';
|
|
40
|
+
anchor.rel = 'noopener nofollow';
|
|
41
|
+
anchor.href = 'https://antv.alipay.com/l7';
|
|
42
|
+
anchor.setAttribute('aria-label', 'AntV logo');
|
|
43
|
+
anchor.setAttribute('rel', 'noopener nofollow');
|
|
44
|
+
container.appendChild(anchor);
|
|
45
|
+
return container;
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
key: "onRemove",
|
|
49
|
+
value: function onRemove() {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}]);
|
|
53
|
+
|
|
54
|
+
return Logo;
|
|
55
|
+
}(Control);
|
|
56
|
+
|
|
57
|
+
export { Logo as default };
|
|
58
|
+
//# sourceMappingURL=logo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/control/logo.ts"],"names":["DOM","Control","PositionType","Logo","position","BOTTOMLEFT","name","className","container","create","anchor","target","rel","href","setAttribute","appendChild"],"mappings":";;;;;;;;;;AACA,SAASA,GAAT,QAAoB,gBAApB;AACA,OAAOC,OAAP,IAAkBC,YAAlB,QAAsC,eAAtC;;IACqBC,I;;;;;;;;;;;;;WACnB,sBAAoB;AAClB,aAAO;AACLC,QAAAA,QAAQ,EAAEF,YAAY,CAACG,UADlB;AAELC,QAAAA,IAAI,EAAE;AAFD,OAAP;AAID;;;WACD,iBAAe;AACb,UAAMC,SAAS,GAAG,iBAAlB;AACA,UAAMC,SAAS,GAAGR,GAAG,CAACS,MAAJ,CAAW,KAAX,EAAkBF,SAAlB,CAAlB;AACA,UAAMG,MAAuB,GAAGV,GAAG,CAACS,MAAJ,CAC9B,GAD8B,EAE9B,cAF8B,CAAhC;AAIAC,MAAAA,MAAM,CAACC,MAAP,GAAgB,QAAhB;AACAD,MAAAA,MAAM,CAACE,GAAP,GAAa,mBAAb;AACAF,MAAAA,MAAM,CAACG,IAAP,GAAc,4BAAd;AACAH,MAAAA,MAAM,CAACI,YAAP,CAAoB,YAApB,EAAkC,WAAlC;AACAJ,MAAAA,MAAM,CAACI,YAAP,CAAoB,KAApB,EAA2B,mBAA3B;AACAN,MAAAA,SAAS,CAACO,WAAV,CAAsBL,MAAtB;AACA,aAAOF,SAAP;AACD;;;WAED,oBAAkB;AAChB,aAAO,IAAP;AACD;;;;EAzB+BP,O;;SAAbE,I","sourcesContent":["import { IControlOption } from '@antv/l7-core';\nimport { DOM } from '@antv/l7-utils';\nimport Control, { PositionType } from './BaseControl';\nexport default class Logo extends Control {\n public getDefault() {\n return {\n position: PositionType.BOTTOMLEFT,\n name: 'logo',\n };\n }\n public onAdd() {\n const className = 'l7-control-logo';\n const container = DOM.create('div', className);\n const anchor: HTMLLinkElement = DOM.create(\n 'a',\n 'l7-ctrl-logo',\n ) as HTMLLinkElement;\n anchor.target = '_blank';\n anchor.rel = 'noopener nofollow';\n anchor.href = 'https://antv.alipay.com/l7';\n anchor.setAttribute('aria-label', 'AntV logo');\n anchor.setAttribute('rel', 'noopener nofollow');\n container.appendChild(anchor);\n return container;\n }\n\n public onRemove() {\n return null;\n }\n}\n"],"file":"logo.js"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IControlOption } from '@antv/l7-core';
|
|
2
|
+
import Control, { PositionType } from './BaseControl';
|
|
3
|
+
export interface IScaleControlOption extends IControlOption {
|
|
4
|
+
maxWidth: number;
|
|
5
|
+
metric: boolean;
|
|
6
|
+
updateWhenIdle: boolean;
|
|
7
|
+
imperial: boolean;
|
|
8
|
+
}
|
|
9
|
+
export default class Scale extends Control {
|
|
10
|
+
private mScale;
|
|
11
|
+
private iScale;
|
|
12
|
+
constructor(cfg?: Partial<IScaleControlOption>);
|
|
13
|
+
getDefault(): {
|
|
14
|
+
position: PositionType;
|
|
15
|
+
maxWidth: number;
|
|
16
|
+
metric: boolean;
|
|
17
|
+
updateWhenIdle: boolean;
|
|
18
|
+
imperial: boolean;
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
21
|
+
onAdd(): HTMLElement;
|
|
22
|
+
onRemove(): void;
|
|
23
|
+
update(): void;
|
|
24
|
+
updateScales(maxMeters: number): void;
|
|
25
|
+
private updateMetric;
|
|
26
|
+
private updateImperial;
|
|
27
|
+
private updateScale;
|
|
28
|
+
private getRoundNum;
|
|
29
|
+
private addScales;
|
|
30
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
|
|
9
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
+
|
|
11
|
+
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; } }
|
|
12
|
+
|
|
13
|
+
import { bindAll, DOM, lnglatDistance } from '@antv/l7-utils';
|
|
14
|
+
import Control, { PositionType } from './BaseControl';
|
|
15
|
+
|
|
16
|
+
var Scale = function (_Control) {
|
|
17
|
+
_inherits(Scale, _Control);
|
|
18
|
+
|
|
19
|
+
var _super = _createSuper(Scale);
|
|
20
|
+
|
|
21
|
+
function Scale(cfg) {
|
|
22
|
+
var _this;
|
|
23
|
+
|
|
24
|
+
_classCallCheck(this, Scale);
|
|
25
|
+
|
|
26
|
+
_this = _super.call(this, cfg);
|
|
27
|
+
|
|
28
|
+
_defineProperty(_assertThisInitialized(_this), "mScale", void 0);
|
|
29
|
+
|
|
30
|
+
_defineProperty(_assertThisInitialized(_this), "iScale", void 0);
|
|
31
|
+
|
|
32
|
+
bindAll(['update'], _assertThisInitialized(_this));
|
|
33
|
+
return _this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
_createClass(Scale, [{
|
|
37
|
+
key: "getDefault",
|
|
38
|
+
value: function getDefault() {
|
|
39
|
+
return {
|
|
40
|
+
position: PositionType.BOTTOMLEFT,
|
|
41
|
+
maxWidth: 100,
|
|
42
|
+
metric: true,
|
|
43
|
+
updateWhenIdle: false,
|
|
44
|
+
imperial: false,
|
|
45
|
+
name: 'scale'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
key: "onAdd",
|
|
50
|
+
value: function onAdd() {
|
|
51
|
+
var className = 'l7-control-scale';
|
|
52
|
+
var container = DOM.create('div', className);
|
|
53
|
+
this.addScales(className + '-line', container);
|
|
54
|
+
var updateWhenIdle = this.controlOption.updateWhenIdle;
|
|
55
|
+
this.mapsService.on(updateWhenIdle ? 'moveend' : 'mapmove', this.update);
|
|
56
|
+
this.mapsService.on(updateWhenIdle ? 'zoomend' : 'zoomchange', this.update);
|
|
57
|
+
this.update();
|
|
58
|
+
return container;
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "onRemove",
|
|
62
|
+
value: function onRemove() {
|
|
63
|
+
var updateWhenIdle = this.controlOption.updateWhenIdle;
|
|
64
|
+
this.mapsService.off(updateWhenIdle ? 'zoomend' : 'zoomchange', this.update);
|
|
65
|
+
this.mapsService.off(updateWhenIdle ? 'moveend' : 'mapmove', this.update);
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "update",
|
|
69
|
+
value: function update() {
|
|
70
|
+
var mapsService = this.mapsService;
|
|
71
|
+
var maxWidth = this.controlOption.maxWidth;
|
|
72
|
+
var y = mapsService.getSize()[1] / 2;
|
|
73
|
+
var p1 = mapsService.containerToLngLat([0, y]);
|
|
74
|
+
var p2 = mapsService.containerToLngLat([maxWidth, y]);
|
|
75
|
+
var maxMeters = lnglatDistance([p1.lng, p1.lat], [p2.lng, p2.lat]);
|
|
76
|
+
this.updateScales(maxMeters);
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: "updateScales",
|
|
80
|
+
value: function updateScales(maxMeters) {
|
|
81
|
+
var _this$controlOption = this.controlOption,
|
|
82
|
+
metric = _this$controlOption.metric,
|
|
83
|
+
imperial = _this$controlOption.imperial;
|
|
84
|
+
|
|
85
|
+
if (metric && maxMeters) {
|
|
86
|
+
this.updateMetric(maxMeters);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (imperial && maxMeters) {
|
|
90
|
+
this.updateImperial(maxMeters);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, {
|
|
94
|
+
key: "updateMetric",
|
|
95
|
+
value: function updateMetric(maxMeters) {
|
|
96
|
+
var meters = this.getRoundNum(maxMeters);
|
|
97
|
+
var label = meters < 1000 ? meters + ' m' : meters / 1000 + ' km';
|
|
98
|
+
this.updateScale(this.mScale, label, meters / maxMeters);
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "updateImperial",
|
|
102
|
+
value: function updateImperial(maxMeters) {
|
|
103
|
+
var maxFeet = maxMeters * 3.2808399;
|
|
104
|
+
var maxMiles;
|
|
105
|
+
var miles;
|
|
106
|
+
var feet;
|
|
107
|
+
|
|
108
|
+
if (maxFeet > 5280) {
|
|
109
|
+
maxMiles = maxFeet / 5280;
|
|
110
|
+
miles = this.getRoundNum(maxMiles);
|
|
111
|
+
this.updateScale(this.iScale, miles + ' mi', miles / maxMiles);
|
|
112
|
+
} else {
|
|
113
|
+
feet = this.getRoundNum(maxFeet);
|
|
114
|
+
this.updateScale(this.iScale, feet + ' ft', feet / maxFeet);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
key: "updateScale",
|
|
119
|
+
value: function updateScale(scale, text, ratio) {
|
|
120
|
+
var maxWidth = this.controlOption.maxWidth;
|
|
121
|
+
scale.style.width = Math.round(maxWidth * ratio) + 'px';
|
|
122
|
+
scale.innerHTML = text;
|
|
123
|
+
}
|
|
124
|
+
}, {
|
|
125
|
+
key: "getRoundNum",
|
|
126
|
+
value: function getRoundNum(num) {
|
|
127
|
+
var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1);
|
|
128
|
+
var d = num / pow10;
|
|
129
|
+
d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
|
|
130
|
+
return pow10 * d;
|
|
131
|
+
}
|
|
132
|
+
}, {
|
|
133
|
+
key: "addScales",
|
|
134
|
+
value: function addScales(className, container) {
|
|
135
|
+
var _this$controlOption2 = this.controlOption,
|
|
136
|
+
metric = _this$controlOption2.metric,
|
|
137
|
+
imperial = _this$controlOption2.imperial;
|
|
138
|
+
|
|
139
|
+
if (metric) {
|
|
140
|
+
this.mScale = DOM.create('div', className, container);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (imperial) {
|
|
144
|
+
this.iScale = DOM.create('div', className, container);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}]);
|
|
148
|
+
|
|
149
|
+
return Scale;
|
|
150
|
+
}(Control);
|
|
151
|
+
|
|
152
|
+
export { Scale as default };
|
|
153
|
+
//# sourceMappingURL=scale.js.map
|