ts-maps 0.2.5 → 0.2.6
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/dist/components/base.d.ts +5 -7
- package/dist/components/concerns/interactable.d.ts +0 -6
- package/dist/components/line.d.ts +11 -11
- package/dist/components/marker.d.ts +24 -5
- package/dist/components/region.d.ts +28 -3
- package/dist/components/tooltip.d.ts +18 -76
- package/dist/core/apply-transform.d.ts +7 -47
- package/dist/core/coords-to-point.d.ts +9 -25
- package/dist/core/create-lines.d.ts +2 -39
- package/dist/core/create-markers.d.ts +2 -50
- package/dist/core/create-regions.d.ts +2 -22
- package/dist/core/create-series.d.ts +2 -19
- package/dist/core/get-inset-for-point.d.ts +3 -30
- package/dist/core/get-marker-position.d.ts +3 -12
- package/dist/core/index.d.ts +0 -23
- package/dist/core/reposition-labels.d.ts +2 -23
- package/dist/core/reposition-lines.d.ts +2 -32
- package/dist/core/reposition-markers.d.ts +2 -23
- package/dist/core/resize.d.ts +0 -2
- package/dist/core/set-focus.d.ts +2 -58
- package/dist/core/set-scale.d.ts +2 -80
- package/dist/core/setup-container-events.d.ts +2 -49
- package/dist/core/setup-container-touch-events.d.ts +2 -68
- package/dist/core/setup-element-events.d.ts +1 -131
- package/dist/core/setup-zoom-buttons.d.ts +2 -21
- package/dist/core/update-size.d.ts +2 -7
- package/dist/data-visualization.d.ts +14 -96
- package/dist/defaults/events.d.ts +0 -13
- package/dist/defaults/options.d.ts +0 -4
- package/dist/event-handler.d.ts +0 -11
- package/dist/index.d.ts +2 -10
- package/dist/legend.d.ts +8 -5
- package/dist/map.d.ts +78 -425
- package/dist/maps/brasil.d.ts +1 -0
- package/dist/maps/canada.d.ts +1 -0
- package/dist/maps/iraq.d.ts +0 -3
- package/dist/maps/italy.d.ts +1 -0
- package/dist/maps/russia.d.ts +0 -3
- package/dist/maps/spain.d.ts +1 -0
- package/dist/maps/us-aea-en.d.ts +0 -3
- package/dist/maps/us-lcc-en.d.ts +0 -3
- package/dist/maps/us-merc-en.d.ts +0 -3
- package/dist/maps/us-mill-en.d.ts +0 -3
- package/dist/maps/world-merc.d.ts +1 -0
- package/dist/maps/world.d.ts +1 -0
- package/dist/projection.d.ts +0 -17
- package/dist/scales/ordinal-scale.d.ts +4 -24
- package/dist/series.d.ts +13 -3
- package/dist/svg/base-element.d.ts +16 -2
- package/dist/svg/canvas-element.d.ts +20 -7
- package/dist/svg/image-element.d.ts +10 -5
- package/dist/svg/shape-element.d.ts +11 -2
- package/dist/svg/text-element.d.ts +6 -0
- package/dist/types.d.ts +32 -17
- package/dist/util/deep-merge.d.ts +1 -43
- package/dist/util/index.d.ts +6 -13
- package/dist/utils.d.ts +67 -3
- package/dist/vector-map.d.ts +2 -12
- package/package.json +1 -2
package/dist/core/set-focus.d.ts
CHANGED
|
@@ -1,58 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
y: number
|
|
4
|
-
width: number
|
|
5
|
-
height: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default function setFocus(this: MapInterface, config: FocusOnOptions = {}): void {
|
|
9
|
-
let bbox: BBox | undefined
|
|
10
|
-
let codes: string[] = []
|
|
11
|
-
|
|
12
|
-
if (config.region) {
|
|
13
|
-
codes.push(config.region)
|
|
14
|
-
}
|
|
15
|
-
else if (config.regions) {
|
|
16
|
-
codes = config.regions
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (codes.length) {
|
|
20
|
-
codes.forEach((code) => {
|
|
21
|
-
if (this.regions[code]) {
|
|
22
|
-
const itemBbox = this.regions[code].element.shape.getBBox()
|
|
23
|
-
|
|
24
|
-
if (itemBbox) {
|
|
25
|
-
if (typeof bbox === 'undefined') {
|
|
26
|
-
bbox = itemBbox
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
bbox = {
|
|
30
|
-
x: Math.min(bbox.x, itemBbox.x),
|
|
31
|
-
y: Math.min(bbox.y, itemBbox.y),
|
|
32
|
-
width: Math.max(bbox.x + bbox.width, itemBbox.x + itemBbox.width) - Math.min(bbox.x, itemBbox.x),
|
|
33
|
-
height: Math.max(bbox.y + bbox.height, itemBbox.y + itemBbox.height) - Math.min(bbox.y, itemBbox.y),
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
if (bbox) {
|
|
41
|
-
return this._setScale(
|
|
42
|
-
Math.min(this._width / bbox.width, this._height / bbox.height),
|
|
43
|
-
-(bbox.x + bbox.width / 2),
|
|
44
|
-
-(bbox.y + bbox.height / 2),
|
|
45
|
-
true,
|
|
46
|
-
config.animate,
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else if (config.coords) {
|
|
51
|
-
const point = this.coordsToPoint(config.coords[0], config.coords[1])
|
|
52
|
-
if (point) {
|
|
53
|
-
const x = this.transX - point.x / this.scale
|
|
54
|
-
const y = this.transY - point.y / this.scale
|
|
55
|
-
return this._setScale(config.scale ? config.scale * this._baseScale : this._baseScale, x, y, true, config.animate)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
1
|
+
import type { FocusOnOptions, MapInterface } from '../types';
|
|
2
|
+
export declare function setFocus(this: MapInterface, config?: FocusOnOptions): void;
|
package/dist/core/set-scale.d.ts
CHANGED
|
@@ -1,80 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
scale: number,
|
|
4
|
-
anchorX: number,
|
|
5
|
-
anchorY: number,
|
|
6
|
-
isCentered?: boolean,
|
|
7
|
-
animate?: boolean,
|
|
8
|
-
): void {
|
|
9
|
-
let zoomStep: number
|
|
10
|
-
let interval: ReturnType<typeof setInterval>
|
|
11
|
-
let i = 0
|
|
12
|
-
const count = Math.abs(Math.round((scale - this.scale) * 60 / Math.max(scale, this.scale)))
|
|
13
|
-
let scaleStart: number
|
|
14
|
-
let scaleDiff: number
|
|
15
|
-
let transXStart: number
|
|
16
|
-
let transXDiff: number
|
|
17
|
-
let transYStart: number
|
|
18
|
-
let transYDiff: number
|
|
19
|
-
let transX: number = this.transX
|
|
20
|
-
let transY: number = this.transY
|
|
21
|
-
|
|
22
|
-
const zoomMax = this.params.zoomMax ?? 8
|
|
23
|
-
const zoomMin = this.params.zoomMin ?? 1
|
|
24
|
-
|
|
25
|
-
if (scale > zoomMax * this._baseScale) {
|
|
26
|
-
scale = zoomMax * this._baseScale
|
|
27
|
-
}
|
|
28
|
-
else if (scale < zoomMin * this._baseScale) {
|
|
29
|
-
scale = zoomMin * this._baseScale
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (typeof anchorX !== 'undefined' && typeof anchorY !== 'undefined') {
|
|
33
|
-
zoomStep = scale / this.scale
|
|
34
|
-
if (isCentered) {
|
|
35
|
-
transX = anchorX + this._defaultWidth * (this._width / (this._defaultWidth * scale)) / 2
|
|
36
|
-
transY = anchorY + this._defaultHeight * (this._height / (this._defaultHeight * scale)) / 2
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
transX = this.transX - (zoomStep - 1) / scale * anchorX
|
|
40
|
-
transY = this.transY - (zoomStep - 1) / scale * anchorY
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (animate && count > 0) {
|
|
45
|
-
scaleStart = this.scale
|
|
46
|
-
scaleDiff = (scale - scaleStart) / count
|
|
47
|
-
transXStart = this.transX * this.scale
|
|
48
|
-
transYStart = this.transY * this.scale
|
|
49
|
-
transXDiff = (transX * scale - transXStart) / count
|
|
50
|
-
transYDiff = (transY * scale - transYStart) / count
|
|
51
|
-
interval = setInterval(() => {
|
|
52
|
-
i += 1
|
|
53
|
-
this.scale = scaleStart + scaleDiff * i
|
|
54
|
-
this.transX = (transXStart + transXDiff * i) / this.scale
|
|
55
|
-
this.transY = (transYStart + transYDiff * i) / this.scale
|
|
56
|
-
this._applyTransform()
|
|
57
|
-
if (i === count) {
|
|
58
|
-
clearInterval(interval)
|
|
59
|
-
|
|
60
|
-
this._emit(Events.onViewportChange, [
|
|
61
|
-
this.scale,
|
|
62
|
-
this.transX,
|
|
63
|
-
this.transY,
|
|
64
|
-
])
|
|
65
|
-
}
|
|
66
|
-
}, 10)
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
this.transX = transX
|
|
70
|
-
this.transY = transY
|
|
71
|
-
this.scale = scale
|
|
72
|
-
|
|
73
|
-
this._applyTransform()
|
|
74
|
-
this._emit(Events.onViewportChange, [
|
|
75
|
-
this.scale,
|
|
76
|
-
this.transX,
|
|
77
|
-
this.transY,
|
|
78
|
-
])
|
|
79
|
-
}
|
|
80
|
-
};
|
|
1
|
+
import type { MapInterface } from '../types';
|
|
2
|
+
export declare function setScale(this: MapInterface, scale: number, anchorX: number, anchorY: number, isCentered?: boolean, animate?: boolean): void;
|
|
@@ -1,49 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let oldPageX: number | undefined
|
|
4
|
-
let oldPageY: number | undefined
|
|
5
|
-
|
|
6
|
-
if (this.params.draggable) {
|
|
7
|
-
EventHandler.on(this.container, 'mousemove', ((e) => {
|
|
8
|
-
if (!mouseDown) {
|
|
9
|
-
return false
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const mouseEvent = e as MouseEvent
|
|
13
|
-
if (oldPageX !== undefined && oldPageY !== undefined) {
|
|
14
|
-
this.transX -= (oldPageX - mouseEvent.pageX) / this.scale
|
|
15
|
-
this.transY -= (oldPageY - mouseEvent.pageY) / this.scale
|
|
16
|
-
|
|
17
|
-
this._applyTransform()
|
|
18
|
-
}
|
|
19
|
-
oldPageX = mouseEvent.pageX
|
|
20
|
-
oldPageY = mouseEvent.pageY
|
|
21
|
-
}) as EventListener)
|
|
22
|
-
|
|
23
|
-
EventHandler.on(this.container, 'mousedown', ((e) => {
|
|
24
|
-
mouseDown = true
|
|
25
|
-
const mouseEvent = e as MouseEvent
|
|
26
|
-
oldPageX = mouseEvent.pageX
|
|
27
|
-
oldPageY = mouseEvent.pageY
|
|
28
|
-
return false
|
|
29
|
-
}) as EventListener)
|
|
30
|
-
|
|
31
|
-
EventHandler.on(document.body, 'mouseup', () => {
|
|
32
|
-
mouseDown = false
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (this.params.zoomOnScroll) {
|
|
37
|
-
EventHandler.on(this.container, 'wheel', ((e) => {
|
|
38
|
-
const wheelEvent = e as WheelEvent
|
|
39
|
-
const deltaY = (((wheelEvent.deltaY || 0) >> 10) || 1) * 75
|
|
40
|
-
const rect = this.container.getBoundingClientRect()
|
|
41
|
-
const offsetX = wheelEvent.pageX - rect.left - window.scrollX
|
|
42
|
-
const offsetY = wheelEvent.pageY - rect.top - window.scrollY
|
|
43
|
-
const zoomStep = (1 + ((this.params.zoomOnScrollSpeed || 3) / 1000)) ** (-1.5 * deltaY)
|
|
44
|
-
|
|
45
|
-
setScale.call(this, this.scale * zoomStep, offsetX, offsetY)
|
|
46
|
-
e.preventDefault()
|
|
47
|
-
}) as EventListener)
|
|
48
|
-
}
|
|
49
|
-
};
|
|
1
|
+
import type { MapInterface } from '../types';
|
|
2
|
+
export declare function setupContainerEvents(this: MapInterface): void;
|
|
@@ -1,68 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let touchStartDistance = 0
|
|
4
|
-
let centerTouchX = 0
|
|
5
|
-
let centerTouchY = 0
|
|
6
|
-
let lastTouchesLength = 0
|
|
7
|
-
let touchStartX = 0
|
|
8
|
-
let touchStartY = 0
|
|
9
|
-
let offset = { top: 0, left: 0 }
|
|
10
|
-
|
|
11
|
-
const handleTouchEvent = (e: TouchEvent) => {
|
|
12
|
-
const touches = e.touches
|
|
13
|
-
let currentScale = this.scale
|
|
14
|
-
|
|
15
|
-
if (touches.length === 1) {
|
|
16
|
-
if (lastTouchesLength === 1) {
|
|
17
|
-
const touch = touches[0]
|
|
18
|
-
if (touchStartScale === currentScale) {
|
|
19
|
-
this.transX -= (touchStartX - touch.pageX) / currentScale
|
|
20
|
-
this.transY -= (touchStartY - touch.pageY) / currentScale
|
|
21
|
-
this.canvas.applyTransformParams(currentScale, this.transX, this.transY)
|
|
22
|
-
}
|
|
23
|
-
touchStartX = touch.pageX
|
|
24
|
-
touchStartY = touch.pageY
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else if (touches.length === 2) {
|
|
28
|
-
if (lastTouchesLength === 2) {
|
|
29
|
-
currentScale = Math.sqrt(
|
|
30
|
-
(touches[0].pageX - touches[1].pageX) ** 2
|
|
31
|
-
+ (touches[0].pageY - touches[1].pageY) ** 2,
|
|
32
|
-
) / touchStartDistance
|
|
33
|
-
|
|
34
|
-
setScale.call(this, touchStartScale * currentScale, centerTouchX, centerTouchY, false, false)
|
|
35
|
-
e.preventDefault()
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
const rect = this.container.getBoundingClientRect()
|
|
39
|
-
offset = {
|
|
40
|
-
top: rect.top + window.scrollY,
|
|
41
|
-
left: rect.left + window.scrollX,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
centerTouchX = touches[0].pageX > touches[1].pageX
|
|
45
|
-
? touches[1].pageX + (touches[0].pageX - touches[1].pageX) / 2
|
|
46
|
-
: touches[0].pageX + (touches[1].pageX - touches[0].pageX) / 2
|
|
47
|
-
|
|
48
|
-
centerTouchY = touches[0].pageY > touches[1].pageY
|
|
49
|
-
? touches[1].pageY + (touches[0].pageY - touches[1].pageY) / 2
|
|
50
|
-
: touches[0].pageY + (touches[1].pageY - touches[0].pageY) / 2
|
|
51
|
-
|
|
52
|
-
centerTouchX -= offset.left
|
|
53
|
-
centerTouchY -= offset.top
|
|
54
|
-
touchStartScale = this.scale
|
|
55
|
-
|
|
56
|
-
touchStartDistance = Math.sqrt(
|
|
57
|
-
(touches[0].pageX - touches[1].pageX) ** 2
|
|
58
|
-
+ (touches[0].pageY - touches[1].pageY) ** 2,
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
lastTouchesLength = touches.length
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
EventHandler.on(this.container, 'touchstart', handleTouchEvent as EventListener)
|
|
67
|
-
EventHandler.on(this.container, 'touchmove', handleTouchEvent as EventListener)
|
|
68
|
-
};
|
|
1
|
+
import type { MapInterface } from '../types';
|
|
2
|
+
export declare function setupContainerTouchEvents(this: MapInterface): void;
|
|
@@ -1,132 +1,2 @@
|
|
|
1
1
|
import type { MapInterface } from '../types';
|
|
2
|
-
|
|
3
|
-
declare interface ElementWithInteraction {
|
|
4
|
-
hover?: (state: boolean) => void
|
|
5
|
-
select?: (state: boolean) => void
|
|
6
|
-
isSelected?: boolean
|
|
7
|
-
isHovered?: boolean
|
|
8
|
-
shape?: any
|
|
9
|
-
}
|
|
10
|
-
declare interface ParseEventResult {
|
|
11
|
-
type: 'region' | 'marker'
|
|
12
|
-
code: string
|
|
13
|
-
event: string
|
|
14
|
-
element: ElementWithInteraction
|
|
15
|
-
tooltipText: string
|
|
16
|
-
}
|
|
17
|
-
declare function parseEvent(map: MapInterface, selector: Element | string, isTooltip?: boolean): ParseEventResult;
|
|
18
|
-
|
|
19
|
-
export default function setupElementEvents(this: MapInterface): void {
|
|
20
|
-
const container = this.container
|
|
21
|
-
let pageX: number | undefined
|
|
22
|
-
let pageY: number | undefined
|
|
23
|
-
let mouseMoved = false
|
|
24
|
-
|
|
25
|
-
EventHandler.on(container, 'mousemove', ((e: Event) => {
|
|
26
|
-
const mouseEvent = e as MouseEvent
|
|
27
|
-
if (Math.abs((pageX || 0) - mouseEvent.pageX) + Math.abs((pageY || 0) - mouseEvent.pageY) > 2) {
|
|
28
|
-
mouseMoved = true
|
|
29
|
-
}
|
|
30
|
-
}) as EventListener)
|
|
31
|
-
|
|
32
|
-
EventHandler.delegate(container, 'mousedown', '.jvm-element', ((e: Event) => {
|
|
33
|
-
const mouseEvent = e as MouseEvent
|
|
34
|
-
pageX = mouseEvent.pageX
|
|
35
|
-
pageY = mouseEvent.pageY
|
|
36
|
-
mouseMoved = false
|
|
37
|
-
}) as EventListener)
|
|
38
|
-
|
|
39
|
-
EventHandler.delegate(container, 'mouseover mouseout', '.jvm-element', ((e: Event) => {
|
|
40
|
-
try {
|
|
41
|
-
const data = parseEvent(this, (e.target as Element), true)
|
|
42
|
-
|
|
43
|
-
const { showTooltip } = this.params
|
|
44
|
-
const tooltip = this._tooltip
|
|
45
|
-
|
|
46
|
-
if (e.type === 'mouseover') {
|
|
47
|
-
if (typeof data.element.hover === 'function') {
|
|
48
|
-
data.element.hover(true)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (showTooltip && tooltip) {
|
|
52
|
-
this._emit(data.event, [data.event, tooltip, data.code])
|
|
53
|
-
if (!e.defaultPrevented) {
|
|
54
|
-
tooltip.show(data.tooltipText)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
if (typeof data.element.hover === 'function') {
|
|
60
|
-
data.element.hover(false)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (showTooltip && tooltip) {
|
|
64
|
-
tooltip.hide()
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
const errorMessage = error instanceof Error ? error.message : String(error)
|
|
70
|
-
console.warn('Skipping mouseover/mouseout event due to error:', errorMessage)
|
|
71
|
-
if (e.type === 'mouseout' && this._tooltip) {
|
|
72
|
-
this._tooltip.hide()
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}) as EventListener)
|
|
76
|
-
|
|
77
|
-
EventHandler.delegate(container, 'mouseup', '.jvm-element', ((e: Event) => {
|
|
78
|
-
try {
|
|
79
|
-
const data = parseEvent(this, (e.target as Element), false)
|
|
80
|
-
|
|
81
|
-
if (mouseMoved) {
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
(data.type === 'region' && this.params.regionsSelectable)
|
|
87
|
-
|| (data.type === 'marker' && this.params.markersSelectable)
|
|
88
|
-
) {
|
|
89
|
-
const element = data.element
|
|
90
|
-
|
|
91
|
-
if (this.params[`${data.type}sSelectableOne`]) {
|
|
92
|
-
data.type === 'region' ? this.clearSelectedRegions() : this.clearSelectedMarkers()
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (typeof element.select === 'function') {
|
|
96
|
-
if (element.isSelected) {
|
|
97
|
-
element.select(false)
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
element.select(true)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
this._emit(data.event, [
|
|
104
|
-
data.event,
|
|
105
|
-
data.code,
|
|
106
|
-
element.isSelected,
|
|
107
|
-
data.type === 'region'
|
|
108
|
-
? this.getSelectedRegions()
|
|
109
|
-
: this.getSelectedMarkers(),
|
|
110
|
-
])
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
console.error('Error in mouseup handler:', error)
|
|
116
|
-
}
|
|
117
|
-
}) as EventListener)
|
|
118
|
-
|
|
119
|
-
EventHandler.delegate(container, 'click', '.jvm-element', ((e: Event) => {
|
|
120
|
-
try {
|
|
121
|
-
const { type, code } = parseEvent(this, (e.target as Element), false)
|
|
122
|
-
|
|
123
|
-
this._emit(
|
|
124
|
-
type === 'region' ? Events.onRegionClick : Events.onMarkerClick,
|
|
125
|
-
[e, code],
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
console.error('Error in click handler:', error)
|
|
130
|
-
}
|
|
131
|
-
}) as EventListener)
|
|
132
|
-
};
|
|
2
|
+
export declare function setupElementEvents(this: MapInterface): void;
|
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const zoomout = createElement('div', 'jvm-zoom-btn jvm-zoomout', '−', true)
|
|
4
|
-
|
|
5
|
-
this.container.appendChild(zoomin)
|
|
6
|
-
this.container.appendChild(zoomout)
|
|
7
|
-
|
|
8
|
-
const handler = (zoomin = true) => {
|
|
9
|
-
return () => setScale.call(
|
|
10
|
-
this,
|
|
11
|
-
zoomin ? this.scale * (this.params.zoomStep || 1.5) : this.scale / (this.params.zoomStep || 1.5),
|
|
12
|
-
this._width / 2,
|
|
13
|
-
this._height / 2,
|
|
14
|
-
false,
|
|
15
|
-
this.params.zoomAnimate,
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
EventHandler.on(zoomin, 'click', handler())
|
|
20
|
-
EventHandler.on(zoomout, 'click', handler(false))
|
|
21
|
-
};
|
|
1
|
+
import type { MapInterface } from '../types';
|
|
2
|
+
export declare function setupZoomButtons(this: MapInterface): void;
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
this._height = this.container.offsetHeight
|
|
4
|
-
resize.call(this)
|
|
5
|
-
this.canvas.setSize(this._width, this._height)
|
|
6
|
-
this._applyTransform()
|
|
7
|
-
};
|
|
1
|
+
import type { MapInterface } from '../types';
|
|
2
|
+
export declare function updateSize(this: MapInterface): void;
|
|
@@ -1,99 +1,17 @@
|
|
|
1
1
|
import type { DataVisualizationOptions, MapInterface } from './types';
|
|
2
|
-
|
|
3
2
|
export declare class DataVisualization {
|
|
4
|
-
private _scale: [string, string]
|
|
5
|
-
private _values: Record<string, number | string
|
|
6
|
-
private _fromColor: number[]
|
|
7
|
-
private _toColor: number[]
|
|
8
|
-
private _map: MapInterface
|
|
9
|
-
private min: number
|
|
10
|
-
private max: number
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this._map = map
|
|
18
|
-
|
|
19
|
-
this.setMinMaxValues(values)
|
|
20
|
-
this.visualize()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
setMinMaxValues(values: Record<string, number | string>): void {
|
|
24
|
-
for (const key in values) {
|
|
25
|
-
const value = Number.parseFloat(String(values[key]))
|
|
26
|
-
|
|
27
|
-
if (value > this.max) {
|
|
28
|
-
this.max = value
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (value < this.min) {
|
|
32
|
-
this.min = value
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
visualize(): void {
|
|
38
|
-
const attrs: Record<string, string> = {}
|
|
39
|
-
let value: number
|
|
40
|
-
|
|
41
|
-
for (const regionCode in this._values) {
|
|
42
|
-
value = Number.parseFloat(String(this._values[regionCode]))
|
|
43
|
-
|
|
44
|
-
if (!Number.isNaN(value)) {
|
|
45
|
-
attrs[regionCode] = this.getValue(value)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.setAttributes(attrs)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
setAttributes(attrs: Record<string, string>): void {
|
|
53
|
-
for (const code in attrs) {
|
|
54
|
-
if (this._map.regions[code]) {
|
|
55
|
-
this._map.regions[code].element.setStyle('fill', attrs[code])
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getValue(value: number): string {
|
|
61
|
-
if (this.min === this.max) {
|
|
62
|
-
return `#${this._toColor.join('')}`
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let hex: string
|
|
66
|
-
let color = '#'
|
|
67
|
-
|
|
68
|
-
for (let i = 0; i < 3; i++) {
|
|
69
|
-
hex = Math.round(
|
|
70
|
-
this._fromColor[i] + (this._toColor[i] - this._fromColor[i]) * ((value - this.min) / (this.max - this.min)),
|
|
71
|
-
).toString(16)
|
|
72
|
-
|
|
73
|
-
color += (hex.length === 1 ? '0' : '') + hex
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return color
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
hexToRgb(h: string): number[] {
|
|
80
|
-
let r: string = '0'
|
|
81
|
-
let g: string = '0'
|
|
82
|
-
let b: string = '0'
|
|
83
|
-
|
|
84
|
-
if (h.length === 4) {
|
|
85
|
-
r = `0x${h[1]}${h[1]}`
|
|
86
|
-
g = `0x${h[2]}${h[2]}`
|
|
87
|
-
b = `0x${h[3]}${h[3]}`
|
|
88
|
-
}
|
|
89
|
-
else if (h.length === 7) {
|
|
90
|
-
r = `0x${h[1]}${h[2]}`
|
|
91
|
-
g = `0x${h[3]}${h[4]}`
|
|
92
|
-
b = `0x${h[5]}${h[6]}`
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return [Number.parseInt(r, 16), Number.parseInt(g, 16), Number.parseInt(b, 16)]
|
|
96
|
-
}
|
|
3
|
+
private _scale: [string, string];
|
|
4
|
+
private _values: Record<string, number | string>;
|
|
5
|
+
private _fromColor: number[];
|
|
6
|
+
private _toColor: number[];
|
|
7
|
+
private _map: MapInterface;
|
|
8
|
+
private min: number;
|
|
9
|
+
private max: number;
|
|
10
|
+
constructor({ scale, values }: DataVisualizationOptions, map: MapInterface);
|
|
11
|
+
setMinMaxValues(values: Record<string, number | string>): void;
|
|
12
|
+
visualize(): void;
|
|
13
|
+
setAttributes(attrs: Record<string, string>): void;
|
|
14
|
+
getValue(value: number): string;
|
|
15
|
+
hexToRgb(h: string): number[];
|
|
97
16
|
}
|
|
98
|
-
|
|
99
|
-
export default DataVisualization
|
|
17
|
+
export default DataVisualization;
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
declare interface Events {
|
|
2
|
-
onLoaded: string
|
|
3
|
-
onViewportChange: string
|
|
4
|
-
onRegionClick: string
|
|
5
|
-
onMarkerClick: string
|
|
6
|
-
onRegionSelected: string
|
|
7
|
-
onMarkerSelected: string
|
|
8
|
-
onRegionTooltipShow: string
|
|
9
|
-
onMarkerTooltipShow: string
|
|
10
|
-
onDestroyed: string
|
|
11
|
-
}
|
|
12
|
-
declare const events: Events;
|
|
13
|
-
|
|
14
1
|
export default events;
|
package/dist/event-handler.d.ts
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
import type { EventRegistry } from './types';
|
|
2
|
-
|
|
3
|
-
declare let eventRegistry: EventRegistry;
|
|
4
|
-
declare const EventHandler: {
|
|
5
|
-
on: (element: HTMLElement, event: string, handler: EventListenerOrEventListenerObject, options: AddEventListenerOptions) => void;
|
|
6
|
-
delegate: (element: HTMLElement, event: string, selector: string, handler: (e: Event) => void;
|
|
7
|
-
off: (element: HTMLElement, event: string, handler: EventListenerOrEventListenerObject) => void;
|
|
8
|
-
flush: () => void;
|
|
9
|
-
getEventRegistry: () => void
|
|
10
|
-
};
|
|
11
|
-
|
|
12
1
|
export default EventHandler;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { VectorMap } from './vector-map';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { VectorMap }
|
|
5
|
-
|
|
6
|
-
export * from './types'
|
|
7
|
-
|
|
8
|
-
if (typeof window !== 'undefined') {
|
|
9
|
-
window.VectorMap = VectorMap
|
|
10
|
-
}
|
|
11
|
-
|
|
2
|
+
export * from './types';
|
|
3
|
+
export { VectorMap };
|
|
12
4
|
export default VectorMap;
|
package/dist/legend.d.ts
CHANGED
|
@@ -6,9 +6,12 @@ declare interface LegendOptions {
|
|
|
6
6
|
title?: string
|
|
7
7
|
labelRender?: (label: string) => string
|
|
8
8
|
}
|
|
9
|
-
declare
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
declare class Legend {
|
|
10
|
+
private _options: LegendOptions;
|
|
11
|
+
private _map: any;
|
|
12
|
+
private _series: any;
|
|
13
|
+
private _body: HTMLElement;
|
|
14
|
+
constructor(options?: LegendOptions);
|
|
15
|
+
render(): void;
|
|
16
|
+
}
|
|
14
17
|
export default Legend;
|