ts-maps 0.0.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/README.md +284 -0
- package/dist/apply-transform.d.ts +47 -0
- package/dist/base-element.d.ts +5 -0
- package/dist/base.d.ts +19 -0
- package/dist/brasil.d.ts +1 -0
- package/dist/canada.d.ts +1 -0
- package/dist/canvas-element.d.ts +8 -0
- package/dist/coords-to-point.d.ts +26 -0
- package/dist/create-lines.d.ts +39 -0
- package/dist/create-markers.d.ts +51 -0
- package/dist/create-regions.d.ts +19 -0
- package/dist/create-series.d.ts +20 -0
- package/dist/data-visualization.d.ts +99 -0
- package/dist/deep-merge.d.ts +44 -0
- package/dist/event-handler.d.ts +12 -0
- package/dist/events.d.ts +14 -0
- package/dist/get-inset-for-point.d.ts +24 -0
- package/dist/get-marker-position.d.ts +15 -0
- package/dist/image-element.d.ts +7 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +2027 -0
- package/dist/interactable.d.ts +7 -0
- package/dist/italy.d.ts +1 -0
- package/dist/legend.d.ts +6 -0
- package/dist/line.d.ts +29 -0
- package/dist/map.d.ts +422 -0
- package/dist/marker.d.ts +31 -0
- package/dist/options.d.ts +5 -0
- package/dist/ordinal-scale.d.ts +32 -0
- package/dist/projection.d.ts +18 -0
- package/dist/region.d.ts +21 -0
- package/dist/reposition-labels.d.ts +27 -0
- package/dist/reposition-lines.d.ts +32 -0
- package/dist/reposition-markers.d.ts +26 -0
- package/dist/resize.d.ts +5 -0
- package/dist/series.d.ts +4 -0
- package/dist/set-focus.d.ts +58 -0
- package/dist/set-scale.d.ts +80 -0
- package/dist/setup-container-events.d.ts +48 -0
- package/dist/setup-container-touch-events.d.ts +68 -0
- package/dist/setup-element-events.d.ts +125 -0
- package/dist/setup-zoom-buttons.d.ts +21 -0
- package/dist/shape-element.d.ts +10 -0
- package/dist/spain.d.ts +1 -0
- package/dist/text-element.d.ts +1 -0
- package/dist/tooltip.d.ts +80 -0
- package/dist/types.d.ts +398 -0
- package/dist/update-size.d.ts +6 -0
- package/dist/us-aea-en.d.ts +266 -0
- package/dist/us-lcc-en.d.ts +266 -0
- package/dist/us-merc-en.d.ts +266 -0
- package/dist/us-mill-en.d.ts +266 -0
- package/dist/utils.d.ts +21 -0
- package/dist/vector-map.d.ts +15 -0
- package/dist/world-merc.d.ts +1 -0
- package/dist/world.d.ts +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
declare interface BBox {
|
|
2
|
+
x: number
|
|
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
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export default function setScale(
|
|
2
|
+
this: MapInterface,
|
|
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 = this.transX
|
|
20
|
+
let transY = 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
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export default function setupContainerEvents(this: MapInterface): void {
|
|
2
|
+
let mouseDown = false
|
|
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
|
+
this.canvas.applyTransformParams(this.scale, this.transX, this.transY)
|
|
17
|
+
}
|
|
18
|
+
oldPageX = mouseEvent.pageX
|
|
19
|
+
oldPageY = mouseEvent.pageY
|
|
20
|
+
}) as EventListener)
|
|
21
|
+
|
|
22
|
+
EventHandler.on(this.container, 'mousedown', ((e) => {
|
|
23
|
+
mouseDown = true
|
|
24
|
+
const mouseEvent = e as MouseEvent
|
|
25
|
+
oldPageX = mouseEvent.pageX
|
|
26
|
+
oldPageY = mouseEvent.pageY
|
|
27
|
+
return false
|
|
28
|
+
}) as EventListener)
|
|
29
|
+
|
|
30
|
+
EventHandler.on(document.body, 'mouseup', () => {
|
|
31
|
+
mouseDown = false
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (this.params.zoomOnScroll) {
|
|
36
|
+
EventHandler.on(this.container, 'wheel', ((e) => {
|
|
37
|
+
const wheelEvent = e as WheelEvent
|
|
38
|
+
const deltaY = (((wheelEvent.deltaY || 0) >> 10) || 1) * 75
|
|
39
|
+
const rect = this.container.getBoundingClientRect()
|
|
40
|
+
const offsetX = wheelEvent.pageX - rect.left - window.scrollX
|
|
41
|
+
const offsetY = wheelEvent.pageY - rect.top - window.scrollY
|
|
42
|
+
const zoomStep = (1 + ((this.params.zoomOnScrollSpeed || 3) / 1000)) ** (-1.5 * deltaY)
|
|
43
|
+
|
|
44
|
+
setScale.call(this, this.scale * zoomStep, offsetX, offsetY)
|
|
45
|
+
e.preventDefault()
|
|
46
|
+
}) as EventListener)
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export default function setupContainerTouchEvents(this: MapInterface): void {
|
|
2
|
+
let touchStartScale = 1
|
|
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
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
const { showTooltip } = this.params
|
|
43
|
+
const tooltip = this._tooltip
|
|
44
|
+
|
|
45
|
+
if (e.type === 'mouseover') {
|
|
46
|
+
if (typeof data.element.hover === 'function') {
|
|
47
|
+
data.element.hover(true)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (showTooltip && tooltip) {
|
|
51
|
+
tooltip.text(data.tooltipText)
|
|
52
|
+
tooltip.show(data.tooltipText)
|
|
53
|
+
this._emit(data.event, [e, tooltip.getElement(), data.code])
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
if (typeof data.element.hover === 'function') {
|
|
58
|
+
data.element.hover(false)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (showTooltip && tooltip) {
|
|
62
|
+
tooltip.hide()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error('Error in mouseover/mouseout handler:', error)
|
|
68
|
+
}
|
|
69
|
+
}) as EventListener)
|
|
70
|
+
|
|
71
|
+
EventHandler.delegate(container, 'mouseup', '.jvm-element', ((e: Event) => {
|
|
72
|
+
try {
|
|
73
|
+
const data = parseEvent(this, (e.target as Element), false)
|
|
74
|
+
|
|
75
|
+
if (mouseMoved) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
(data.type === 'region' && this.params.regionsSelectable)
|
|
81
|
+
|| (data.type === 'marker' && this.params.markersSelectable)
|
|
82
|
+
) {
|
|
83
|
+
const element = data.element
|
|
84
|
+
|
|
85
|
+
if (this.params[`${data.type}sSelectableOne`]) {
|
|
86
|
+
data.type === 'region' ? this.clearSelectedRegions() : this.clearSelectedMarkers()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (typeof element.select === 'function') {
|
|
90
|
+
if (element.isSelected) {
|
|
91
|
+
element.select(false)
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
element.select(true)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this._emit(data.event, [
|
|
98
|
+
data.code,
|
|
99
|
+
element.isSelected,
|
|
100
|
+
data.type === 'region'
|
|
101
|
+
? this.getSelectedRegions()
|
|
102
|
+
: this.getSelectedMarkers(),
|
|
103
|
+
])
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error('Error in mouseup handler:', error)
|
|
109
|
+
}
|
|
110
|
+
}) as EventListener)
|
|
111
|
+
|
|
112
|
+
EventHandler.delegate(container, 'click', '.jvm-element', ((e: Event) => {
|
|
113
|
+
try {
|
|
114
|
+
const { type, code } = parseEvent(this, (e.target as Element), false)
|
|
115
|
+
|
|
116
|
+
this._emit(
|
|
117
|
+
type === 'region' ? Events.onRegionClick : Events.onMarkerClick,
|
|
118
|
+
[e, code],
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error('Error in click handler:', error)
|
|
123
|
+
}
|
|
124
|
+
}) as EventListener)
|
|
125
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default function setupZoomButtons(this: MapInterface): void {
|
|
2
|
+
const zoomin = createElement('div', 'jvm-zoom-btn jvm-zoomin', '+', true)
|
|
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
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare interface ShapeStyle {
|
|
2
|
+
initial: Record<string, string | number>
|
|
3
|
+
current?: Record<string, string | number>
|
|
4
|
+
hover?: Record<string, string | number>
|
|
5
|
+
selected?: Record<string, string | number>
|
|
6
|
+
selectedHover?: Record<string, string | number>
|
|
7
|
+
}
|
|
8
|
+
declare const attrs: Record<string, string | number>;
|
|
9
|
+
|
|
10
|
+
export default SVGShapeElement;
|
package/dist/spain.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default spain;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default SVGTextElement;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { MapInterface } from '../types';
|
|
2
|
+
|
|
3
|
+
export declare class Tooltip extends BaseComponent {
|
|
4
|
+
private _map: MapInterface
|
|
5
|
+
protected _tooltip: HTMLElement
|
|
6
|
+
private _hoveredRegion: string | null = null
|
|
7
|
+
private _hoveredMarker: string | null = null
|
|
8
|
+
private _customPositioning: boolean = true
|
|
9
|
+
|
|
10
|
+
constructor(map: MapInterface) {
|
|
11
|
+
super()
|
|
12
|
+
|
|
13
|
+
this._map = map
|
|
14
|
+
this._tooltip = createElement('div', 'jvm-tooltip', '')
|
|
15
|
+
this._tooltip.style.display = 'none'
|
|
16
|
+
this._map.container.appendChild(this._tooltip)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
return this
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getElement(): HTMLElement {
|
|
23
|
+
return this._tooltip
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
show(text: string): void {
|
|
27
|
+
this._tooltip.style.display = 'block'
|
|
28
|
+
this._tooltip.innerHTML = text
|
|
29
|
+
this._tooltip.classList.add('active')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
hide(): void {
|
|
33
|
+
this._tooltip.style.display = 'none'
|
|
34
|
+
this._tooltip.classList.remove('active')
|
|
35
|
+
this._hoveredRegion = null
|
|
36
|
+
this._hoveredMarker = null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
text(text: string): void {
|
|
40
|
+
if (this._tooltip) {
|
|
41
|
+
this._tooltip.innerHTML = text
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
html(html: string): void {
|
|
46
|
+
if (this._tooltip) {
|
|
47
|
+
this._tooltip.innerHTML = html
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
css(css: Record<string, string>): this {
|
|
52
|
+
if (this._customPositioning && (css.top || css.left)) {
|
|
53
|
+
return this
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
for (const style in css) {
|
|
57
|
+
this._tooltip.style[style as any] = css[style]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setHoveredRegion(code: string): void {
|
|
64
|
+
this._hoveredRegion = code
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getHoveredRegion(): string | null {
|
|
68
|
+
return this._hoveredRegion
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setHoveredMarker(index: string): void {
|
|
72
|
+
this._hoveredMarker = index
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getHoveredMarker(): string | null {
|
|
76
|
+
return this._hoveredMarker
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default Tooltip;
|