@ohos-ports/jsvectormap 1.7.0-beta.0
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/LICENSE +21 -0
- package/dist/jsvectormap.cjs +2355 -0
- package/dist/jsvectormap.css +147 -0
- package/dist/jsvectormap.esm.js +2293 -0
- package/dist/jsvectormap.js +2301 -0
- package/dist/jsvectormap.min.css +1 -0
- package/dist/jsvectormap.min.js +1 -0
- package/dist/maps/world-merc.js +1 -0
- package/dist/maps/world.js +1 -0
- package/package.json +49 -0
- package/src/js/components/base.js +18 -0
- package/src/js/components/concerns/interactable.js +68 -0
- package/src/js/components/line.js +50 -0
- package/src/js/components/marker.js +109 -0
- package/src/js/components/region.js +53 -0
- package/src/js/components/route.js +76 -0
- package/src/js/components/tooltip.js +88 -0
- package/src/js/core/applyTransform.js +43 -0
- package/src/js/core/coordsToPoint.js +22 -0
- package/src/js/core/createLines.js +44 -0
- package/src/js/core/createMarkers.js +55 -0
- package/src/js/core/createRegions.js +23 -0
- package/src/js/core/createRoutes.js +16 -0
- package/src/js/core/createSeries.js +13 -0
- package/src/js/core/getInsetForPoint.js +13 -0
- package/src/js/core/getMarkerPosition.js +12 -0
- package/src/js/core/index.js +41 -0
- package/src/js/core/repositionLabels.js +21 -0
- package/src/js/core/repositionLines.js +30 -0
- package/src/js/core/repositionMarkers.js +11 -0
- package/src/js/core/resize.js +15 -0
- package/src/js/core/setFocus.js +46 -0
- package/src/js/core/setScale.js +65 -0
- package/src/js/core/setupContainerEvents.js +50 -0
- package/src/js/core/setupContainerTouchEvents.js +85 -0
- package/src/js/core/setupElementEvents.js +112 -0
- package/src/js/core/setupZoomButtons.js +40 -0
- package/src/js/core/updateSize.js +7 -0
- package/src/js/dataVisualization.js +87 -0
- package/src/js/defaults/events.js +11 -0
- package/src/js/defaults/options.js +90 -0
- package/src/js/eventHandler.js +47 -0
- package/src/js/index.js +25 -0
- package/src/js/legend.js +69 -0
- package/src/js/map.js +367 -0
- package/src/js/projection.js +127 -0
- package/src/js/scales/ordinalScale.js +21 -0
- package/src/js/series.js +68 -0
- package/src/js/svg/baseElement.js +53 -0
- package/src/js/svg/canvasElement.js +99 -0
- package/src/js/svg/imageElement.js +49 -0
- package/src/js/svg/shapeElement.js +48 -0
- package/src/js/svg/textElement.js +13 -0
- package/src/js/util/deepMerge.js +129 -0
- package/src/js/util/index.js +81 -0
- package/src/scss/_variables.scss +37 -0
- package/src/scss/jsvectormap.scss +153 -0
|
@@ -0,0 +1,2355 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DOM Polyfill for Node.js/HarmonyOS environment
|
|
5
|
+
* Provides minimal window/document/Node/Element stubs so the module
|
|
6
|
+
* can be required in a non-browser environment.
|
|
7
|
+
*/
|
|
8
|
+
(function () {
|
|
9
|
+
if (typeof global !== 'undefined') {
|
|
10
|
+
if (typeof global.window === 'undefined') {
|
|
11
|
+
global.window = {
|
|
12
|
+
addEventListener: function () {},
|
|
13
|
+
scrollX: 0,
|
|
14
|
+
scrollY: 0,
|
|
15
|
+
DocumentTouch: undefined
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (typeof global.document === 'undefined') {
|
|
19
|
+
var _stubEl = function () {
|
|
20
|
+
return {
|
|
21
|
+
nodeType: 1,
|
|
22
|
+
children: [],
|
|
23
|
+
classList: { add: function () {}, remove: function () {}, contains: function () { return false; } },
|
|
24
|
+
style: {},
|
|
25
|
+
appendChild: function (child) { this.children.push(child); return child; },
|
|
26
|
+
removeChild: function (child) { var i = this.children.indexOf(child); if (i >= 0) this.children.splice(i, 1); return child; },
|
|
27
|
+
querySelector: function () { return null; },
|
|
28
|
+
querySelectorAll: function () { return []; },
|
|
29
|
+
addEventListener: function () {},
|
|
30
|
+
removeEventListener: function () {},
|
|
31
|
+
setAttribute: function () {},
|
|
32
|
+
getAttribute: function () { return null; },
|
|
33
|
+
textContent: '',
|
|
34
|
+
innerHTML: '',
|
|
35
|
+
className: ''
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
global.document = {
|
|
39
|
+
readyState: 'complete',
|
|
40
|
+
body: _stubEl(),
|
|
41
|
+
documentElement: _stubEl(),
|
|
42
|
+
createElement: function (tag) { var el = _stubEl(); el.tagName = tag; return el; },
|
|
43
|
+
createElementNS: function (ns, tag) { var el = _stubEl(); el.tagName = tag; el.namespaceURI = ns; return el; },
|
|
44
|
+
createTextNode: function (text) { return { nodeType: 3, textContent: text }; },
|
|
45
|
+
querySelector: function () { return null; },
|
|
46
|
+
querySelectorAll: function () { return []; },
|
|
47
|
+
addEventListener: function () {},
|
|
48
|
+
removeEventListener: function () {}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (typeof global.Node === 'undefined') {
|
|
52
|
+
function Node() {}
|
|
53
|
+
global.Node = Node;
|
|
54
|
+
}
|
|
55
|
+
if (typeof global.Element === 'undefined') {
|
|
56
|
+
function Element() {}
|
|
57
|
+
Element.prototype = { querySelector: function () { return null; }, querySelectorAll: function () { return []; } };
|
|
58
|
+
global.Element = Element;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
})();
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* By https://github.com/TehShrike/deepmerge
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
var isMergeableObject = function isMergeableObject(value) {
|
|
68
|
+
return isNonNullObject(value) && !isSpecial(value);
|
|
69
|
+
};
|
|
70
|
+
function isNonNullObject(value) {
|
|
71
|
+
return !!value && typeof value === 'object';
|
|
72
|
+
}
|
|
73
|
+
function isSpecial(value) {
|
|
74
|
+
var stringValue = Object.prototype.toString.call(value);
|
|
75
|
+
return stringValue === '[object RegExp]' || stringValue === '[object Date]' || isNode(value) || isReactElement(value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25
|
|
79
|
+
var canUseSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
80
|
+
var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7;
|
|
81
|
+
function isReactElement(value) {
|
|
82
|
+
return value.$$typeof === REACT_ELEMENT_TYPE;
|
|
83
|
+
}
|
|
84
|
+
function isNode(value) {
|
|
85
|
+
return value instanceof Node;
|
|
86
|
+
}
|
|
87
|
+
function emptyTarget(val) {
|
|
88
|
+
return Array.isArray(val) ? [] : {};
|
|
89
|
+
}
|
|
90
|
+
function cloneUnlessOtherwiseSpecified(value, options) {
|
|
91
|
+
return options.clone !== false && options.isMergeableObject(value) ? deepmerge(emptyTarget(value), value, options) : value;
|
|
92
|
+
}
|
|
93
|
+
function defaultArrayMerge(target, source, options) {
|
|
94
|
+
return target.concat(source).map(function (element) {
|
|
95
|
+
return cloneUnlessOtherwiseSpecified(element, options);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function getMergeFunction(key, options) {
|
|
99
|
+
if (!options.customMerge) {
|
|
100
|
+
return deepmerge;
|
|
101
|
+
}
|
|
102
|
+
var customMerge = options.customMerge(key);
|
|
103
|
+
return typeof customMerge === 'function' ? customMerge : deepmerge;
|
|
104
|
+
}
|
|
105
|
+
function getEnumerableOwnPropertySymbols(target) {
|
|
106
|
+
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(function (symbol) {
|
|
107
|
+
return target.propertyIsEnumerable(symbol);
|
|
108
|
+
}) : [];
|
|
109
|
+
}
|
|
110
|
+
function getKeys(target) {
|
|
111
|
+
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
|
|
112
|
+
}
|
|
113
|
+
function propertyIsOnObject(object, property) {
|
|
114
|
+
try {
|
|
115
|
+
return property in object;
|
|
116
|
+
} catch (_) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Protects from prototype poisoning and unexpected merging up the prototype chain.
|
|
122
|
+
function propertyIsUnsafe(target, key) {
|
|
123
|
+
return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet,
|
|
124
|
+
&& !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain,
|
|
125
|
+
&& Object.propertyIsEnumerable.call(target, key)); // and also unsafe if they're nonenumerable.
|
|
126
|
+
}
|
|
127
|
+
function mergeObject(target, source, options) {
|
|
128
|
+
var destination = {};
|
|
129
|
+
if (options.isMergeableObject(target)) {
|
|
130
|
+
getKeys(target).forEach(function (key) {
|
|
131
|
+
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
getKeys(source).forEach(function (key) {
|
|
135
|
+
if (propertyIsUnsafe(target, key)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
|
|
139
|
+
destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
|
|
140
|
+
} else {
|
|
141
|
+
destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return destination;
|
|
145
|
+
}
|
|
146
|
+
var deepmerge = function deepmerge(target, source, options) {
|
|
147
|
+
options = options || {};
|
|
148
|
+
options.arrayMerge = options.arrayMerge || defaultArrayMerge;
|
|
149
|
+
options.isMergeableObject = options.isMergeableObject || isMergeableObject;
|
|
150
|
+
// cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()
|
|
151
|
+
// implementations can use it. The caller may not replace it.
|
|
152
|
+
options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;
|
|
153
|
+
var sourceIsArray = Array.isArray(source);
|
|
154
|
+
var targetIsArray = Array.isArray(target);
|
|
155
|
+
var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
|
|
156
|
+
if (!sourceAndTargetTypesMatch) {
|
|
157
|
+
return cloneUnlessOtherwiseSpecified(source, options);
|
|
158
|
+
} else if (sourceIsArray) {
|
|
159
|
+
return options.arrayMerge(target, source, options);
|
|
160
|
+
} else {
|
|
161
|
+
return mergeObject(target, source, options);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* --------------------------------------------------------------------------
|
|
167
|
+
* Public Util Api
|
|
168
|
+
* --------------------------------------------------------------------------
|
|
169
|
+
*/
|
|
170
|
+
var getElement = function getElement(selector) {
|
|
171
|
+
if (typeof selector === 'object' && typeof selector.nodeType !== 'undefined') {
|
|
172
|
+
return selector;
|
|
173
|
+
}
|
|
174
|
+
if (typeof selector === 'string') {
|
|
175
|
+
return document.querySelector(selector);
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
};
|
|
179
|
+
var createElement = function createElement(type, classes, content, html) {
|
|
180
|
+
if (html === void 0) {
|
|
181
|
+
html = false;
|
|
182
|
+
}
|
|
183
|
+
var el = document.createElement(type);
|
|
184
|
+
if (content) {
|
|
185
|
+
el[!html ? 'textContent' : 'innerHTML'] = content;
|
|
186
|
+
}
|
|
187
|
+
if (classes) {
|
|
188
|
+
el.className = classes;
|
|
189
|
+
}
|
|
190
|
+
return el;
|
|
191
|
+
};
|
|
192
|
+
var findElement = function findElement(parentElement, selector) {
|
|
193
|
+
return Element.prototype.querySelector.call(parentElement, selector);
|
|
194
|
+
};
|
|
195
|
+
var removeElement = function removeElement(target) {
|
|
196
|
+
target.parentNode.removeChild(target);
|
|
197
|
+
};
|
|
198
|
+
var isImageUrl = function isImageUrl(url) {
|
|
199
|
+
return /\.(jpg|gif|png)$/.test(url);
|
|
200
|
+
};
|
|
201
|
+
var hyphenate = function hyphenate(string) {
|
|
202
|
+
return string.replace(/[\w]([A-Z])/g, function (m) {
|
|
203
|
+
return m[0] + "-" + m[1];
|
|
204
|
+
}).toLowerCase();
|
|
205
|
+
};
|
|
206
|
+
var merge = function merge(target, source, deep) {
|
|
207
|
+
if (deep === void 0) {
|
|
208
|
+
deep = false;
|
|
209
|
+
}
|
|
210
|
+
if (deep) {
|
|
211
|
+
return deepmerge(target, source);
|
|
212
|
+
}
|
|
213
|
+
return Object.assign(target, source);
|
|
214
|
+
};
|
|
215
|
+
var getLineUid = function getLineUid(from, to) {
|
|
216
|
+
return from.toLowerCase() + ":to:" + to.toLowerCase();
|
|
217
|
+
};
|
|
218
|
+
var inherit = function inherit(target, source) {
|
|
219
|
+
Object.assign(target.prototype, source);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
var eventRegistry = {};
|
|
223
|
+
var eventUid = 1;
|
|
224
|
+
var EventHandler = {
|
|
225
|
+
on: function on(element, event, handler, options) {
|
|
226
|
+
if (options === void 0) {
|
|
227
|
+
options = {};
|
|
228
|
+
}
|
|
229
|
+
var uid = "jvm:" + event + "::" + eventUid++;
|
|
230
|
+
eventRegistry[uid] = {
|
|
231
|
+
selector: element,
|
|
232
|
+
handler: handler
|
|
233
|
+
};
|
|
234
|
+
handler._uid = uid;
|
|
235
|
+
element.addEventListener(event, handler, options);
|
|
236
|
+
},
|
|
237
|
+
delegate: function delegate(element, event, selector, handler) {
|
|
238
|
+
event = event.split(' ');
|
|
239
|
+
event.forEach(function (eventName) {
|
|
240
|
+
EventHandler.on(element, eventName, function (e) {
|
|
241
|
+
var target = e.target;
|
|
242
|
+
if (target.matches(selector)) {
|
|
243
|
+
handler.call(target, e);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
off: function off(element, event, handler) {
|
|
249
|
+
var eventType = event.split(':')[1];
|
|
250
|
+
element.removeEventListener(eventType, handler);
|
|
251
|
+
delete eventRegistry[handler._uid];
|
|
252
|
+
},
|
|
253
|
+
flush: function flush() {
|
|
254
|
+
Object.keys(eventRegistry).forEach(function (event) {
|
|
255
|
+
EventHandler.off(eventRegistry[event].selector, event, eventRegistry[event].handler);
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
getEventRegistry: function getEventRegistry() {
|
|
259
|
+
return eventRegistry;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
function setupContainerEvents() {
|
|
264
|
+
var _this = this;
|
|
265
|
+
var map = this;
|
|
266
|
+
var mouseDown = false;
|
|
267
|
+
var oldPageX;
|
|
268
|
+
var oldPageY;
|
|
269
|
+
if (this.params.draggable) {
|
|
270
|
+
EventHandler.on(this.container, 'mousemove', function (e) {
|
|
271
|
+
if (!mouseDown) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
map.transX -= (oldPageX - e.pageX) / map.scale;
|
|
275
|
+
map.transY -= (oldPageY - e.pageY) / map.scale;
|
|
276
|
+
map._applyTransform();
|
|
277
|
+
oldPageX = e.pageX;
|
|
278
|
+
oldPageY = e.pageY;
|
|
279
|
+
});
|
|
280
|
+
EventHandler.on(this.container, 'mousedown', function (e) {
|
|
281
|
+
mouseDown = true;
|
|
282
|
+
oldPageX = e.pageX;
|
|
283
|
+
oldPageY = e.pageY;
|
|
284
|
+
return false;
|
|
285
|
+
});
|
|
286
|
+
EventHandler.on(document.body, 'mouseup', function () {
|
|
287
|
+
mouseDown = false;
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
if (this.params.zoomOnScroll) {
|
|
291
|
+
EventHandler.on(this.container, 'wheel', function (event) {
|
|
292
|
+
var deltaY = ((event.deltaY || -event.wheelDelta || event.detail) >> 10 || 1) * 75;
|
|
293
|
+
var rect = _this.container.getBoundingClientRect();
|
|
294
|
+
var offsetX = event.pageX - rect.left - window.scrollX;
|
|
295
|
+
var offsetY = event.pageY - rect.top - window.scrollY;
|
|
296
|
+
var zoomStep = Math.pow(1 + map.params.zoomOnScrollSpeed / 1000, -1.5 * deltaY);
|
|
297
|
+
if (map.tooltip) {
|
|
298
|
+
map._tooltip.hide();
|
|
299
|
+
}
|
|
300
|
+
map._setScale(map.scale * zoomStep, offsetX, offsetY);
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
var Events = {
|
|
307
|
+
onLoaded: 'map:loaded',
|
|
308
|
+
onViewportChange: 'viewport:changed',
|
|
309
|
+
onRegionClick: 'region:clicked',
|
|
310
|
+
onMarkerClick: 'marker:clicked',
|
|
311
|
+
onRegionSelected: 'region:selected',
|
|
312
|
+
onMarkerSelected: 'marker:selected',
|
|
313
|
+
onRegionTooltipShow: 'region.tooltip:show',
|
|
314
|
+
onMarkerTooltipShow: 'marker.tooltip:show',
|
|
315
|
+
onDestroyed: 'map:destroyed'
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
var parseEvent = function parseEvent(map, selector, isTooltip) {
|
|
319
|
+
var element = getElement(selector);
|
|
320
|
+
var type = element.getAttribute('class').indexOf('jvm-region') === -1 ? 'marker' : 'region';
|
|
321
|
+
var isRegion = type === 'region';
|
|
322
|
+
var code = isRegion ? element.getAttribute('data-code') : element.getAttribute('data-index');
|
|
323
|
+
var event = isRegion ? Events.onRegionSelected : Events.onMarkerSelected;
|
|
324
|
+
|
|
325
|
+
// Init tooltip event
|
|
326
|
+
if (isTooltip) {
|
|
327
|
+
event = isRegion ? Events.onRegionTooltipShow : Events.onMarkerTooltipShow;
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
type: type,
|
|
331
|
+
code: code,
|
|
332
|
+
event: event,
|
|
333
|
+
element: isRegion ? map.regions[code].element : map._markers[code].element,
|
|
334
|
+
tooltipText: isRegion ? map._mapData.paths[code].name || '' : map._markers[code].config.name || ''
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
function setupElementEvents() {
|
|
338
|
+
var map = this;
|
|
339
|
+
var container = this.container;
|
|
340
|
+
var pageX, pageY, mouseMoved;
|
|
341
|
+
EventHandler.on(container, 'mousemove', function (event) {
|
|
342
|
+
if (Math.abs(pageX - event.pageX) + Math.abs(pageY - event.pageY) > 2) {
|
|
343
|
+
mouseMoved = true;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
// When the mouse is pressed
|
|
348
|
+
EventHandler.delegate(container, 'mousedown', '.jvm-element', function (event) {
|
|
349
|
+
pageX = event.pageX;
|
|
350
|
+
pageY = event.pageY;
|
|
351
|
+
mouseMoved = false;
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// When the mouse is over the region/marker | When the mouse is out the region/marker
|
|
355
|
+
EventHandler.delegate(container, 'mouseover mouseout', '.jvm-element', function (event) {
|
|
356
|
+
var data = parseEvent(map, this, true);
|
|
357
|
+
var showTooltip = map.params.showTooltip;
|
|
358
|
+
if (event.type === 'mouseover') {
|
|
359
|
+
data.element.hover(true);
|
|
360
|
+
if (showTooltip) {
|
|
361
|
+
map._tooltip.text(data.tooltipText);
|
|
362
|
+
map._emit(data.event, [event, map._tooltip, data.code]);
|
|
363
|
+
if (!event.defaultPrevented) {
|
|
364
|
+
map._tooltip.show();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
data.element.hover(false);
|
|
369
|
+
if (showTooltip) {
|
|
370
|
+
map._tooltip.hide();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// When the click is released
|
|
376
|
+
EventHandler.delegate(container, 'mouseup', '.jvm-element', function (event) {
|
|
377
|
+
var data = parseEvent(map, this);
|
|
378
|
+
if (mouseMoved) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (data.type === 'region' && map.params.regionsSelectable || data.type === 'marker' && map.params.markersSelectable) {
|
|
382
|
+
var element = data.element;
|
|
383
|
+
|
|
384
|
+
// We're checking if regions/markers|SelectableOne option is presented
|
|
385
|
+
if (map.params[data.type + "sSelectableOne"]) {
|
|
386
|
+
data.type === 'region' ? map.clearSelectedRegions() : map.clearSelectedMarkers();
|
|
387
|
+
}
|
|
388
|
+
if (data.element.isSelected) {
|
|
389
|
+
element.select(false);
|
|
390
|
+
} else {
|
|
391
|
+
element.select(true);
|
|
392
|
+
}
|
|
393
|
+
map._emit(data.event, [data.code, element.isSelected, data.type === 'region' ? map.getSelectedRegions() : map.getSelectedMarkers()]);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// When region/marker is clicked
|
|
398
|
+
EventHandler.delegate(container, 'click', '.jvm-element', function (event) {
|
|
399
|
+
var _parseEvent = parseEvent(map, this),
|
|
400
|
+
type = _parseEvent.type,
|
|
401
|
+
code = _parseEvent.code;
|
|
402
|
+
map._emit(type === 'region' ? Events.onRegionClick : Events.onMarkerClick, [event, code]);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function setupZoomButtons() {
|
|
407
|
+
var _this = this;
|
|
408
|
+
var zoomInOption = this.params.zoomInButton;
|
|
409
|
+
var zoomOutOption = this.params.zoomOutButton;
|
|
410
|
+
var getZoomButton = function getZoomButton(zoomOption) {
|
|
411
|
+
return typeof zoomOption === 'string' ? document.querySelector(zoomOption) : zoomOption;
|
|
412
|
+
};
|
|
413
|
+
var zoomIn = zoomInOption ? getZoomButton(zoomInOption) : createElement('div', 'jvm-zoom-btn jvm-zoomin', '+', true);
|
|
414
|
+
var zoomOut = zoomOutOption ? getZoomButton(zoomOutOption) : createElement('div', 'jvm-zoom-btn jvm-zoomout', '−', true);
|
|
415
|
+
if (!zoomInOption) {
|
|
416
|
+
this.container.appendChild(zoomIn);
|
|
417
|
+
}
|
|
418
|
+
if (!zoomOutOption) {
|
|
419
|
+
this.container.appendChild(zoomOut);
|
|
420
|
+
}
|
|
421
|
+
var handler = function handler(zoomin) {
|
|
422
|
+
if (zoomin === void 0) {
|
|
423
|
+
zoomin = true;
|
|
424
|
+
}
|
|
425
|
+
return function () {
|
|
426
|
+
return _this._setScale(zoomin ? _this.scale * _this.params.zoomStep : _this.scale / _this.params.zoomStep, _this._width / 2, _this._height / 2, false, _this.params.zoomAnimate);
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
EventHandler.on(zoomIn, 'click', handler());
|
|
430
|
+
EventHandler.on(zoomOut, 'click', handler(false));
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function setupContainerTouchEvents() {
|
|
434
|
+
var map = this,
|
|
435
|
+
touchStartScale,
|
|
436
|
+
touchStartDistance,
|
|
437
|
+
touchX,
|
|
438
|
+
touchY,
|
|
439
|
+
centerTouchX,
|
|
440
|
+
centerTouchY,
|
|
441
|
+
lastTouchesLength;
|
|
442
|
+
var handleTouchEvent = function handleTouchEvent(e) {
|
|
443
|
+
var touches = e.touches;
|
|
444
|
+
var offset, scale, transXOld, transYOld;
|
|
445
|
+
if (e.type == 'touchstart') {
|
|
446
|
+
lastTouchesLength = 0;
|
|
447
|
+
}
|
|
448
|
+
if (touches.length == 1) {
|
|
449
|
+
if (lastTouchesLength == 1) {
|
|
450
|
+
var _map$_tooltip;
|
|
451
|
+
transXOld = map.transX;
|
|
452
|
+
transYOld = map.transY;
|
|
453
|
+
map.transX -= (touchX - touches[0].pageX) / map.scale;
|
|
454
|
+
map.transY -= (touchY - touches[0].pageY) / map.scale;
|
|
455
|
+
(_map$_tooltip = map._tooltip) == null || _map$_tooltip.hide();
|
|
456
|
+
map._applyTransform();
|
|
457
|
+
if (transXOld != map.transX || transYOld != map.transY) {
|
|
458
|
+
e.preventDefault();
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
touchX = touches[0].pageX;
|
|
462
|
+
touchY = touches[0].pageY;
|
|
463
|
+
} else if (touches.length == 2) {
|
|
464
|
+
if (lastTouchesLength == 2) {
|
|
465
|
+
var _map$_tooltip2;
|
|
466
|
+
scale = Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2)) / touchStartDistance;
|
|
467
|
+
map._setScale(touchStartScale * scale, centerTouchX, centerTouchY);
|
|
468
|
+
(_map$_tooltip2 = map._tooltip) == null || _map$_tooltip2.hide();
|
|
469
|
+
e.preventDefault();
|
|
470
|
+
} else {
|
|
471
|
+
var rect = map.container.getBoundingClientRect();
|
|
472
|
+
offset = {
|
|
473
|
+
top: rect.top + window.scrollY,
|
|
474
|
+
left: rect.left + window.scrollX
|
|
475
|
+
};
|
|
476
|
+
if (touches[0].pageX > touches[1].pageX) {
|
|
477
|
+
centerTouchX = touches[1].pageX + (touches[0].pageX - touches[1].pageX) / 2;
|
|
478
|
+
} else {
|
|
479
|
+
centerTouchX = touches[0].pageX + (touches[1].pageX - touches[0].pageX) / 2;
|
|
480
|
+
}
|
|
481
|
+
if (touches[0].pageY > touches[1].pageY) {
|
|
482
|
+
centerTouchY = touches[1].pageY + (touches[0].pageY - touches[1].pageY) / 2;
|
|
483
|
+
} else {
|
|
484
|
+
centerTouchY = touches[0].pageY + (touches[1].pageY - touches[0].pageY) / 2;
|
|
485
|
+
}
|
|
486
|
+
centerTouchX -= offset.left;
|
|
487
|
+
centerTouchY -= offset.top;
|
|
488
|
+
touchStartScale = map.scale;
|
|
489
|
+
touchStartDistance = Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
lastTouchesLength = touches.length;
|
|
493
|
+
};
|
|
494
|
+
EventHandler.on(map.container, 'touchstart', handleTouchEvent);
|
|
495
|
+
EventHandler.on(map.container, 'touchmove', handleTouchEvent);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function _arrayLikeToArray(r, a) {
|
|
499
|
+
(null == a || a > r.length) && (a = r.length);
|
|
500
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
501
|
+
return n;
|
|
502
|
+
}
|
|
503
|
+
function _assertThisInitialized(e) {
|
|
504
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
505
|
+
return e;
|
|
506
|
+
}
|
|
507
|
+
function _defineProperties(e, r) {
|
|
508
|
+
for (var t = 0; t < r.length; t++) {
|
|
509
|
+
var o = r[t];
|
|
510
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function _createClass(e, r, t) {
|
|
514
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
515
|
+
writable: !1
|
|
516
|
+
}), e;
|
|
517
|
+
}
|
|
518
|
+
function _createForOfIteratorHelperLoose(r, e) {
|
|
519
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
520
|
+
if (t) return (t = t.call(r)).next.bind(t);
|
|
521
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
522
|
+
t && (r = t);
|
|
523
|
+
var o = 0;
|
|
524
|
+
return function () {
|
|
525
|
+
return o >= r.length ? {
|
|
526
|
+
done: !0
|
|
527
|
+
} : {
|
|
528
|
+
done: !1,
|
|
529
|
+
value: r[o++]
|
|
530
|
+
};
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
534
|
+
}
|
|
535
|
+
function _extends() {
|
|
536
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
537
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
538
|
+
var t = arguments[e];
|
|
539
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
540
|
+
}
|
|
541
|
+
return n;
|
|
542
|
+
}, _extends.apply(null, arguments);
|
|
543
|
+
}
|
|
544
|
+
function _inheritsLoose(t, o) {
|
|
545
|
+
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
546
|
+
}
|
|
547
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
548
|
+
if (null == r) return {};
|
|
549
|
+
var t = {};
|
|
550
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
551
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
552
|
+
t[n] = r[n];
|
|
553
|
+
}
|
|
554
|
+
return t;
|
|
555
|
+
}
|
|
556
|
+
function _setPrototypeOf(t, e) {
|
|
557
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
558
|
+
return t.__proto__ = e, t;
|
|
559
|
+
}, _setPrototypeOf(t, e);
|
|
560
|
+
}
|
|
561
|
+
function _toPrimitive(t, r) {
|
|
562
|
+
if ("object" != typeof t || !t) return t;
|
|
563
|
+
var e = t[Symbol.toPrimitive];
|
|
564
|
+
if (void 0 !== e) {
|
|
565
|
+
var i = e.call(t, r || "default");
|
|
566
|
+
if ("object" != typeof i) return i;
|
|
567
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
568
|
+
}
|
|
569
|
+
return ("string" === r ? String : Number)(t);
|
|
570
|
+
}
|
|
571
|
+
function _toPropertyKey(t) {
|
|
572
|
+
var i = _toPrimitive(t, "string");
|
|
573
|
+
return "symbol" == typeof i ? i : i + "";
|
|
574
|
+
}
|
|
575
|
+
function _unsupportedIterableToArray(r, a) {
|
|
576
|
+
if (r) {
|
|
577
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
578
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
579
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
var BaseComponent = /*#__PURE__*/function () {
|
|
584
|
+
function BaseComponent() {}
|
|
585
|
+
var _proto = BaseComponent.prototype;
|
|
586
|
+
_proto.dispose = function dispose() {
|
|
587
|
+
if (this._tooltip) {
|
|
588
|
+
removeElement(this._tooltip);
|
|
589
|
+
} else {
|
|
590
|
+
// @todo: move shape in base component in v2
|
|
591
|
+
this.shape.remove();
|
|
592
|
+
}
|
|
593
|
+
for (var _iterator = _createForOfIteratorHelperLoose(Object.getOwnPropertyNames(this)), _step; !(_step = _iterator()).done;) {
|
|
594
|
+
var propertyName = _step.value;
|
|
595
|
+
this[propertyName] = null;
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
return BaseComponent;
|
|
599
|
+
}();
|
|
600
|
+
|
|
601
|
+
var Interactable = {
|
|
602
|
+
getLabelText: function getLabelText(key, label) {
|
|
603
|
+
if (!label) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (typeof label.render === 'function') {
|
|
607
|
+
var params = [];
|
|
608
|
+
|
|
609
|
+
// Pass additional paramater (Marker config object) in case it's a Marker.
|
|
610
|
+
if (this.constructor.Name === 'marker') {
|
|
611
|
+
params.push(this.getConfig());
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// Becuase we need to add the key always at the end
|
|
615
|
+
params.push(key);
|
|
616
|
+
return label.render.apply(this, params);
|
|
617
|
+
}
|
|
618
|
+
return key;
|
|
619
|
+
},
|
|
620
|
+
getLabelOffsets: function getLabelOffsets(key, label) {
|
|
621
|
+
if (typeof label.offsets === 'function') {
|
|
622
|
+
return label.offsets(key);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// If offsets are an array of offsets e.g offsets: [ [0, 25], [10, 15] ]
|
|
626
|
+
if (Array.isArray(label.offsets)) {
|
|
627
|
+
return label.offsets[key];
|
|
628
|
+
}
|
|
629
|
+
return [0, 0];
|
|
630
|
+
},
|
|
631
|
+
setStyle: function setStyle(property, value) {
|
|
632
|
+
this.shape.setStyle(property, value);
|
|
633
|
+
},
|
|
634
|
+
remove: function remove() {
|
|
635
|
+
this.shape.remove();
|
|
636
|
+
if (this.label) this.label.remove();
|
|
637
|
+
},
|
|
638
|
+
hover: function hover(state) {
|
|
639
|
+
this._setStatus('isHovered', state);
|
|
640
|
+
},
|
|
641
|
+
select: function select(state) {
|
|
642
|
+
this._setStatus('isSelected', state);
|
|
643
|
+
},
|
|
644
|
+
// Private
|
|
645
|
+
_setStatus: function _setStatus(property, state) {
|
|
646
|
+
this.shape[property] = state;
|
|
647
|
+
this.shape.updateStyle();
|
|
648
|
+
this[property] = state;
|
|
649
|
+
if (this.label) {
|
|
650
|
+
this.label[property] = state;
|
|
651
|
+
this.label.updateStyle();
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
var Region = /*#__PURE__*/function (_BaseComponent) {
|
|
657
|
+
function Region(_ref) {
|
|
658
|
+
var _this;
|
|
659
|
+
var map = _ref.map,
|
|
660
|
+
code = _ref.code,
|
|
661
|
+
path = _ref.path,
|
|
662
|
+
style = _ref.style,
|
|
663
|
+
label = _ref.label,
|
|
664
|
+
labelStyle = _ref.labelStyle,
|
|
665
|
+
labelsGroup = _ref.labelsGroup;
|
|
666
|
+
_this = _BaseComponent.call(this) || this;
|
|
667
|
+
_this._map = map;
|
|
668
|
+
_this.shape = _this._createRegion(path, code, style);
|
|
669
|
+
var text = _this.getLabelText(code, label);
|
|
670
|
+
|
|
671
|
+
// If label is passed and render function returns something
|
|
672
|
+
if (label && text) {
|
|
673
|
+
var bbox = _this.shape.getBBox();
|
|
674
|
+
var offsets = _this.getLabelOffsets(code, label);
|
|
675
|
+
_this.labelX = bbox.x + bbox.width / 2 + offsets[0];
|
|
676
|
+
_this.labelY = bbox.y + bbox.height / 2 + offsets[1];
|
|
677
|
+
_this.label = _this._map.canvas.createText({
|
|
678
|
+
text: text,
|
|
679
|
+
textAnchor: 'middle',
|
|
680
|
+
alignmentBaseline: 'central',
|
|
681
|
+
dataCode: code,
|
|
682
|
+
x: _this.labelX,
|
|
683
|
+
y: _this.labelY
|
|
684
|
+
}, labelStyle, labelsGroup);
|
|
685
|
+
_this.label.addClass('jvm-region jvm-element');
|
|
686
|
+
}
|
|
687
|
+
return _this;
|
|
688
|
+
}
|
|
689
|
+
_inheritsLoose(Region, _BaseComponent);
|
|
690
|
+
var _proto = Region.prototype;
|
|
691
|
+
_proto._createRegion = function _createRegion(path, code, style) {
|
|
692
|
+
path = this._map.canvas.createPath({
|
|
693
|
+
d: path,
|
|
694
|
+
dataCode: code
|
|
695
|
+
}, style);
|
|
696
|
+
path.addClass('jvm-region jvm-element');
|
|
697
|
+
return path;
|
|
698
|
+
};
|
|
699
|
+
_proto.updateLabelPosition = function updateLabelPosition() {
|
|
700
|
+
if (this.label) {
|
|
701
|
+
this.label.set({
|
|
702
|
+
x: this.labelX * this._map.scale + this._map.transX * this._map.scale,
|
|
703
|
+
y: this.labelY * this._map.scale + this._map.transY * this._map.scale
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
return Region;
|
|
708
|
+
}(BaseComponent);
|
|
709
|
+
inherit(Region, Interactable);
|
|
710
|
+
|
|
711
|
+
function createRegions() {
|
|
712
|
+
this._regionLabelsGroup = this._regionLabelsGroup || this.canvas.createGroup('jvm-regions-labels-group');
|
|
713
|
+
for (var code in this._mapData.paths) {
|
|
714
|
+
var region = new Region({
|
|
715
|
+
map: this,
|
|
716
|
+
code: code,
|
|
717
|
+
path: this._mapData.paths[code].path,
|
|
718
|
+
style: merge({}, this.params.regionStyle),
|
|
719
|
+
labelStyle: this.params.regionLabelStyle,
|
|
720
|
+
labelsGroup: this._regionLabelsGroup,
|
|
721
|
+
label: this.params.labels && this.params.labels.regions
|
|
722
|
+
});
|
|
723
|
+
this.regions[code] = {
|
|
724
|
+
config: this._mapData.paths[code],
|
|
725
|
+
element: region
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
var LINE_CLASS = 'jvm-line';
|
|
731
|
+
var Line = /*#__PURE__*/function (_BaseComponent) {
|
|
732
|
+
function Line(options, style) {
|
|
733
|
+
var _this;
|
|
734
|
+
_this = _BaseComponent.call(this) || this;
|
|
735
|
+
_this._options = options;
|
|
736
|
+
_this._style = {
|
|
737
|
+
initial: style
|
|
738
|
+
};
|
|
739
|
+
_this._draw();
|
|
740
|
+
return _this;
|
|
741
|
+
}
|
|
742
|
+
_inheritsLoose(Line, _BaseComponent);
|
|
743
|
+
var _proto = Line.prototype;
|
|
744
|
+
_proto.setStyle = function setStyle(property, value) {
|
|
745
|
+
this.shape.setStyle(property, value);
|
|
746
|
+
};
|
|
747
|
+
_proto.getConfig = function getConfig() {
|
|
748
|
+
return this._options.config;
|
|
749
|
+
};
|
|
750
|
+
_proto._draw = function _draw() {
|
|
751
|
+
var _this$_options = this._options,
|
|
752
|
+
index = _this$_options.index,
|
|
753
|
+
group = _this$_options.group,
|
|
754
|
+
map = _this$_options.map;
|
|
755
|
+
var config = {
|
|
756
|
+
d: this._getDAttribute(),
|
|
757
|
+
fill: 'none',
|
|
758
|
+
dataIndex: index
|
|
759
|
+
};
|
|
760
|
+
this.shape = map.canvas.createPath(config, this._style, group);
|
|
761
|
+
this.shape.addClass(LINE_CLASS);
|
|
762
|
+
};
|
|
763
|
+
_proto._getDAttribute = function _getDAttribute() {
|
|
764
|
+
var _this$_options2 = this._options,
|
|
765
|
+
x1 = _this$_options2.x1,
|
|
766
|
+
y1 = _this$_options2.y1,
|
|
767
|
+
x2 = _this$_options2.x2,
|
|
768
|
+
y2 = _this$_options2.y2,
|
|
769
|
+
curvature = _this$_options2.curvature;
|
|
770
|
+
return "M" + x1 + "," + y1 + this._getQCommand(x1, y1, x2, y2, curvature) + x2 + "," + y2;
|
|
771
|
+
};
|
|
772
|
+
_proto._getQCommand = function _getQCommand(x1, y1, x2, y2, curvature) {
|
|
773
|
+
if (!curvature) {
|
|
774
|
+
return ' ';
|
|
775
|
+
}
|
|
776
|
+
var curveX = (x1 + x2) / 2 + curvature * (y2 - y1);
|
|
777
|
+
var curveY = (y1 + y2) / 2 - curvature * (x2 - x1);
|
|
778
|
+
return " Q" + curveX + "," + curveY + " ";
|
|
779
|
+
};
|
|
780
|
+
return Line;
|
|
781
|
+
}(BaseComponent);
|
|
782
|
+
|
|
783
|
+
var _excluded = ["curvature"],
|
|
784
|
+
_excluded2 = ["curvature"];
|
|
785
|
+
function createLines(lines) {
|
|
786
|
+
var point1 = false,
|
|
787
|
+
point2 = false;
|
|
788
|
+
var _this$params$lineStyl = this.params.lineStyle,
|
|
789
|
+
curvature = _this$params$lineStyl.curvature,
|
|
790
|
+
lineStyle = _objectWithoutPropertiesLoose(_this$params$lineStyl, _excluded);
|
|
791
|
+
for (var index in lines) {
|
|
792
|
+
var lineConfig = lines[index];
|
|
793
|
+
for (var _i = 0, _Object$values = Object.values(this._markers); _i < _Object$values.length; _i++) {
|
|
794
|
+
var markerConfig = _Object$values[_i].config;
|
|
795
|
+
if (markerConfig.name === lineConfig.from) {
|
|
796
|
+
point1 = this.getMarkerPosition(markerConfig);
|
|
797
|
+
}
|
|
798
|
+
if (markerConfig.name === lineConfig.to) {
|
|
799
|
+
point2 = this.getMarkerPosition(markerConfig);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
if (point1 !== false && point2 !== false) {
|
|
803
|
+
var _ref = lineConfig.style || {},
|
|
804
|
+
curvatureOption = _ref.curvature,
|
|
805
|
+
style = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
806
|
+
|
|
807
|
+
// Register lines with unique keys
|
|
808
|
+
this._lines[getLineUid(lineConfig.from, lineConfig.to)] = new Line({
|
|
809
|
+
index: index,
|
|
810
|
+
map: this,
|
|
811
|
+
group: this._linesGroup,
|
|
812
|
+
config: lineConfig,
|
|
813
|
+
x1: point1.x,
|
|
814
|
+
y1: point1.y,
|
|
815
|
+
x2: point2.x,
|
|
816
|
+
y2: point2.y,
|
|
817
|
+
curvature: curvatureOption == 0 ? 0 : curvatureOption || curvature
|
|
818
|
+
}, merge(lineStyle, style, true));
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
var NAME = 'marker';
|
|
824
|
+
var JVM_PREFIX$1 = 'jvm-';
|
|
825
|
+
var MARKER_CLASS = JVM_PREFIX$1 + "element " + JVM_PREFIX$1 + "marker";
|
|
826
|
+
var MARKER_LABEL_CLASS = JVM_PREFIX$1 + "element " + JVM_PREFIX$1 + "label";
|
|
827
|
+
var Marker = /*#__PURE__*/function (_BaseComponent) {
|
|
828
|
+
function Marker(options, style) {
|
|
829
|
+
var _this;
|
|
830
|
+
_this = _BaseComponent.call(this) || this;
|
|
831
|
+
_this._options = options;
|
|
832
|
+
_this._style = style;
|
|
833
|
+
_this._labelX = null;
|
|
834
|
+
_this._labelY = null;
|
|
835
|
+
_this._offsets = null;
|
|
836
|
+
_this._isImage = !!style.initial.image;
|
|
837
|
+
_this._draw();
|
|
838
|
+
if (_this._options.label) {
|
|
839
|
+
_this._drawLabel();
|
|
840
|
+
}
|
|
841
|
+
if (_this._isImage) {
|
|
842
|
+
_this.updateLabelPosition();
|
|
843
|
+
}
|
|
844
|
+
return _this;
|
|
845
|
+
}
|
|
846
|
+
_inheritsLoose(Marker, _BaseComponent);
|
|
847
|
+
var _proto = Marker.prototype;
|
|
848
|
+
_proto.getConfig = function getConfig() {
|
|
849
|
+
return this._options.config;
|
|
850
|
+
};
|
|
851
|
+
_proto.updateLabelPosition = function updateLabelPosition() {
|
|
852
|
+
var map = this._options.map;
|
|
853
|
+
if (this.label) {
|
|
854
|
+
this.label.set({
|
|
855
|
+
x: this._labelX * map.scale + this._offsets[0] + map.transX * map.scale + 5 + (this._isImage ? (this.shape.width || 0) / 2 : this.shape.node.r.baseVal.value),
|
|
856
|
+
y: this._labelY * map.scale + map.transY * this._options.map.scale + this._offsets[1]
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
_proto._draw = function _draw() {
|
|
861
|
+
var _this$_options = this._options,
|
|
862
|
+
index = _this$_options.index,
|
|
863
|
+
map = _this$_options.map,
|
|
864
|
+
group = _this$_options.group,
|
|
865
|
+
cx = _this$_options.cx,
|
|
866
|
+
cy = _this$_options.cy;
|
|
867
|
+
var shapeType = this._isImage ? 'createImage' : 'createCircle';
|
|
868
|
+
this.shape = map.canvas[shapeType]({
|
|
869
|
+
dataIndex: index,
|
|
870
|
+
cx: cx,
|
|
871
|
+
cy: cy
|
|
872
|
+
}, this._style, group);
|
|
873
|
+
this.shape.addClass(MARKER_CLASS);
|
|
874
|
+
};
|
|
875
|
+
_proto._drawLabel = function _drawLabel() {
|
|
876
|
+
var _this$_options2 = this._options,
|
|
877
|
+
index = _this$_options2.index,
|
|
878
|
+
map = _this$_options2.map,
|
|
879
|
+
label = _this$_options2.label,
|
|
880
|
+
labelsGroup = _this$_options2.labelsGroup,
|
|
881
|
+
cx = _this$_options2.cx,
|
|
882
|
+
cy = _this$_options2.cy,
|
|
883
|
+
config = _this$_options2.config,
|
|
884
|
+
isRecentlyCreated = _this$_options2.isRecentlyCreated;
|
|
885
|
+
var labelText = this.getLabelText(index, label);
|
|
886
|
+
this._labelX = cx / map.scale - map.transX;
|
|
887
|
+
this._labelY = cy / map.scale - map.transY;
|
|
888
|
+
this._offsets = isRecentlyCreated && config.offsets ? config.offsets : this.getLabelOffsets(index, label);
|
|
889
|
+
this.label = map.canvas.createText({
|
|
890
|
+
text: labelText,
|
|
891
|
+
dataIndex: index,
|
|
892
|
+
x: this._labelX,
|
|
893
|
+
y: this._labelY,
|
|
894
|
+
dy: '0.6ex'
|
|
895
|
+
}, map.params.markerLabelStyle, labelsGroup);
|
|
896
|
+
this.label.addClass(MARKER_LABEL_CLASS);
|
|
897
|
+
if (isRecentlyCreated) {
|
|
898
|
+
this.updateLabelPosition();
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
return _createClass(Marker, null, [{
|
|
902
|
+
key: "Name",
|
|
903
|
+
get: function get() {
|
|
904
|
+
return NAME;
|
|
905
|
+
}
|
|
906
|
+
}]);
|
|
907
|
+
}(BaseComponent);
|
|
908
|
+
inherit(Marker, Interactable);
|
|
909
|
+
|
|
910
|
+
function createMarkers(markers, isRecentlyCreated) {
|
|
911
|
+
var _this = this;
|
|
912
|
+
if (markers === void 0) {
|
|
913
|
+
markers = {};
|
|
914
|
+
}
|
|
915
|
+
if (isRecentlyCreated === void 0) {
|
|
916
|
+
isRecentlyCreated = false;
|
|
917
|
+
}
|
|
918
|
+
var _loop = function _loop() {
|
|
919
|
+
var config = markers[index];
|
|
920
|
+
var point = _this.getMarkerPosition(config);
|
|
921
|
+
var uid = config.coords.join(':');
|
|
922
|
+
if (!point) {
|
|
923
|
+
return 0; // continue
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// We're checking if recently created marker does already exist
|
|
927
|
+
// If it does we don't need to create it again, so we'll continue
|
|
928
|
+
// Becuase we may have more than one marker submitted via `addMarkers` method.
|
|
929
|
+
if (isRecentlyCreated) {
|
|
930
|
+
if (Object.keys(_this._markers).filter(function (i) {
|
|
931
|
+
return _this._markers[i]._uid === uid;
|
|
932
|
+
}).length) {
|
|
933
|
+
return 0; // continue
|
|
934
|
+
}
|
|
935
|
+
index = Object.keys(_this._markers).length;
|
|
936
|
+
}
|
|
937
|
+
var marker = new Marker({
|
|
938
|
+
index: index,
|
|
939
|
+
map: _this,
|
|
940
|
+
label: _this.params.labels && _this.params.labels.markers,
|
|
941
|
+
labelsGroup: _this._markerLabelsGroup,
|
|
942
|
+
cx: point.x,
|
|
943
|
+
cy: point.y,
|
|
944
|
+
group: _this._markersGroup,
|
|
945
|
+
config: config,
|
|
946
|
+
isRecentlyCreated: isRecentlyCreated
|
|
947
|
+
}, merge(_this.params.markerStyle, _extends({}, config.style || {}), true));
|
|
948
|
+
|
|
949
|
+
// Check for marker duplication
|
|
950
|
+
// this is useful when for example: a user clicks a button for creating marker two times
|
|
951
|
+
// so it will remove the old one and the new one will take its place.
|
|
952
|
+
if (_this._markers[index]) {
|
|
953
|
+
_this.removeMarkers([index]);
|
|
954
|
+
}
|
|
955
|
+
_this._markers[index] = {
|
|
956
|
+
_uid: uid,
|
|
957
|
+
config: config,
|
|
958
|
+
element: marker
|
|
959
|
+
};
|
|
960
|
+
},
|
|
961
|
+
_ret;
|
|
962
|
+
for (var index in markers) {
|
|
963
|
+
_ret = _loop();
|
|
964
|
+
if (_ret === 0) continue;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
var Legend = /*#__PURE__*/function () {
|
|
969
|
+
function Legend(options) {
|
|
970
|
+
if (options === void 0) {
|
|
971
|
+
options = {};
|
|
972
|
+
}
|
|
973
|
+
this._options = options;
|
|
974
|
+
this._map = this._options.map;
|
|
975
|
+
this._series = this._options.series;
|
|
976
|
+
this._body = createElement('div', 'jvm-legend');
|
|
977
|
+
if (this._options.cssClass) {
|
|
978
|
+
this._body.setAttribute('class', this._options.cssClass);
|
|
979
|
+
}
|
|
980
|
+
if (options.vertical) {
|
|
981
|
+
this._map.legendVertical.appendChild(this._body);
|
|
982
|
+
} else {
|
|
983
|
+
this._map.legendHorizontal.appendChild(this._body);
|
|
984
|
+
}
|
|
985
|
+
this.render();
|
|
986
|
+
}
|
|
987
|
+
var _proto = Legend.prototype;
|
|
988
|
+
_proto.render = function render() {
|
|
989
|
+
var ticks = this._series.scale.getTicks();
|
|
990
|
+
this._body.innderHTML = '';
|
|
991
|
+
if (this._options.title) {
|
|
992
|
+
var legendTitle = createElement('div', 'jvm-legend-title', this._options.title);
|
|
993
|
+
this._body.appendChild(legendTitle);
|
|
994
|
+
}
|
|
995
|
+
for (var i = 0; i < ticks.length; i++) {
|
|
996
|
+
var tick = createElement('div', 'jvm-legend-tick');
|
|
997
|
+
var sample = createElement('div', 'jvm-legend-tick-sample');
|
|
998
|
+
switch (this._series.config.attribute) {
|
|
999
|
+
case 'fill':
|
|
1000
|
+
if (isImageUrl(ticks[i].value)) {
|
|
1001
|
+
sample.style.background = "url(" + ticks[i].value + ")";
|
|
1002
|
+
} else {
|
|
1003
|
+
sample.style.background = ticks[i].value;
|
|
1004
|
+
}
|
|
1005
|
+
break;
|
|
1006
|
+
case 'stroke':
|
|
1007
|
+
sample.style.background = ticks[i].value;
|
|
1008
|
+
break;
|
|
1009
|
+
case 'image':
|
|
1010
|
+
sample.style.background = "url(" + (typeof ticks[i].value === 'object' ? ticks[i].value.url : ticks[i].value) + ") no-repeat center center";
|
|
1011
|
+
sample.style.backgroundSize = 'cover';
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
tick.appendChild(sample);
|
|
1015
|
+
var label = ticks[i].label;
|
|
1016
|
+
if (this._options.labelRender) {
|
|
1017
|
+
label = this._options.labelRender(label);
|
|
1018
|
+
}
|
|
1019
|
+
var tickText = createElement('div', 'jvm-legend-tick-text', label);
|
|
1020
|
+
tick.appendChild(tickText);
|
|
1021
|
+
this._body.appendChild(tick);
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
return Legend;
|
|
1025
|
+
}();
|
|
1026
|
+
|
|
1027
|
+
var OrdinalScale = /*#__PURE__*/function () {
|
|
1028
|
+
function OrdinalScale(scale) {
|
|
1029
|
+
this._scale = scale;
|
|
1030
|
+
}
|
|
1031
|
+
var _proto = OrdinalScale.prototype;
|
|
1032
|
+
_proto.getValue = function getValue(value) {
|
|
1033
|
+
return this._scale[value];
|
|
1034
|
+
};
|
|
1035
|
+
_proto.getTicks = function getTicks() {
|
|
1036
|
+
var ticks = [];
|
|
1037
|
+
for (var key in this._scale) {
|
|
1038
|
+
ticks.push({
|
|
1039
|
+
label: key,
|
|
1040
|
+
value: this._scale[key]
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
return ticks;
|
|
1044
|
+
};
|
|
1045
|
+
return OrdinalScale;
|
|
1046
|
+
}();
|
|
1047
|
+
|
|
1048
|
+
var Series = /*#__PURE__*/function () {
|
|
1049
|
+
function Series(config, elements, map) {
|
|
1050
|
+
if (config === void 0) {
|
|
1051
|
+
config = {};
|
|
1052
|
+
}
|
|
1053
|
+
// Private
|
|
1054
|
+
this._map = map;
|
|
1055
|
+
this._elements = elements; // Could be markers or regions
|
|
1056
|
+
this._values = config.values || {};
|
|
1057
|
+
|
|
1058
|
+
// Protected
|
|
1059
|
+
this.config = config;
|
|
1060
|
+
this.config.attribute = config.attribute || 'fill';
|
|
1061
|
+
|
|
1062
|
+
// Set initial attributes
|
|
1063
|
+
if (config.attributes) {
|
|
1064
|
+
this.setAttributes(config.attributes);
|
|
1065
|
+
}
|
|
1066
|
+
if (typeof config.scale === 'object') {
|
|
1067
|
+
this.scale = new OrdinalScale(config.scale);
|
|
1068
|
+
}
|
|
1069
|
+
if (this.config.legend) {
|
|
1070
|
+
this.legend = new Legend(merge({
|
|
1071
|
+
map: this._map,
|
|
1072
|
+
series: this
|
|
1073
|
+
}, this.config.legend));
|
|
1074
|
+
}
|
|
1075
|
+
this.setValues(this._values);
|
|
1076
|
+
}
|
|
1077
|
+
var _proto = Series.prototype;
|
|
1078
|
+
_proto.setValues = function setValues(values) {
|
|
1079
|
+
var attrs = {};
|
|
1080
|
+
for (var key in values) {
|
|
1081
|
+
if (values[key]) {
|
|
1082
|
+
attrs[key] = this.scale.getValue(values[key]);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
this.setAttributes(attrs);
|
|
1086
|
+
};
|
|
1087
|
+
_proto.setAttributes = function setAttributes(attrs) {
|
|
1088
|
+
for (var code in attrs) {
|
|
1089
|
+
if (this._elements[code]) {
|
|
1090
|
+
this._elements[code].element.setStyle(this.config.attribute, attrs[code]);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
_proto.clear = function clear() {
|
|
1095
|
+
var key,
|
|
1096
|
+
attrs = {};
|
|
1097
|
+
for (key in this._values) {
|
|
1098
|
+
if (this._elements[key]) {
|
|
1099
|
+
attrs[key] = this._elements[key].element.shape.style.initial[this.config.attribute];
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
this.setAttributes(attrs);
|
|
1103
|
+
this._values = {};
|
|
1104
|
+
};
|
|
1105
|
+
return Series;
|
|
1106
|
+
}();
|
|
1107
|
+
|
|
1108
|
+
function createSeries() {
|
|
1109
|
+
this.series = {
|
|
1110
|
+
markers: [],
|
|
1111
|
+
regions: []
|
|
1112
|
+
};
|
|
1113
|
+
for (var key in this.params.series) {
|
|
1114
|
+
for (var i = 0; i < this.params.series[key].length; i++) {
|
|
1115
|
+
this.series[key][i] = new Series(this.params.series[key][i], key === 'markers' ? this._markers : this.regions, this);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
function applyTransform() {
|
|
1121
|
+
var maxTransX, maxTransY, minTransX, minTransY;
|
|
1122
|
+
if (this._defaultWidth * this.scale <= this._width) {
|
|
1123
|
+
maxTransX = (this._width - this._defaultWidth * this.scale) / (2 * this.scale);
|
|
1124
|
+
minTransX = (this._width - this._defaultWidth * this.scale) / (2 * this.scale);
|
|
1125
|
+
} else {
|
|
1126
|
+
maxTransX = 0;
|
|
1127
|
+
minTransX = (this._width - this._defaultWidth * this.scale) / this.scale;
|
|
1128
|
+
}
|
|
1129
|
+
if (this._defaultHeight * this.scale <= this._height) {
|
|
1130
|
+
maxTransY = (this._height - this._defaultHeight * this.scale) / (2 * this.scale);
|
|
1131
|
+
minTransY = (this._height - this._defaultHeight * this.scale) / (2 * this.scale);
|
|
1132
|
+
} else {
|
|
1133
|
+
maxTransY = 0;
|
|
1134
|
+
minTransY = (this._height - this._defaultHeight * this.scale) / this.scale;
|
|
1135
|
+
}
|
|
1136
|
+
if (this.transY > maxTransY) {
|
|
1137
|
+
this.transY = maxTransY;
|
|
1138
|
+
} else if (this.transY < minTransY) {
|
|
1139
|
+
this.transY = minTransY;
|
|
1140
|
+
}
|
|
1141
|
+
if (this.transX > maxTransX) {
|
|
1142
|
+
this.transX = maxTransX;
|
|
1143
|
+
} else if (this.transX < minTransX) {
|
|
1144
|
+
this.transX = minTransX;
|
|
1145
|
+
}
|
|
1146
|
+
this.canvas.applyTransformParams(this.scale, this.transX, this.transY);
|
|
1147
|
+
if (this._markers) {
|
|
1148
|
+
this._repositionMarkers();
|
|
1149
|
+
}
|
|
1150
|
+
if (this._lines) {
|
|
1151
|
+
this._repositionLines();
|
|
1152
|
+
}
|
|
1153
|
+
this._repositionLabels();
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
function resize() {
|
|
1157
|
+
var curBaseScale = this._baseScale;
|
|
1158
|
+
if (this._width / this._height > this._defaultWidth / this._defaultHeight) {
|
|
1159
|
+
this._baseScale = this._height / this._defaultHeight;
|
|
1160
|
+
this._baseTransX = Math.abs(this._width - this._defaultWidth * this._baseScale) / (2 * this._baseScale);
|
|
1161
|
+
} else {
|
|
1162
|
+
this._baseScale = this._width / this._defaultWidth;
|
|
1163
|
+
this._baseTransY = Math.abs(this._height - this._defaultHeight * this._baseScale) / (2 * this._baseScale);
|
|
1164
|
+
}
|
|
1165
|
+
this.scale *= this._baseScale / curBaseScale;
|
|
1166
|
+
this.transX *= this._baseScale / curBaseScale;
|
|
1167
|
+
this.transY *= this._baseScale / curBaseScale;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
function setScale(scale, anchorX, anchorY, isCentered, animate) {
|
|
1171
|
+
var _this = this;
|
|
1172
|
+
var zoomStep,
|
|
1173
|
+
interval,
|
|
1174
|
+
i = 0,
|
|
1175
|
+
count = Math.abs(Math.round((scale - this.scale) * 60 / Math.max(scale, this.scale))),
|
|
1176
|
+
scaleStart,
|
|
1177
|
+
scaleDiff,
|
|
1178
|
+
transXStart,
|
|
1179
|
+
transXDiff,
|
|
1180
|
+
transYStart,
|
|
1181
|
+
transYDiff,
|
|
1182
|
+
transX,
|
|
1183
|
+
transY;
|
|
1184
|
+
if (scale > this.params.zoomMax * this._baseScale) {
|
|
1185
|
+
scale = this.params.zoomMax * this._baseScale;
|
|
1186
|
+
} else if (scale < this.params.zoomMin * this._baseScale) {
|
|
1187
|
+
scale = this.params.zoomMin * this._baseScale;
|
|
1188
|
+
}
|
|
1189
|
+
if (typeof anchorX != 'undefined' && typeof anchorY != 'undefined') {
|
|
1190
|
+
zoomStep = scale / this.scale;
|
|
1191
|
+
if (isCentered) {
|
|
1192
|
+
transX = anchorX + this._defaultWidth * (this._width / (this._defaultWidth * scale)) / 2;
|
|
1193
|
+
transY = anchorY + this._defaultHeight * (this._height / (this._defaultHeight * scale)) / 2;
|
|
1194
|
+
} else {
|
|
1195
|
+
transX = this.transX - (zoomStep - 1) / scale * anchorX;
|
|
1196
|
+
transY = this.transY - (zoomStep - 1) / scale * anchorY;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
if (animate && count > 0) {
|
|
1200
|
+
scaleStart = this.scale;
|
|
1201
|
+
scaleDiff = (scale - scaleStart) / count;
|
|
1202
|
+
transXStart = this.transX * this.scale;
|
|
1203
|
+
transYStart = this.transY * this.scale;
|
|
1204
|
+
transXDiff = (transX * scale - transXStart) / count;
|
|
1205
|
+
transYDiff = (transY * scale - transYStart) / count;
|
|
1206
|
+
interval = setInterval(function () {
|
|
1207
|
+
i += 1;
|
|
1208
|
+
_this.scale = scaleStart + scaleDiff * i;
|
|
1209
|
+
_this.transX = (transXStart + transXDiff * i) / _this.scale;
|
|
1210
|
+
_this.transY = (transYStart + transYDiff * i) / _this.scale;
|
|
1211
|
+
_this._applyTransform();
|
|
1212
|
+
if (i == count) {
|
|
1213
|
+
clearInterval(interval);
|
|
1214
|
+
_this._emit(Events.onViewportChange, [_this.scale, _this.transX, _this.transY]);
|
|
1215
|
+
}
|
|
1216
|
+
}, 10);
|
|
1217
|
+
} else {
|
|
1218
|
+
this.transX = transX;
|
|
1219
|
+
this.transY = transY;
|
|
1220
|
+
this.scale = scale;
|
|
1221
|
+
this._applyTransform();
|
|
1222
|
+
this._emit(Events.onViewportChange, [this.scale, this.transX, this.transY]);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
function setFocus(config) {
|
|
1227
|
+
var _this = this;
|
|
1228
|
+
if (config === void 0) {
|
|
1229
|
+
config = {};
|
|
1230
|
+
}
|
|
1231
|
+
var bbox,
|
|
1232
|
+
codes = [];
|
|
1233
|
+
if (config.region) {
|
|
1234
|
+
codes.push(config.region);
|
|
1235
|
+
} else if (config.regions) {
|
|
1236
|
+
codes = config.regions;
|
|
1237
|
+
}
|
|
1238
|
+
if (codes.length) {
|
|
1239
|
+
codes.forEach(function (code) {
|
|
1240
|
+
if (_this.regions[code]) {
|
|
1241
|
+
var itemBbox = _this.regions[code].element.shape.getBBox();
|
|
1242
|
+
if (itemBbox) {
|
|
1243
|
+
// Handle the first loop
|
|
1244
|
+
if (typeof bbox == 'undefined') {
|
|
1245
|
+
bbox = itemBbox;
|
|
1246
|
+
} else {
|
|
1247
|
+
// get the old bbox properties plus the current
|
|
1248
|
+
// this kinda incrementing the old values and the new values
|
|
1249
|
+
bbox = {
|
|
1250
|
+
x: Math.min(bbox.x, itemBbox.x),
|
|
1251
|
+
y: Math.min(bbox.y, itemBbox.y),
|
|
1252
|
+
width: Math.max(bbox.x + bbox.width, itemBbox.x + itemBbox.width) - Math.min(bbox.x, itemBbox.x),
|
|
1253
|
+
height: Math.max(bbox.y + bbox.height, itemBbox.y + itemBbox.height) - Math.min(bbox.y, itemBbox.y)
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
return this._setScale(Math.min(this._width / bbox.width, this._height / bbox.height), -(bbox.x + bbox.width / 2), -(bbox.y + bbox.height / 2), true, config.animate);
|
|
1260
|
+
} else if (config.coords) {
|
|
1261
|
+
var point = this.coordsToPoint(config.coords[0], config.coords[1]);
|
|
1262
|
+
var x = this.transX - point.x / this.scale;
|
|
1263
|
+
var y = this.transY - point.y / this.scale;
|
|
1264
|
+
return this._setScale(config.scale * this._baseScale, x, y, true, config.animate);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
function updateSize() {
|
|
1269
|
+
this._width = this.container.offsetWidth;
|
|
1270
|
+
this._height = this.container.offsetHeight;
|
|
1271
|
+
this._resize();
|
|
1272
|
+
this.canvas.setSize(this._width, this._height);
|
|
1273
|
+
this._applyTransform();
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* ------------------------------------------------------------------------
|
|
1278
|
+
* Object
|
|
1279
|
+
* ------------------------------------------------------------------------
|
|
1280
|
+
*/
|
|
1281
|
+
var Proj = {
|
|
1282
|
+
/* sgn(n){
|
|
1283
|
+
if (n > 0) {
|
|
1284
|
+
return 1;
|
|
1285
|
+
} else if (n < 0) {
|
|
1286
|
+
return -1;
|
|
1287
|
+
} else {
|
|
1288
|
+
return n;
|
|
1289
|
+
}
|
|
1290
|
+
}, */
|
|
1291
|
+
mill: function mill(lat, lng, c) {
|
|
1292
|
+
return {
|
|
1293
|
+
x: this.radius * (lng - c) * this.radDeg,
|
|
1294
|
+
y: -this.radius * Math.log(Math.tan((45 + 0.4 * lat) * this.radDeg)) / 0.8
|
|
1295
|
+
};
|
|
1296
|
+
},
|
|
1297
|
+
/* mill_inv(x, y, c) {
|
|
1298
|
+
return {
|
|
1299
|
+
lat: (2.5 * Math.atan(Math.exp(0.8 * y / this.radius)) - 5 * Math.PI / 8) * this.degRad,
|
|
1300
|
+
lng: (c * this.radDeg + x / this.radius) * this.degRad
|
|
1301
|
+
};
|
|
1302
|
+
}, */
|
|
1303
|
+
merc: function merc(lat, lng, c) {
|
|
1304
|
+
return {
|
|
1305
|
+
x: this.radius * (lng - c) * this.radDeg,
|
|
1306
|
+
y: -this.radius * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360))
|
|
1307
|
+
};
|
|
1308
|
+
},
|
|
1309
|
+
/* merc_inv(x, y, c) {
|
|
1310
|
+
return {
|
|
1311
|
+
lat: (2 * Math.atan(Math.exp(y / this.radius)) - Math.PI / 2) * this.degRad,
|
|
1312
|
+
lng: (c * this.radDeg + x / this.radius) * this.degRad
|
|
1313
|
+
};
|
|
1314
|
+
}, */
|
|
1315
|
+
aea: function aea(lat, lng, c) {
|
|
1316
|
+
var fi0 = 0,
|
|
1317
|
+
lambda0 = c * this.radDeg,
|
|
1318
|
+
fi1 = 29.5 * this.radDeg,
|
|
1319
|
+
fi2 = 45.5 * this.radDeg,
|
|
1320
|
+
fi = lat * this.radDeg,
|
|
1321
|
+
lambda = lng * this.radDeg,
|
|
1322
|
+
n = (Math.sin(fi1) + Math.sin(fi2)) / 2,
|
|
1323
|
+
C = Math.cos(fi1) * Math.cos(fi1) + 2 * n * Math.sin(fi1),
|
|
1324
|
+
theta = n * (lambda - lambda0),
|
|
1325
|
+
ro = Math.sqrt(C - 2 * n * Math.sin(fi)) / n,
|
|
1326
|
+
ro0 = Math.sqrt(C - 2 * n * Math.sin(fi0)) / n;
|
|
1327
|
+
return {
|
|
1328
|
+
x: ro * Math.sin(theta) * this.radius,
|
|
1329
|
+
y: -(ro0 - ro * Math.cos(theta)) * this.radius
|
|
1330
|
+
};
|
|
1331
|
+
},
|
|
1332
|
+
/* aea_inv(xCoord, yCoord, c) {
|
|
1333
|
+
var x = xCoord / this.radius,
|
|
1334
|
+
y = yCoord / this.radius,
|
|
1335
|
+
fi0 = 0,
|
|
1336
|
+
lambda0 = c * this.radDeg,
|
|
1337
|
+
fi1 = 29.5 * this.radDeg,
|
|
1338
|
+
fi2 = 45.5 * this.radDeg,
|
|
1339
|
+
n = (Math.sin(fi1)+Math.sin(fi2)) / 2,
|
|
1340
|
+
C = Math.cos(fi1)*Math.cos(fi1)+2*n*Math.sin(fi1),
|
|
1341
|
+
ro0 = Math.sqrt(C-2*n*Math.sin(fi0))/n,
|
|
1342
|
+
ro = Math.sqrt(x*x+(ro0-y)*(ro0-y)),
|
|
1343
|
+
theta = Math.atan( x / (ro0 - y) );
|
|
1344
|
+
return {
|
|
1345
|
+
lat: (Math.asin((C - ro * ro * n * n) / (2 * n))) * this.degRad,
|
|
1346
|
+
lng: (lambda0 + theta / n) * this.degRad
|
|
1347
|
+
};
|
|
1348
|
+
}, */
|
|
1349
|
+
lcc: function lcc(lat, lng, c) {
|
|
1350
|
+
var fi0 = 0,
|
|
1351
|
+
lambda0 = c * this.radDeg,
|
|
1352
|
+
lambda = lng * this.radDeg,
|
|
1353
|
+
fi1 = 33 * this.radDeg,
|
|
1354
|
+
fi2 = 45 * this.radDeg,
|
|
1355
|
+
fi = lat * this.radDeg,
|
|
1356
|
+
n = Math.log(Math.cos(fi1) * (1 / Math.cos(fi2))) / Math.log(Math.tan(Math.PI / 4 + fi2 / 2) * (1 / Math.tan(Math.PI / 4 + fi1 / 2))),
|
|
1357
|
+
F = Math.cos(fi1) * Math.pow(Math.tan(Math.PI / 4 + fi1 / 2), n) / n,
|
|
1358
|
+
ro = F * Math.pow(1 / Math.tan(Math.PI / 4 + fi / 2), n),
|
|
1359
|
+
ro0 = F * Math.pow(1 / Math.tan(Math.PI / 4 + fi0 / 2), n);
|
|
1360
|
+
return {
|
|
1361
|
+
x: ro * Math.sin(n * (lambda - lambda0)) * this.radius,
|
|
1362
|
+
y: -(ro0 - ro * Math.cos(n * (lambda - lambda0))) * this.radius
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
/* lcc_inv(xCoord, yCoord, c) {
|
|
1366
|
+
var x = xCoord / this.radius,
|
|
1367
|
+
y = yCoord / this.radius,
|
|
1368
|
+
fi0 = 0,
|
|
1369
|
+
lambda0 = c * this.radDeg,
|
|
1370
|
+
fi1 = 33 * this.radDeg,
|
|
1371
|
+
fi2 = 45 * this.radDeg,
|
|
1372
|
+
n = Math.log( Math.cos(fi1) * (1 / Math.cos(fi2)) ) / Math.log( Math.tan( Math.PI / 4 + fi2 / 2) * (1 / Math.tan( Math.PI / 4 + fi1 / 2) ) ),
|
|
1373
|
+
F = ( Math.cos(fi1) * Math.pow( Math.tan( Math.PI / 4 + fi1 / 2 ), n ) ) / n,
|
|
1374
|
+
ro0 = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi0 / 2 ), n ),
|
|
1375
|
+
ro = this.sgn(n) * Math.sqrt(x*x+(ro0-y)*(ro0-y)),
|
|
1376
|
+
theta = Math.atan( x / (ro0 - y) );
|
|
1377
|
+
return {
|
|
1378
|
+
lat: (2 * Math.atan(Math.pow(F/ro, 1/n)) - Math.PI / 2) * this.degRad,
|
|
1379
|
+
lng: (lambda0 + theta / n) * this.degRad
|
|
1380
|
+
};
|
|
1381
|
+
} */
|
|
1382
|
+
};
|
|
1383
|
+
Proj.degRad = 180 / Math.PI;
|
|
1384
|
+
Proj.radDeg = Math.PI / 180;
|
|
1385
|
+
Proj.radius = 6381372;
|
|
1386
|
+
|
|
1387
|
+
function coordsToPoint(lat, lng) {
|
|
1388
|
+
var projection = Map.maps[this.params.map].projection;
|
|
1389
|
+
var _Proj$projection$type = Proj[projection.type](lat, lng, projection.centralMeridian),
|
|
1390
|
+
x = _Proj$projection$type.x,
|
|
1391
|
+
y = _Proj$projection$type.y;
|
|
1392
|
+
var inset = this.getInsetForPoint(x, y);
|
|
1393
|
+
if (!inset) {
|
|
1394
|
+
return false;
|
|
1395
|
+
}
|
|
1396
|
+
var bbox = inset.bbox;
|
|
1397
|
+
x = (x - bbox[0].x) / (bbox[1].x - bbox[0].x) * inset.width * this.scale;
|
|
1398
|
+
y = (y - bbox[0].y) / (bbox[1].y - bbox[0].y) * inset.height * this.scale;
|
|
1399
|
+
return {
|
|
1400
|
+
x: x + this.transX * this.scale + inset.left * this.scale,
|
|
1401
|
+
y: y + this.transY * this.scale + inset.top * this.scale
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
function getInsetForPoint(x, y) {
|
|
1406
|
+
var insets = Map.maps[this.params.map].insets;
|
|
1407
|
+
for (var index = 0; index < insets.length; index++) {
|
|
1408
|
+
var _insets$index$bbox = insets[index].bbox,
|
|
1409
|
+
start = _insets$index$bbox[0],
|
|
1410
|
+
end = _insets$index$bbox[1];
|
|
1411
|
+
if (x > start.x && x < end.x && y > start.y && y < end.y) {
|
|
1412
|
+
return insets[index];
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
function getMarkerPosition(_ref) {
|
|
1418
|
+
var coords = _ref.coords;
|
|
1419
|
+
if (Map.maps[this.params.map].projection) {
|
|
1420
|
+
return this.coordsToPoint.apply(this, coords);
|
|
1421
|
+
}
|
|
1422
|
+
return {
|
|
1423
|
+
x: coords[0] * this.scale + this.transX * this.scale,
|
|
1424
|
+
y: coords[1] * this.scale + this.transY * this.scale
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
function repositionLines() {
|
|
1429
|
+
var _this = this;
|
|
1430
|
+
var curvature = this.params.lineStyle.curvature;
|
|
1431
|
+
Object.values(this._lines).forEach(function (line) {
|
|
1432
|
+
var startMarker = Object.values(_this._markers).find(function (_ref) {
|
|
1433
|
+
var config = _ref.config;
|
|
1434
|
+
return config.name === line.getConfig().from;
|
|
1435
|
+
});
|
|
1436
|
+
var endMarker = Object.values(_this._markers).find(function (_ref2) {
|
|
1437
|
+
var config = _ref2.config;
|
|
1438
|
+
return config.name === line.getConfig().to;
|
|
1439
|
+
});
|
|
1440
|
+
if (startMarker && endMarker) {
|
|
1441
|
+
var _this$getMarkerPositi = _this.getMarkerPosition(startMarker.config),
|
|
1442
|
+
x1 = _this$getMarkerPositi.x,
|
|
1443
|
+
y1 = _this$getMarkerPositi.y;
|
|
1444
|
+
var _this$getMarkerPositi2 = _this.getMarkerPosition(endMarker.config),
|
|
1445
|
+
x2 = _this$getMarkerPositi2.x,
|
|
1446
|
+
y2 = _this$getMarkerPositi2.y;
|
|
1447
|
+
var curvatureOption = line._options.curvature == 0 ? 0 : line._options.curvature || curvature;
|
|
1448
|
+
var midX = (x1 + x2) / 2;
|
|
1449
|
+
var midY = (y1 + y2) / 2;
|
|
1450
|
+
var curveX = midX + curvatureOption * (y2 - y1);
|
|
1451
|
+
var curveY = midY - curvatureOption * (x2 - x1);
|
|
1452
|
+
line.setStyle({
|
|
1453
|
+
d: "M" + x1 + "," + y1 + " Q" + curveX + "," + curveY + " " + x2 + "," + y2
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
function repositionMarkers() {
|
|
1460
|
+
for (var index in this._markers) {
|
|
1461
|
+
var point = this.getMarkerPosition(this._markers[index].config);
|
|
1462
|
+
if (point !== false) {
|
|
1463
|
+
this._markers[index].element.setStyle({
|
|
1464
|
+
cx: point.x,
|
|
1465
|
+
cy: point.y
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
function repositionLabels() {
|
|
1472
|
+
var labels = this.params.labels;
|
|
1473
|
+
if (!labels) {
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
// Regions labels
|
|
1478
|
+
if (labels.regions) {
|
|
1479
|
+
for (var key in this.regions) {
|
|
1480
|
+
this.regions[key].element.updateLabelPosition();
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// Markers labels
|
|
1485
|
+
if (labels.markers) {
|
|
1486
|
+
for (var _key in this._markers) {
|
|
1487
|
+
this._markers[_key].element.updateLabelPosition();
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
var core = {
|
|
1493
|
+
_setupContainerEvents: setupContainerEvents,
|
|
1494
|
+
_setupElementEvents: setupElementEvents,
|
|
1495
|
+
_setupZoomButtons: setupZoomButtons,
|
|
1496
|
+
_setupContainerTouchEvents: setupContainerTouchEvents,
|
|
1497
|
+
_createRegions: createRegions,
|
|
1498
|
+
_createLines: createLines,
|
|
1499
|
+
_createMarkers: createMarkers,
|
|
1500
|
+
_createSeries: createSeries,
|
|
1501
|
+
_applyTransform: applyTransform,
|
|
1502
|
+
_resize: resize,
|
|
1503
|
+
_setScale: setScale,
|
|
1504
|
+
setFocus: setFocus,
|
|
1505
|
+
updateSize: updateSize,
|
|
1506
|
+
coordsToPoint: coordsToPoint,
|
|
1507
|
+
getInsetForPoint: getInsetForPoint,
|
|
1508
|
+
getMarkerPosition: getMarkerPosition,
|
|
1509
|
+
_repositionLines: repositionLines,
|
|
1510
|
+
_repositionMarkers: repositionMarkers,
|
|
1511
|
+
_repositionLabels: repositionLabels
|
|
1512
|
+
};
|
|
1513
|
+
|
|
1514
|
+
var Defaults = {
|
|
1515
|
+
map: 'world',
|
|
1516
|
+
backgroundColor: 'transparent',
|
|
1517
|
+
draggable: true,
|
|
1518
|
+
zoomButtons: true,
|
|
1519
|
+
zoomOnScroll: true,
|
|
1520
|
+
zoomOnScrollSpeed: 3,
|
|
1521
|
+
zoomMax: 12,
|
|
1522
|
+
zoomMin: 1,
|
|
1523
|
+
zoomAnimate: true,
|
|
1524
|
+
showTooltip: true,
|
|
1525
|
+
zoomStep: 1.5,
|
|
1526
|
+
bindTouchEvents: true,
|
|
1527
|
+
// Line options
|
|
1528
|
+
lineStyle: {
|
|
1529
|
+
curvature: 0,
|
|
1530
|
+
stroke: '#808080',
|
|
1531
|
+
strokeWidth: 1,
|
|
1532
|
+
strokeLinecap: 'round'
|
|
1533
|
+
},
|
|
1534
|
+
// Marker options
|
|
1535
|
+
markersSelectable: false,
|
|
1536
|
+
markersSelectableOne: false,
|
|
1537
|
+
markerStyle: {
|
|
1538
|
+
initial: {
|
|
1539
|
+
r: 7,
|
|
1540
|
+
fill: '#374151',
|
|
1541
|
+
fillOpacity: 1,
|
|
1542
|
+
stroke: '#FFF',
|
|
1543
|
+
strokeWidth: 5,
|
|
1544
|
+
strokeOpacity: .5
|
|
1545
|
+
},
|
|
1546
|
+
hover: {
|
|
1547
|
+
fill: '#3cc0ff',
|
|
1548
|
+
cursor: 'pointer'
|
|
1549
|
+
},
|
|
1550
|
+
selected: {
|
|
1551
|
+
fill: 'blue'
|
|
1552
|
+
},
|
|
1553
|
+
selectedHover: {}
|
|
1554
|
+
},
|
|
1555
|
+
markerLabelStyle: {
|
|
1556
|
+
initial: {
|
|
1557
|
+
fontFamily: 'Verdana',
|
|
1558
|
+
fontSize: 12,
|
|
1559
|
+
fontWeight: 500,
|
|
1560
|
+
cursor: 'default',
|
|
1561
|
+
fill: '#374151'
|
|
1562
|
+
},
|
|
1563
|
+
hover: {
|
|
1564
|
+
cursor: 'pointer'
|
|
1565
|
+
},
|
|
1566
|
+
selected: {},
|
|
1567
|
+
selectedHover: {}
|
|
1568
|
+
},
|
|
1569
|
+
// Region options
|
|
1570
|
+
regionsSelectable: false,
|
|
1571
|
+
regionsSelectableOne: false,
|
|
1572
|
+
regionStyle: {
|
|
1573
|
+
initial: {
|
|
1574
|
+
fill: '#dee2e8',
|
|
1575
|
+
fillOpacity: 1,
|
|
1576
|
+
stroke: 'none',
|
|
1577
|
+
strokeWidth: 0
|
|
1578
|
+
},
|
|
1579
|
+
hover: {
|
|
1580
|
+
fillOpacity: .7,
|
|
1581
|
+
cursor: 'pointer'
|
|
1582
|
+
},
|
|
1583
|
+
selected: {
|
|
1584
|
+
fill: '#9ca3af'
|
|
1585
|
+
},
|
|
1586
|
+
selectedHover: {}
|
|
1587
|
+
},
|
|
1588
|
+
regionLabelStyle: {
|
|
1589
|
+
initial: {
|
|
1590
|
+
fontFamily: 'Verdana',
|
|
1591
|
+
fontSize: '12',
|
|
1592
|
+
fontWeight: 'bold',
|
|
1593
|
+
cursor: 'default',
|
|
1594
|
+
fill: '#35373e'
|
|
1595
|
+
},
|
|
1596
|
+
hover: {
|
|
1597
|
+
cursor: 'pointer'
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
|
|
1602
|
+
var SVGElement = /*#__PURE__*/function () {
|
|
1603
|
+
function SVGElement(name, config) {
|
|
1604
|
+
this.node = this._createElement(name);
|
|
1605
|
+
if (config) {
|
|
1606
|
+
this.set(config);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
// Create new SVG element `svg`, `g`, `path`, `line`, `circle`, `image`, etc.
|
|
1611
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS#important_namespace_uris
|
|
1612
|
+
var _proto = SVGElement.prototype;
|
|
1613
|
+
_proto._createElement = function _createElement(tagName) {
|
|
1614
|
+
return document.createElementNS('http://www.w3.org/2000/svg', tagName);
|
|
1615
|
+
};
|
|
1616
|
+
_proto.addClass = function addClass(className) {
|
|
1617
|
+
this.node.setAttribute('class', className);
|
|
1618
|
+
};
|
|
1619
|
+
_proto.getBBox = function getBBox() {
|
|
1620
|
+
return this.node.getBBox();
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
// Apply attributes on the current node element
|
|
1624
|
+
;
|
|
1625
|
+
_proto.set = function set(property, value) {
|
|
1626
|
+
if (typeof property === 'object') {
|
|
1627
|
+
for (var attr in property) {
|
|
1628
|
+
this.applyAttr(attr, property[attr]);
|
|
1629
|
+
}
|
|
1630
|
+
} else {
|
|
1631
|
+
this.applyAttr(property, value);
|
|
1632
|
+
}
|
|
1633
|
+
};
|
|
1634
|
+
_proto.get = function get(property) {
|
|
1635
|
+
return this.style.initial[property];
|
|
1636
|
+
};
|
|
1637
|
+
_proto.applyAttr = function applyAttr(property, value) {
|
|
1638
|
+
this.node.setAttribute(hyphenate(property), value);
|
|
1639
|
+
};
|
|
1640
|
+
_proto.remove = function remove() {
|
|
1641
|
+
removeElement(this.node);
|
|
1642
|
+
};
|
|
1643
|
+
return SVGElement;
|
|
1644
|
+
}();
|
|
1645
|
+
|
|
1646
|
+
var SVGShapeElement = /*#__PURE__*/function (_SVGElement) {
|
|
1647
|
+
function SVGShapeElement(name, config, style) {
|
|
1648
|
+
var _this;
|
|
1649
|
+
if (style === void 0) {
|
|
1650
|
+
style = {};
|
|
1651
|
+
}
|
|
1652
|
+
_this = _SVGElement.call(this, name, config) || this;
|
|
1653
|
+
_this.isHovered = false;
|
|
1654
|
+
_this.isSelected = false;
|
|
1655
|
+
_this.style = style;
|
|
1656
|
+
_this.style.current = {};
|
|
1657
|
+
_this.updateStyle();
|
|
1658
|
+
return _this;
|
|
1659
|
+
}
|
|
1660
|
+
_inheritsLoose(SVGShapeElement, _SVGElement);
|
|
1661
|
+
var _proto = SVGShapeElement.prototype;
|
|
1662
|
+
_proto.setStyle = function setStyle(property, value) {
|
|
1663
|
+
if (typeof property === 'object') {
|
|
1664
|
+
merge(this.style.current, property);
|
|
1665
|
+
} else {
|
|
1666
|
+
var _merge;
|
|
1667
|
+
merge(this.style.current, (_merge = {}, _merge[property] = value, _merge));
|
|
1668
|
+
}
|
|
1669
|
+
this.updateStyle();
|
|
1670
|
+
};
|
|
1671
|
+
_proto.updateStyle = function updateStyle() {
|
|
1672
|
+
var attrs = {};
|
|
1673
|
+
merge(attrs, this.style.initial);
|
|
1674
|
+
merge(attrs, this.style.current);
|
|
1675
|
+
if (this.isHovered) {
|
|
1676
|
+
merge(attrs, this.style.hover);
|
|
1677
|
+
}
|
|
1678
|
+
if (this.isSelected) {
|
|
1679
|
+
merge(attrs, this.style.selected);
|
|
1680
|
+
if (this.isHovered) {
|
|
1681
|
+
merge(attrs, this.style.selectedHover);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
this.set(attrs);
|
|
1685
|
+
};
|
|
1686
|
+
return SVGShapeElement;
|
|
1687
|
+
}(SVGElement);
|
|
1688
|
+
|
|
1689
|
+
var SVGTextElement = /*#__PURE__*/function (_SVGShapeElement) {
|
|
1690
|
+
function SVGTextElement(config, style) {
|
|
1691
|
+
return _SVGShapeElement.call(this, 'text', config, style) || this;
|
|
1692
|
+
}
|
|
1693
|
+
_inheritsLoose(SVGTextElement, _SVGShapeElement);
|
|
1694
|
+
var _proto = SVGTextElement.prototype;
|
|
1695
|
+
_proto.applyAttr = function applyAttr(attr, value) {
|
|
1696
|
+
attr === 'text' ? this.node.textContent = value : _SVGShapeElement.prototype.applyAttr.call(this, attr, value);
|
|
1697
|
+
};
|
|
1698
|
+
return SVGTextElement;
|
|
1699
|
+
}(SVGShapeElement);
|
|
1700
|
+
|
|
1701
|
+
var SVGImageElement = /*#__PURE__*/function (_SVGShapeElement) {
|
|
1702
|
+
function SVGImageElement(config, style) {
|
|
1703
|
+
return _SVGShapeElement.call(this, 'image', config, style) || this;
|
|
1704
|
+
}
|
|
1705
|
+
_inheritsLoose(SVGImageElement, _SVGShapeElement);
|
|
1706
|
+
var _proto = SVGImageElement.prototype;
|
|
1707
|
+
_proto.applyAttr = function applyAttr(attr, value) {
|
|
1708
|
+
var imageUrl;
|
|
1709
|
+
if (attr === 'image') {
|
|
1710
|
+
// This get executed when we have url in series.markers[0].scale.someScale.url
|
|
1711
|
+
if (typeof value === 'object') {
|
|
1712
|
+
imageUrl = value.url;
|
|
1713
|
+
this.offset = value.offset || [0, 0];
|
|
1714
|
+
} else {
|
|
1715
|
+
imageUrl = value;
|
|
1716
|
+
this.offset = [0, 0];
|
|
1717
|
+
}
|
|
1718
|
+
this.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', imageUrl);
|
|
1719
|
+
|
|
1720
|
+
// Set width and height then call this `applyAttr` again
|
|
1721
|
+
this.width = 23;
|
|
1722
|
+
this.height = 23;
|
|
1723
|
+
this.applyAttr('width', this.width);
|
|
1724
|
+
this.applyAttr('height', this.height);
|
|
1725
|
+
this.applyAttr('x', this.cx - this.width / 2 + this.offset[0]);
|
|
1726
|
+
this.applyAttr('y', this.cy - this.height / 2 + this.offset[1]);
|
|
1727
|
+
} else if (attr == 'cx') {
|
|
1728
|
+
this.cx = value;
|
|
1729
|
+
if (this.width) {
|
|
1730
|
+
this.applyAttr('x', value - this.width / 2 + this.offset[0]);
|
|
1731
|
+
}
|
|
1732
|
+
} else if (attr == 'cy') {
|
|
1733
|
+
this.cy = value;
|
|
1734
|
+
if (this.height) {
|
|
1735
|
+
this.applyAttr('y', value - this.height / 2 + this.offset[1]);
|
|
1736
|
+
}
|
|
1737
|
+
} else {
|
|
1738
|
+
// This time Call SVGElement
|
|
1739
|
+
_SVGShapeElement.prototype.applyAttr.apply(this, arguments);
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
return SVGImageElement;
|
|
1743
|
+
}(SVGShapeElement);
|
|
1744
|
+
|
|
1745
|
+
var SVGCanvasElement = /*#__PURE__*/function (_SVGElement) {
|
|
1746
|
+
function SVGCanvasElement(container) {
|
|
1747
|
+
var _this;
|
|
1748
|
+
_this = _SVGElement.call(this, 'svg') || this; // Create svg element for holding the whole map
|
|
1749
|
+
|
|
1750
|
+
_this._container = container;
|
|
1751
|
+
|
|
1752
|
+
// Create the defs element
|
|
1753
|
+
_this._defsElement = new SVGElement('defs');
|
|
1754
|
+
|
|
1755
|
+
// Create group element which will hold the paths (regions)
|
|
1756
|
+
_this._rootElement = new SVGElement('g', {
|
|
1757
|
+
id: 'jvm-regions-group'
|
|
1758
|
+
});
|
|
1759
|
+
|
|
1760
|
+
// Append the defs element to the this.node (SVG tag)
|
|
1761
|
+
_this.node.appendChild(_this._defsElement.node);
|
|
1762
|
+
|
|
1763
|
+
// Append the group to this.node (SVG tag)
|
|
1764
|
+
_this.node.appendChild(_this._rootElement.node);
|
|
1765
|
+
|
|
1766
|
+
// Append this.node (SVG tag) to the container
|
|
1767
|
+
_this._container.appendChild(_this.node);
|
|
1768
|
+
return _this;
|
|
1769
|
+
}
|
|
1770
|
+
_inheritsLoose(SVGCanvasElement, _SVGElement);
|
|
1771
|
+
var _proto = SVGCanvasElement.prototype;
|
|
1772
|
+
_proto.setSize = function setSize(width, height) {
|
|
1773
|
+
this.node.setAttribute('width', width);
|
|
1774
|
+
this.node.setAttribute('height', height);
|
|
1775
|
+
};
|
|
1776
|
+
_proto.applyTransformParams = function applyTransformParams(scale, transX, transY) {
|
|
1777
|
+
this._rootElement.node.setAttribute('transform', "scale(" + scale + ") translate(" + transX + ", " + transY + ")");
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
// Create `path` element
|
|
1781
|
+
;
|
|
1782
|
+
_proto.createPath = function createPath(config, style, group) {
|
|
1783
|
+
var path = new SVGShapeElement('path', config, style);
|
|
1784
|
+
path.node.setAttribute('fill-rule', 'evenodd');
|
|
1785
|
+
return this._add(path, group);
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
// Create `circle` element
|
|
1789
|
+
;
|
|
1790
|
+
_proto.createCircle = function createCircle(config, style, group) {
|
|
1791
|
+
var circle = new SVGShapeElement('circle', config, style);
|
|
1792
|
+
return this._add(circle, group);
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
// Create `line` element
|
|
1796
|
+
;
|
|
1797
|
+
_proto.createLine = function createLine(config, style, group) {
|
|
1798
|
+
var line = new SVGShapeElement('line', config, style);
|
|
1799
|
+
return this._add(line, group);
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
// Create `text` element
|
|
1803
|
+
;
|
|
1804
|
+
_proto.createText = function createText(config, style, group) {
|
|
1805
|
+
var text = new SVGTextElement(config, style);
|
|
1806
|
+
return this._add(text, group);
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
// Create `image` element
|
|
1810
|
+
;
|
|
1811
|
+
_proto.createImage = function createImage(config, style, group) {
|
|
1812
|
+
var image = new SVGImageElement(config, style);
|
|
1813
|
+
return this._add(image, group);
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
// Create `g` element
|
|
1817
|
+
;
|
|
1818
|
+
_proto.createGroup = function createGroup(id) {
|
|
1819
|
+
var group = new SVGElement('g');
|
|
1820
|
+
this.node.appendChild(group.node);
|
|
1821
|
+
if (id) {
|
|
1822
|
+
group.node.id = id;
|
|
1823
|
+
}
|
|
1824
|
+
group.canvas = this;
|
|
1825
|
+
return group;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
// Add some element to a spcific group or the root element if the group isn't given
|
|
1829
|
+
;
|
|
1830
|
+
_proto._add = function _add(element, group) {
|
|
1831
|
+
group = group || this._rootElement;
|
|
1832
|
+
group.node.appendChild(element.node);
|
|
1833
|
+
return element;
|
|
1834
|
+
};
|
|
1835
|
+
return SVGCanvasElement;
|
|
1836
|
+
}(SVGElement);
|
|
1837
|
+
|
|
1838
|
+
var Tooltip = /*#__PURE__*/function (_BaseComponent) {
|
|
1839
|
+
function Tooltip(map) {
|
|
1840
|
+
var _this;
|
|
1841
|
+
_this = _BaseComponent.call(this) || this;
|
|
1842
|
+
var tooltip = createElement('div', 'jvm-tooltip');
|
|
1843
|
+
_this._map = map;
|
|
1844
|
+
_this._tooltip = document.body.appendChild(tooltip);
|
|
1845
|
+
_this._bindEventListeners();
|
|
1846
|
+
return _this || _assertThisInitialized(_this);
|
|
1847
|
+
}
|
|
1848
|
+
_inheritsLoose(Tooltip, _BaseComponent);
|
|
1849
|
+
var _proto = Tooltip.prototype;
|
|
1850
|
+
_proto._bindEventListeners = function _bindEventListeners() {
|
|
1851
|
+
var _this2 = this;
|
|
1852
|
+
EventHandler.on(this._map.container, 'mousemove', function (event) {
|
|
1853
|
+
if (!_this2._tooltip.classList.contains('active')) {
|
|
1854
|
+
return;
|
|
1855
|
+
}
|
|
1856
|
+
var container = findElement(_this2._map.container, '#jvm-regions-group').getBoundingClientRect();
|
|
1857
|
+
var space = 5; // Space between the cursor and tooltip element
|
|
1858
|
+
|
|
1859
|
+
// Tooltip
|
|
1860
|
+
var _this2$_tooltip$getBo = _this2._tooltip.getBoundingClientRect(),
|
|
1861
|
+
height = _this2$_tooltip$getBo.height,
|
|
1862
|
+
width = _this2$_tooltip$getBo.width;
|
|
1863
|
+
var topIsPassed = event.clientY <= container.top + height + space;
|
|
1864
|
+
var top = event.pageY - height - space;
|
|
1865
|
+
var left = event.pageX - width - space;
|
|
1866
|
+
|
|
1867
|
+
// Ensure the tooltip will never cross outside the canvas area(map)
|
|
1868
|
+
if (topIsPassed) {
|
|
1869
|
+
// Top:
|
|
1870
|
+
top += height + space;
|
|
1871
|
+
|
|
1872
|
+
// The cursor is a bit larger from left side
|
|
1873
|
+
left -= space * 2;
|
|
1874
|
+
}
|
|
1875
|
+
if (event.clientX < container.left + width + space) {
|
|
1876
|
+
// Left:
|
|
1877
|
+
left = event.pageX + space + 2;
|
|
1878
|
+
if (topIsPassed) {
|
|
1879
|
+
left += space * 2;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
_this2.css({
|
|
1883
|
+
top: top + "px",
|
|
1884
|
+
left: left + "px"
|
|
1885
|
+
});
|
|
1886
|
+
});
|
|
1887
|
+
};
|
|
1888
|
+
_proto.getElement = function getElement() {
|
|
1889
|
+
return this._tooltip;
|
|
1890
|
+
};
|
|
1891
|
+
_proto.show = function show() {
|
|
1892
|
+
this._tooltip.classList.add('active');
|
|
1893
|
+
};
|
|
1894
|
+
_proto.hide = function hide() {
|
|
1895
|
+
this._tooltip.classList.remove('active');
|
|
1896
|
+
};
|
|
1897
|
+
_proto.text = function text(string, html) {
|
|
1898
|
+
if (html === void 0) {
|
|
1899
|
+
html = false;
|
|
1900
|
+
}
|
|
1901
|
+
var property = html ? 'innerHTML' : 'textContent';
|
|
1902
|
+
if (!string) {
|
|
1903
|
+
return this._tooltip[property];
|
|
1904
|
+
}
|
|
1905
|
+
this._tooltip[property] = string;
|
|
1906
|
+
};
|
|
1907
|
+
_proto.css = function css(_css) {
|
|
1908
|
+
for (var style in _css) {
|
|
1909
|
+
this._tooltip.style[style] = _css[style];
|
|
1910
|
+
}
|
|
1911
|
+
return this;
|
|
1912
|
+
};
|
|
1913
|
+
return Tooltip;
|
|
1914
|
+
}(BaseComponent);
|
|
1915
|
+
|
|
1916
|
+
var DataVisualization = /*#__PURE__*/function () {
|
|
1917
|
+
function DataVisualization(_ref, map) {
|
|
1918
|
+
var scale = _ref.scale,
|
|
1919
|
+
values = _ref.values;
|
|
1920
|
+
this._scale = scale;
|
|
1921
|
+
this._values = values;
|
|
1922
|
+
this._fromColor = this.hexToRgb(scale[0]);
|
|
1923
|
+
this._toColor = this.hexToRgb(scale[1]);
|
|
1924
|
+
this._map = map;
|
|
1925
|
+
this.setMinMaxValues(values);
|
|
1926
|
+
this.visualize();
|
|
1927
|
+
}
|
|
1928
|
+
var _proto = DataVisualization.prototype;
|
|
1929
|
+
_proto.setMinMaxValues = function setMinMaxValues(values) {
|
|
1930
|
+
this.min = Number.MAX_VALUE;
|
|
1931
|
+
this.max = 0;
|
|
1932
|
+
for (var value in values) {
|
|
1933
|
+
value = parseFloat(values[value]);
|
|
1934
|
+
if (value > this.max) {
|
|
1935
|
+
this.max = value;
|
|
1936
|
+
}
|
|
1937
|
+
if (value < this.min) {
|
|
1938
|
+
this.min = value;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
};
|
|
1942
|
+
_proto.visualize = function visualize() {
|
|
1943
|
+
var attrs = {},
|
|
1944
|
+
value;
|
|
1945
|
+
for (var regionCode in this._values) {
|
|
1946
|
+
value = parseFloat(this._values[regionCode]);
|
|
1947
|
+
if (!isNaN(value)) {
|
|
1948
|
+
attrs[regionCode] = this.getValue(value);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
this.setAttributes(attrs);
|
|
1952
|
+
};
|
|
1953
|
+
_proto.setAttributes = function setAttributes(attrs) {
|
|
1954
|
+
for (var code in attrs) {
|
|
1955
|
+
if (this._map.regions[code]) {
|
|
1956
|
+
this._map.regions[code].element.setStyle('fill', attrs[code]);
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
_proto.getValue = function getValue(value) {
|
|
1961
|
+
if (this.min === this.max) {
|
|
1962
|
+
return "#" + this._toColor.join('');
|
|
1963
|
+
}
|
|
1964
|
+
var hex,
|
|
1965
|
+
color = '#';
|
|
1966
|
+
for (var i = 0; i < 3; i++) {
|
|
1967
|
+
hex = Math.round(this._fromColor[i] + (this._toColor[i] - this._fromColor[i]) * ((value - this.min) / (this.max - this.min))).toString(16);
|
|
1968
|
+
color += (hex.length === 1 ? '0' : '') + hex;
|
|
1969
|
+
}
|
|
1970
|
+
return color;
|
|
1971
|
+
};
|
|
1972
|
+
_proto.hexToRgb = function hexToRgb(h) {
|
|
1973
|
+
var r = 0,
|
|
1974
|
+
g = 0,
|
|
1975
|
+
b = 0;
|
|
1976
|
+
if (h.length == 4) {
|
|
1977
|
+
r = '0x' + h[1] + h[1];
|
|
1978
|
+
g = '0x' + h[2] + h[2];
|
|
1979
|
+
b = '0x' + h[3] + h[3];
|
|
1980
|
+
} else if (h.length == 7) {
|
|
1981
|
+
r = '0x' + h[1] + h[2];
|
|
1982
|
+
g = '0x' + h[3] + h[4];
|
|
1983
|
+
b = '0x' + h[5] + h[6];
|
|
1984
|
+
}
|
|
1985
|
+
return [parseInt(r), parseInt(g), parseInt(b)];
|
|
1986
|
+
};
|
|
1987
|
+
return DataVisualization;
|
|
1988
|
+
}();
|
|
1989
|
+
|
|
1990
|
+
var JVM_PREFIX = 'jvm-';
|
|
1991
|
+
var CONTAINER_CLASS = JVM_PREFIX + "container";
|
|
1992
|
+
var MARKERS_GROUP_ID = JVM_PREFIX + "markers-group";
|
|
1993
|
+
var MARKERS_LABELS_GROUP_ID = JVM_PREFIX + "markers-labels-group";
|
|
1994
|
+
var LINES_GROUP_ID = JVM_PREFIX + "lines-group";
|
|
1995
|
+
var SERIES_CONTAINER_CLASS = JVM_PREFIX + "series-container";
|
|
1996
|
+
var SERIES_CONTAINER_H_CLASS = SERIES_CONTAINER_CLASS + " " + JVM_PREFIX + "series-h";
|
|
1997
|
+
var SERIES_CONTAINER_V_CLASS = SERIES_CONTAINER_CLASS + " " + JVM_PREFIX + "series-v";
|
|
1998
|
+
var Map = /*#__PURE__*/function () {
|
|
1999
|
+
function Map(options) {
|
|
2000
|
+
var _this = this;
|
|
2001
|
+
if (options === void 0) {
|
|
2002
|
+
options = {};
|
|
2003
|
+
}
|
|
2004
|
+
// Merge the given options with the default options
|
|
2005
|
+
this.params = merge(Map.defaults, options, true);
|
|
2006
|
+
|
|
2007
|
+
// Throw an error if the given map name doesn't match
|
|
2008
|
+
// the map that was set in map file
|
|
2009
|
+
if (!Map.maps[this.params.map]) {
|
|
2010
|
+
throw new Error("Attempt to use map which was not loaded: " + options.map);
|
|
2011
|
+
}
|
|
2012
|
+
this.regions = {};
|
|
2013
|
+
this.scale = 1;
|
|
2014
|
+
this.transX = 0;
|
|
2015
|
+
this.transY = 0;
|
|
2016
|
+
this._mapData = Map.maps[this.params.map];
|
|
2017
|
+
this._markers = {};
|
|
2018
|
+
this._lines = {};
|
|
2019
|
+
this._defaultWidth = this._mapData.width;
|
|
2020
|
+
this._defaultHeight = this._mapData.height;
|
|
2021
|
+
this._height = 0;
|
|
2022
|
+
this._width = 0;
|
|
2023
|
+
this._baseScale = 1;
|
|
2024
|
+
this._baseTransX = 0;
|
|
2025
|
+
this._baseTransY = 0;
|
|
2026
|
+
|
|
2027
|
+
// `document` is already ready, just initialise now
|
|
2028
|
+
if (document.readyState !== 'loading') {
|
|
2029
|
+
this._init();
|
|
2030
|
+
} else {
|
|
2031
|
+
// Wait until `document` is ready
|
|
2032
|
+
window.addEventListener('DOMContentLoaded', function () {
|
|
2033
|
+
return _this._init();
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
var _proto = Map.prototype;
|
|
2038
|
+
_proto._init = function _init() {
|
|
2039
|
+
var options = this.params;
|
|
2040
|
+
this.container = getElement(options.selector);
|
|
2041
|
+
this.container.classList.add(CONTAINER_CLASS);
|
|
2042
|
+
|
|
2043
|
+
// The map canvas element
|
|
2044
|
+
this.canvas = new SVGCanvasElement(this.container);
|
|
2045
|
+
|
|
2046
|
+
// Set the map's background color
|
|
2047
|
+
this.setBackgroundColor(options.backgroundColor);
|
|
2048
|
+
|
|
2049
|
+
// Create regions
|
|
2050
|
+
this._createRegions();
|
|
2051
|
+
|
|
2052
|
+
// Update size
|
|
2053
|
+
this.updateSize();
|
|
2054
|
+
|
|
2055
|
+
// Lines group must be created before markers
|
|
2056
|
+
// Otherwise the lines will be drawn on top of the markers.
|
|
2057
|
+
if (options.lines) {
|
|
2058
|
+
this._linesGroup = this.canvas.createGroup(LINES_GROUP_ID);
|
|
2059
|
+
}
|
|
2060
|
+
if (options.markers) {
|
|
2061
|
+
this._markersGroup = this.canvas.createGroup(MARKERS_GROUP_ID);
|
|
2062
|
+
this._markerLabelsGroup = this.canvas.createGroup(MARKERS_LABELS_GROUP_ID);
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
// Create markers
|
|
2066
|
+
this._createMarkers(options.markers);
|
|
2067
|
+
|
|
2068
|
+
// Create lines
|
|
2069
|
+
this._createLines(options.lines || {});
|
|
2070
|
+
|
|
2071
|
+
// Position labels
|
|
2072
|
+
this._repositionLabels();
|
|
2073
|
+
|
|
2074
|
+
// Setup the container events
|
|
2075
|
+
this._setupContainerEvents();
|
|
2076
|
+
|
|
2077
|
+
// Setup regions/markers events
|
|
2078
|
+
this._setupElementEvents();
|
|
2079
|
+
|
|
2080
|
+
// Create zoom buttons if `zoomButtons` is presented
|
|
2081
|
+
if (options.zoomButtons) {
|
|
2082
|
+
this._setupZoomButtons();
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
// Create toolip
|
|
2086
|
+
if (options.showTooltip) {
|
|
2087
|
+
this._tooltip = new Tooltip(this);
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
// Set selected regions if any
|
|
2091
|
+
if (options.selectedRegions) {
|
|
2092
|
+
this._setSelected('regions', options.selectedRegions);
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
// Set selected regions if any
|
|
2096
|
+
if (options.selectedMarkers) {
|
|
2097
|
+
this._setSelected('_markers', options.selectedMarkers);
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
// Set focus on a spcific region
|
|
2101
|
+
if (options.focusOn) {
|
|
2102
|
+
this.setFocus(options.focusOn);
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
// Data visualization
|
|
2106
|
+
if (options.visualizeData) {
|
|
2107
|
+
this.dataVisualization = new DataVisualization(options.visualizeData, this);
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
// Bind touch events if true
|
|
2111
|
+
if (options.bindTouchEvents) {
|
|
2112
|
+
if ('ontouchstart' in window || window.DocumentTouch && document instanceof DocumentTouch) {
|
|
2113
|
+
this._setupContainerTouchEvents();
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
// Create series if any
|
|
2118
|
+
if (options.series) {
|
|
2119
|
+
this.container.appendChild(this.legendHorizontal = createElement('div', SERIES_CONTAINER_H_CLASS));
|
|
2120
|
+
this.container.appendChild(this.legendVertical = createElement('div', SERIES_CONTAINER_V_CLASS));
|
|
2121
|
+
this._createSeries();
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
// Fire loaded event
|
|
2125
|
+
this._emit(Events.onLoaded, [this]);
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
// Public
|
|
2129
|
+
;
|
|
2130
|
+
_proto.setBackgroundColor = function setBackgroundColor(color) {
|
|
2131
|
+
this.container.style.backgroundColor = color;
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
// Regions
|
|
2135
|
+
;
|
|
2136
|
+
_proto.getSelectedRegions = function getSelectedRegions() {
|
|
2137
|
+
return this._getSelected('regions');
|
|
2138
|
+
};
|
|
2139
|
+
_proto.clearSelectedRegions = function clearSelectedRegions(regions) {
|
|
2140
|
+
var _this2 = this;
|
|
2141
|
+
if (regions === void 0) {
|
|
2142
|
+
regions = undefined;
|
|
2143
|
+
}
|
|
2144
|
+
regions = this._normalizeRegions(regions) || this._getSelected('regions');
|
|
2145
|
+
regions.forEach(function (key) {
|
|
2146
|
+
_this2.regions[key].element.select(false);
|
|
2147
|
+
});
|
|
2148
|
+
};
|
|
2149
|
+
_proto.setSelectedRegions = function setSelectedRegions(regions) {
|
|
2150
|
+
this.clearSelectedRegions();
|
|
2151
|
+
this._setSelected('regions', this._normalizeRegions(regions));
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
// Markers
|
|
2155
|
+
;
|
|
2156
|
+
_proto.getSelectedMarkers = function getSelectedMarkers() {
|
|
2157
|
+
return this._getSelected('_markers');
|
|
2158
|
+
};
|
|
2159
|
+
_proto.clearSelectedMarkers = function clearSelectedMarkers() {
|
|
2160
|
+
this._clearSelected('_markers');
|
|
2161
|
+
};
|
|
2162
|
+
_proto.setSelectedMarkers = function setSelectedMarkers(markers) {
|
|
2163
|
+
this._setSelected('_markers', markers);
|
|
2164
|
+
};
|
|
2165
|
+
_proto.addMarkers = function addMarkers(config) {
|
|
2166
|
+
config = Array.isArray(config) ? config : [config];
|
|
2167
|
+
this._createMarkers(config, true);
|
|
2168
|
+
};
|
|
2169
|
+
_proto.removeMarkers = function removeMarkers(markers) {
|
|
2170
|
+
var _this3 = this;
|
|
2171
|
+
if (!markers) {
|
|
2172
|
+
markers = Object.keys(this._markers);
|
|
2173
|
+
}
|
|
2174
|
+
markers.forEach(function (index) {
|
|
2175
|
+
// Remove the element from the DOM
|
|
2176
|
+
_this3._markers[index].element.remove();
|
|
2177
|
+
// Remove the element from markers object
|
|
2178
|
+
delete _this3._markers[index];
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
// Lines
|
|
2183
|
+
;
|
|
2184
|
+
_proto.addLine = function addLine(from, to, style) {
|
|
2185
|
+
if (style === void 0) {
|
|
2186
|
+
style = {};
|
|
2187
|
+
}
|
|
2188
|
+
console.warn('`addLine` method is deprecated, please use `addLines` instead.');
|
|
2189
|
+
this._createLines([{
|
|
2190
|
+
from: from,
|
|
2191
|
+
to: to,
|
|
2192
|
+
style: style
|
|
2193
|
+
}], this._markers, true);
|
|
2194
|
+
};
|
|
2195
|
+
_proto.addLines = function addLines(config) {
|
|
2196
|
+
var uids = this._getLinesAsUids();
|
|
2197
|
+
if (!Array.isArray(config)) {
|
|
2198
|
+
config = [config];
|
|
2199
|
+
}
|
|
2200
|
+
this._createLines(config.filter(function (line) {
|
|
2201
|
+
return !(uids.indexOf(getLineUid(line.from, line.to)) > -1);
|
|
2202
|
+
}), true);
|
|
2203
|
+
};
|
|
2204
|
+
_proto.removeLines = function removeLines(lines) {
|
|
2205
|
+
var _this4 = this;
|
|
2206
|
+
if (Array.isArray(lines)) {
|
|
2207
|
+
lines = lines.map(function (line) {
|
|
2208
|
+
return getLineUid(line.from, line.to);
|
|
2209
|
+
});
|
|
2210
|
+
} else {
|
|
2211
|
+
lines = this._getLinesAsUids();
|
|
2212
|
+
}
|
|
2213
|
+
lines.forEach(function (uid) {
|
|
2214
|
+
_this4._lines[uid].dispose();
|
|
2215
|
+
delete _this4._lines[uid];
|
|
2216
|
+
});
|
|
2217
|
+
};
|
|
2218
|
+
_proto.removeLine = function removeLine(from, to) {
|
|
2219
|
+
console.warn('`removeLine` method is deprecated, please use `removeLines` instead.');
|
|
2220
|
+
var uid = getLineUid(from, to);
|
|
2221
|
+
if (this._lines.hasOwnProperty(uid)) {
|
|
2222
|
+
this._lines[uid].element.remove();
|
|
2223
|
+
delete this._lines[uid];
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
// Reset map
|
|
2228
|
+
;
|
|
2229
|
+
_proto.reset = function reset() {
|
|
2230
|
+
for (var key in this.series) {
|
|
2231
|
+
for (var i = 0; i < this.series[key].length; i++) {
|
|
2232
|
+
this.series[key][i].clear();
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
if (this.legendHorizontal) {
|
|
2236
|
+
removeElement(this.legendHorizontal);
|
|
2237
|
+
this.legendHorizontal = null;
|
|
2238
|
+
}
|
|
2239
|
+
if (this.legendVertical) {
|
|
2240
|
+
removeElement(this.legendVertical);
|
|
2241
|
+
this.legendVertical = null;
|
|
2242
|
+
}
|
|
2243
|
+
this.scale = this._baseScale;
|
|
2244
|
+
this.transX = this._baseTransX;
|
|
2245
|
+
this.transY = this._baseTransY;
|
|
2246
|
+
this._applyTransform();
|
|
2247
|
+
this.clearSelectedMarkers();
|
|
2248
|
+
this.clearSelectedRegions();
|
|
2249
|
+
this.removeMarkers();
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
// Destroy the map
|
|
2253
|
+
;
|
|
2254
|
+
_proto.destroy = function destroy(destroyInstance) {
|
|
2255
|
+
var _this5 = this;
|
|
2256
|
+
if (destroyInstance === void 0) {
|
|
2257
|
+
destroyInstance = true;
|
|
2258
|
+
}
|
|
2259
|
+
// Remove event registry
|
|
2260
|
+
EventHandler.flush();
|
|
2261
|
+
|
|
2262
|
+
// Remove tooltip from DOM and memory
|
|
2263
|
+
this._tooltip.dispose();
|
|
2264
|
+
|
|
2265
|
+
// Fire destroyed event
|
|
2266
|
+
this._emit(Events.onDestroyed);
|
|
2267
|
+
|
|
2268
|
+
// Remove references
|
|
2269
|
+
if (destroyInstance) {
|
|
2270
|
+
Object.keys(this).forEach(function (key) {
|
|
2271
|
+
try {
|
|
2272
|
+
delete _this5[key];
|
|
2273
|
+
} catch (e) {}
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
};
|
|
2277
|
+
_proto.extend = function extend(name, callback) {
|
|
2278
|
+
if (typeof this[name] === 'function') {
|
|
2279
|
+
throw new Error("The method [" + name + "] does already exist, please use another name.");
|
|
2280
|
+
}
|
|
2281
|
+
Map.prototype[name] = callback;
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
// Private
|
|
2285
|
+
;
|
|
2286
|
+
_proto._emit = function _emit(eventName, args) {
|
|
2287
|
+
for (var event in Events) {
|
|
2288
|
+
if (Events[event] === eventName && typeof this.params[event] === 'function') {
|
|
2289
|
+
this.params[event].apply(this, args);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
// Get selected markers/regions
|
|
2295
|
+
;
|
|
2296
|
+
_proto._getSelected = function _getSelected(type) {
|
|
2297
|
+
var selected = [];
|
|
2298
|
+
for (var key in this[type]) {
|
|
2299
|
+
if (this[type][key].element.isSelected) {
|
|
2300
|
+
selected.push(key);
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
return selected;
|
|
2304
|
+
};
|
|
2305
|
+
_proto._setSelected = function _setSelected(type, keys) {
|
|
2306
|
+
var _this6 = this;
|
|
2307
|
+
keys.forEach(function (key) {
|
|
2308
|
+
if (_this6[type][key]) {
|
|
2309
|
+
_this6[type][key].element.select(true);
|
|
2310
|
+
}
|
|
2311
|
+
});
|
|
2312
|
+
};
|
|
2313
|
+
_proto._clearSelected = function _clearSelected(type) {
|
|
2314
|
+
var _this7 = this;
|
|
2315
|
+
this._getSelected(type).forEach(function (key) {
|
|
2316
|
+
_this7[type][key].element.select(false);
|
|
2317
|
+
});
|
|
2318
|
+
};
|
|
2319
|
+
_proto._getLinesAsUids = function _getLinesAsUids() {
|
|
2320
|
+
return Object.keys(this._lines);
|
|
2321
|
+
};
|
|
2322
|
+
_proto._normalizeRegions = function _normalizeRegions(regions) {
|
|
2323
|
+
return typeof regions === 'string' ? [regions] : regions;
|
|
2324
|
+
};
|
|
2325
|
+
return Map;
|
|
2326
|
+
}();
|
|
2327
|
+
Map.maps = {};
|
|
2328
|
+
Map.defaults = Defaults;
|
|
2329
|
+
Object.assign(Map.prototype, core);
|
|
2330
|
+
|
|
2331
|
+
/**
|
|
2332
|
+
* jsVectorMap
|
|
2333
|
+
* Copyrights (c) Mustafa Omar https://github.com/themustafaomar
|
|
2334
|
+
* Released under the MIT License.
|
|
2335
|
+
*/
|
|
2336
|
+
var jsVectorMap = /*#__PURE__*/function () {
|
|
2337
|
+
function jsVectorMap(options) {
|
|
2338
|
+
if (options === void 0) {
|
|
2339
|
+
options = {};
|
|
2340
|
+
}
|
|
2341
|
+
if (!options.selector) {
|
|
2342
|
+
throw new Error('Selector is not given.');
|
|
2343
|
+
}
|
|
2344
|
+
return new Map(options);
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
// Public
|
|
2348
|
+
jsVectorMap.addMap = function addMap(name, map) {
|
|
2349
|
+
Map.maps[name] = map;
|
|
2350
|
+
};
|
|
2351
|
+
return jsVectorMap;
|
|
2352
|
+
}();
|
|
2353
|
+
var index = window.jsVectorMap = jsVectorMap;
|
|
2354
|
+
|
|
2355
|
+
module.exports = index;
|