@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,23 @@
|
|
|
1
|
+
import { merge } from '../util'
|
|
2
|
+
import Region from '../components/region'
|
|
3
|
+
|
|
4
|
+
export default function createRegions() {
|
|
5
|
+
this._regionLabelsGroup = this._regionLabelsGroup || this.canvas.createGroup('jvm-regions-labels-group')
|
|
6
|
+
|
|
7
|
+
for (const code in this._mapData.paths) {
|
|
8
|
+
const region = new Region({
|
|
9
|
+
map: this,
|
|
10
|
+
code: code,
|
|
11
|
+
path: this._mapData.paths[code].path,
|
|
12
|
+
style: merge({}, this.params.regionStyle),
|
|
13
|
+
labelStyle: this.params.regionLabelStyle,
|
|
14
|
+
labelsGroup: this._regionLabelsGroup,
|
|
15
|
+
label: this.params.labels && this.params.labels.regions,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
this.regions[code] = {
|
|
19
|
+
config: this._mapData.paths[code],
|
|
20
|
+
element: region,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import waypoints from "../../../../playground/data/waypoints"
|
|
2
|
+
import { Route } from "../components/route"
|
|
3
|
+
|
|
4
|
+
export default function createRoutes(routes) {
|
|
5
|
+
this._routes = {}
|
|
6
|
+
|
|
7
|
+
let index = 0
|
|
8
|
+
for (let route of routes) {
|
|
9
|
+
this._routes[route.name] = new Route({
|
|
10
|
+
map: this,
|
|
11
|
+
group: this._routesGroup,
|
|
12
|
+
waypoints: route.data,
|
|
13
|
+
index: index++,
|
|
14
|
+
}, {})
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Series from '../series'
|
|
2
|
+
|
|
3
|
+
export default function createSeries() {
|
|
4
|
+
this.series = { markers: [], regions: [] }
|
|
5
|
+
|
|
6
|
+
for (const key in this.params.series) {
|
|
7
|
+
for (let i = 0; i < this.params.series[key].length; i++) {
|
|
8
|
+
this.series[key][i] = new Series(
|
|
9
|
+
this.params.series[key][i], key === 'markers' ? this._markers : this.regions, this
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Map from '../map'
|
|
2
|
+
|
|
3
|
+
export default function getInsetForPoint(x, y) {
|
|
4
|
+
const insets = Map.maps[this.params.map].insets
|
|
5
|
+
|
|
6
|
+
for (let index = 0; index < insets.length; index++) {
|
|
7
|
+
const [start, end] = insets[index].bbox
|
|
8
|
+
|
|
9
|
+
if (x > start.x && x < end.x && y > start.y && y < end.y) {
|
|
10
|
+
return insets[index]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Map from '../map'
|
|
2
|
+
|
|
3
|
+
export default function getMarkerPosition({ coords }) {
|
|
4
|
+
if (Map.maps[this.params.map].projection) {
|
|
5
|
+
return this.coordsToPoint(...coords)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
x: coords[0] * this.scale + this.transX * this.scale,
|
|
10
|
+
y: coords[1] * this.scale + this.transY * this.scale
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import _setupContainerEvents from './setupContainerEvents'
|
|
2
|
+
import _setupElementEvents from './setupElementEvents'
|
|
3
|
+
import _setupZoomButtons from './setupZoomButtons'
|
|
4
|
+
import _setupContainerTouchEvents from './setupContainerTouchEvents'
|
|
5
|
+
import _createRegions from './createRegions'
|
|
6
|
+
import _createLines from './createLines'
|
|
7
|
+
import _createMarkers from './createMarkers'
|
|
8
|
+
import _createSeries from './createSeries'
|
|
9
|
+
import _applyTransform from './applyTransform'
|
|
10
|
+
import _resize from './resize'
|
|
11
|
+
import _setScale from './setScale'
|
|
12
|
+
import setFocus from './setFocus'
|
|
13
|
+
import updateSize from './updateSize'
|
|
14
|
+
import coordsToPoint from './coordsToPoint'
|
|
15
|
+
import getInsetForPoint from './getInsetForPoint'
|
|
16
|
+
import getMarkerPosition from './getMarkerPosition'
|
|
17
|
+
import _repositionLines from './repositionLines'
|
|
18
|
+
import _repositionMarkers from './repositionMarkers'
|
|
19
|
+
import _repositionLabels from './repositionLabels'
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
_setupContainerEvents,
|
|
23
|
+
_setupElementEvents,
|
|
24
|
+
_setupZoomButtons,
|
|
25
|
+
_setupContainerTouchEvents,
|
|
26
|
+
_createRegions,
|
|
27
|
+
_createLines,
|
|
28
|
+
_createMarkers,
|
|
29
|
+
_createSeries,
|
|
30
|
+
_applyTransform,
|
|
31
|
+
_resize,
|
|
32
|
+
_setScale,
|
|
33
|
+
setFocus,
|
|
34
|
+
updateSize,
|
|
35
|
+
coordsToPoint,
|
|
36
|
+
getInsetForPoint,
|
|
37
|
+
getMarkerPosition,
|
|
38
|
+
_repositionLines,
|
|
39
|
+
_repositionMarkers,
|
|
40
|
+
_repositionLabels,
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default function repositionLabels() {
|
|
2
|
+
const labels = this.params.labels
|
|
3
|
+
|
|
4
|
+
if (!labels) {
|
|
5
|
+
return
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Regions labels
|
|
9
|
+
if (labels.regions) {
|
|
10
|
+
for (const key in this.regions) {
|
|
11
|
+
this.regions[key].element.updateLabelPosition()
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Markers labels
|
|
16
|
+
if (labels.markers) {
|
|
17
|
+
for (const key in this._markers) {
|
|
18
|
+
this._markers[key].element.updateLabelPosition()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export default function repositionLines() {
|
|
2
|
+
const curvature = this.params.lineStyle.curvature
|
|
3
|
+
|
|
4
|
+
Object.values(this._lines).forEach((line) => {
|
|
5
|
+
const startMarker = Object.values(this._markers).find(
|
|
6
|
+
({ config }) => config.name === line.getConfig().from
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
const endMarker = Object.values(this._markers).find(
|
|
10
|
+
({ config }) => config.name === line.getConfig().to
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
if (startMarker && endMarker) {
|
|
14
|
+
const { x: x1, y: y1 } = this.getMarkerPosition(startMarker.config)
|
|
15
|
+
const { x: x2, y: y2 } = this.getMarkerPosition(endMarker.config)
|
|
16
|
+
const curvatureOption = line._options.curvature == 0
|
|
17
|
+
? 0
|
|
18
|
+
: line._options.curvature || curvature
|
|
19
|
+
|
|
20
|
+
const midX = (x1 + x2) / 2
|
|
21
|
+
const midY = (y1 + y2) / 2
|
|
22
|
+
const curveX = midX + curvatureOption * (y2 - y1)
|
|
23
|
+
const curveY = midY - curvatureOption * (x2 - x1)
|
|
24
|
+
|
|
25
|
+
line.setStyle({
|
|
26
|
+
d: `M${x1},${y1} Q${curveX},${curveY} ${x2},${y2}`,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default function repositionMarkers() {
|
|
2
|
+
for (const index in this._markers) {
|
|
3
|
+
const point = this.getMarkerPosition(this._markers[index].config)
|
|
4
|
+
|
|
5
|
+
if (point !== false) {
|
|
6
|
+
this._markers[index].element.setStyle({
|
|
7
|
+
cx: point.x, cy: point.y
|
|
8
|
+
})
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default function resize() {
|
|
2
|
+
const curBaseScale = this._baseScale
|
|
3
|
+
|
|
4
|
+
if (this._width / this._height > this._defaultWidth / this._defaultHeight) {
|
|
5
|
+
this._baseScale = this._height / this._defaultHeight
|
|
6
|
+
this._baseTransX = Math.abs(this._width - this._defaultWidth * this._baseScale) / (2 * this._baseScale)
|
|
7
|
+
} else {
|
|
8
|
+
this._baseScale = this._width / this._defaultWidth
|
|
9
|
+
this._baseTransY = Math.abs(this._height - this._defaultHeight * this._baseScale) / (2 * this._baseScale)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
this.scale *= this._baseScale / curBaseScale
|
|
13
|
+
this.transX *= this._baseScale / curBaseScale
|
|
14
|
+
this.transY *= this._baseScale / curBaseScale
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export default function setFocus(config = {}) {
|
|
2
|
+
let bbox, codes = []
|
|
3
|
+
|
|
4
|
+
if (config.region) {
|
|
5
|
+
codes.push(config.region)
|
|
6
|
+
} else if (config.regions) {
|
|
7
|
+
codes = config.regions
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (codes.length) {
|
|
11
|
+
codes.forEach((code) => {
|
|
12
|
+
if (this.regions[code]) {
|
|
13
|
+
let itemBbox = this.regions[code].element.shape.getBBox()
|
|
14
|
+
|
|
15
|
+
if (itemBbox) {
|
|
16
|
+
// Handle the first loop
|
|
17
|
+
if (typeof bbox == 'undefined') {
|
|
18
|
+
bbox = itemBbox
|
|
19
|
+
} else {
|
|
20
|
+
// get the old bbox properties plus the current
|
|
21
|
+
// this kinda incrementing the old values and the new values
|
|
22
|
+
bbox = {
|
|
23
|
+
x: Math.min(bbox.x, itemBbox.x),
|
|
24
|
+
y: Math.min(bbox.y, itemBbox.y),
|
|
25
|
+
width: Math.max(bbox.x + bbox.width, itemBbox.x + itemBbox.width) - Math.min(bbox.x, itemBbox.x),
|
|
26
|
+
height: Math.max(bbox.y + bbox.height, itemBbox.y + itemBbox.height) - Math.min(bbox.y, itemBbox.y),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return this._setScale(
|
|
34
|
+
Math.min(this._width / bbox.width, this._height / bbox.height),
|
|
35
|
+
-(bbox.x + bbox.width / 2),
|
|
36
|
+
-(bbox.y + bbox.height / 2),
|
|
37
|
+
true,
|
|
38
|
+
config.animate,
|
|
39
|
+
)
|
|
40
|
+
} else if (config.coords) {
|
|
41
|
+
const point = this.coordsToPoint(config.coords[0], config.coords[1])
|
|
42
|
+
const x = this.transX - point.x / this.scale
|
|
43
|
+
const y = this.transY - point.y / this.scale
|
|
44
|
+
return this._setScale(config.scale * this._baseScale, x, y, true, config.animate)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Events from '../defaults/events'
|
|
2
|
+
|
|
3
|
+
export default function setScale(scale, anchorX, anchorY, isCentered, animate) {
|
|
4
|
+
let zoomStep,
|
|
5
|
+
interval,
|
|
6
|
+
i = 0,
|
|
7
|
+
count = Math.abs(Math.round((scale - this.scale) * 60 / Math.max(scale, this.scale))),
|
|
8
|
+
scaleStart,
|
|
9
|
+
scaleDiff,
|
|
10
|
+
transXStart,
|
|
11
|
+
transXDiff,
|
|
12
|
+
transYStart,
|
|
13
|
+
transYDiff,
|
|
14
|
+
transX,
|
|
15
|
+
transY
|
|
16
|
+
|
|
17
|
+
if (scale > this.params.zoomMax * this._baseScale) {
|
|
18
|
+
scale = this.params.zoomMax * this._baseScale
|
|
19
|
+
} else if (scale < this.params.zoomMin * this._baseScale) {
|
|
20
|
+
scale = this.params.zoomMin * this._baseScale
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof anchorX != 'undefined' && typeof anchorY != 'undefined') {
|
|
24
|
+
zoomStep = scale / this.scale
|
|
25
|
+
if (isCentered) {
|
|
26
|
+
transX = anchorX + this._defaultWidth * (this._width / (this._defaultWidth * scale)) / 2
|
|
27
|
+
transY = anchorY + this._defaultHeight * (this._height / (this._defaultHeight * scale)) / 2
|
|
28
|
+
} else {
|
|
29
|
+
transX = this.transX - (zoomStep - 1) / scale * anchorX
|
|
30
|
+
transY = this.transY - (zoomStep - 1) / scale * anchorY
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (animate && count > 0) {
|
|
35
|
+
scaleStart = this.scale
|
|
36
|
+
scaleDiff = (scale - scaleStart) / count
|
|
37
|
+
transXStart = this.transX * this.scale
|
|
38
|
+
transYStart = this.transY * this.scale
|
|
39
|
+
transXDiff = (transX * scale - transXStart) / count
|
|
40
|
+
transYDiff = (transY * scale - transYStart) / count
|
|
41
|
+
interval = setInterval(() => {
|
|
42
|
+
i += 1
|
|
43
|
+
this.scale = scaleStart + scaleDiff * i
|
|
44
|
+
this.transX = (transXStart + transXDiff * i) / this.scale
|
|
45
|
+
this.transY = (transYStart + transYDiff * i) / this.scale
|
|
46
|
+
this._applyTransform()
|
|
47
|
+
if (i == count) {
|
|
48
|
+
clearInterval(interval)
|
|
49
|
+
|
|
50
|
+
this._emit(Events.onViewportChange, [
|
|
51
|
+
this.scale, this.transX, this.transY
|
|
52
|
+
])
|
|
53
|
+
}
|
|
54
|
+
}, 10)
|
|
55
|
+
} else {
|
|
56
|
+
this.transX = transX
|
|
57
|
+
this.transY = transY
|
|
58
|
+
this.scale = scale
|
|
59
|
+
|
|
60
|
+
this._applyTransform()
|
|
61
|
+
this._emit(Events.onViewportChange, [
|
|
62
|
+
this.scale, this.transX, this.transY
|
|
63
|
+
])
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import EventHandler from '../eventHandler'
|
|
2
|
+
|
|
3
|
+
export default function setupContainerEvents() {
|
|
4
|
+
const map = this
|
|
5
|
+
let mouseDown = false
|
|
6
|
+
let oldPageX
|
|
7
|
+
let oldPageY
|
|
8
|
+
|
|
9
|
+
if (this.params.draggable) {
|
|
10
|
+
EventHandler.on(this.container, 'mousemove', (e) => {
|
|
11
|
+
if (!mouseDown) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
map.transX -= (oldPageX - e.pageX) / map.scale
|
|
16
|
+
map.transY -= (oldPageY - e.pageY) / map.scale
|
|
17
|
+
map._applyTransform()
|
|
18
|
+
oldPageX = e.pageX
|
|
19
|
+
oldPageY = e.pageY
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
EventHandler.on(this.container, 'mousedown', (e) => {
|
|
23
|
+
mouseDown = true
|
|
24
|
+
oldPageX = e.pageX
|
|
25
|
+
oldPageY = e.pageY
|
|
26
|
+
return false
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
EventHandler.on(document.body, 'mouseup', () => {
|
|
30
|
+
mouseDown = false
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (this.params.zoomOnScroll) {
|
|
35
|
+
EventHandler.on(this.container, 'wheel', event => {
|
|
36
|
+
const deltaY = (((event.deltaY || -event.wheelDelta || event.detail) >> 10) || 1) * 75
|
|
37
|
+
const rect = this.container.getBoundingClientRect()
|
|
38
|
+
const offsetX = event.pageX - rect.left - window.scrollX
|
|
39
|
+
const offsetY = event.pageY - rect.top - window.scrollY
|
|
40
|
+
const zoomStep = Math.pow(1 + (map.params.zoomOnScrollSpeed / 1000), -1.5 * deltaY)
|
|
41
|
+
|
|
42
|
+
if (map.tooltip) {
|
|
43
|
+
map._tooltip.hide()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
map._setScale(map.scale * zoomStep, offsetX, offsetY)
|
|
47
|
+
event.preventDefault()
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import EventHandler from '../eventHandler'
|
|
2
|
+
|
|
3
|
+
export default function setupContainerTouchEvents() {
|
|
4
|
+
let map = this,
|
|
5
|
+
touchStartScale,
|
|
6
|
+
touchStartDistance,
|
|
7
|
+
touchX,
|
|
8
|
+
touchY,
|
|
9
|
+
centerTouchX,
|
|
10
|
+
centerTouchY,
|
|
11
|
+
lastTouchesLength
|
|
12
|
+
|
|
13
|
+
let handleTouchEvent = e => {
|
|
14
|
+
const touches = e.touches
|
|
15
|
+
let offset, scale, transXOld, transYOld
|
|
16
|
+
|
|
17
|
+
if (e.type == 'touchstart') {
|
|
18
|
+
lastTouchesLength = 0
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (touches.length == 1) {
|
|
22
|
+
if (lastTouchesLength == 1) {
|
|
23
|
+
transXOld = map.transX
|
|
24
|
+
transYOld = map.transY
|
|
25
|
+
map.transX -= (touchX - touches[0].pageX) / map.scale
|
|
26
|
+
map.transY -= (touchY - touches[0].pageY) / map.scale
|
|
27
|
+
|
|
28
|
+
map._tooltip?.hide()
|
|
29
|
+
map._applyTransform()
|
|
30
|
+
|
|
31
|
+
if (transXOld != map.transX || transYOld != map.transY) {
|
|
32
|
+
e.preventDefault()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
touchX = touches[0].pageX
|
|
37
|
+
touchY = touches[0].pageY
|
|
38
|
+
} else if (touches.length == 2) {
|
|
39
|
+
if (lastTouchesLength == 2) {
|
|
40
|
+
scale = Math.sqrt(
|
|
41
|
+
Math.pow(touches[0].pageX - touches[1].pageX, 2) +
|
|
42
|
+
Math.pow(touches[0].pageY - touches[1].pageY, 2)
|
|
43
|
+
) / touchStartDistance
|
|
44
|
+
|
|
45
|
+
map._setScale(touchStartScale * scale, centerTouchX, centerTouchY)
|
|
46
|
+
|
|
47
|
+
map._tooltip?.hide()
|
|
48
|
+
e.preventDefault()
|
|
49
|
+
} else {
|
|
50
|
+
let rect = map.container.getBoundingClientRect()
|
|
51
|
+
|
|
52
|
+
offset = {
|
|
53
|
+
top: rect.top + window.scrollY,
|
|
54
|
+
left: rect.left + window.scrollX,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (touches[0].pageX > touches[1].pageX) {
|
|
58
|
+
centerTouchX = touches[1].pageX + (touches[0].pageX - touches[1].pageX) / 2
|
|
59
|
+
} else {
|
|
60
|
+
centerTouchX = touches[0].pageX + (touches[1].pageX - touches[0].pageX) / 2
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (touches[0].pageY > touches[1].pageY) {
|
|
64
|
+
centerTouchY = touches[1].pageY + (touches[0].pageY - touches[1].pageY) / 2
|
|
65
|
+
} else {
|
|
66
|
+
centerTouchY = touches[0].pageY + (touches[1].pageY - touches[0].pageY) / 2
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
centerTouchX -= offset.left
|
|
70
|
+
centerTouchY -= offset.top
|
|
71
|
+
touchStartScale = map.scale
|
|
72
|
+
|
|
73
|
+
touchStartDistance = Math.sqrt(
|
|
74
|
+
Math.pow(touches[0].pageX - touches[1].pageX, 2) +
|
|
75
|
+
Math.pow(touches[0].pageY - touches[1].pageY, 2)
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
lastTouchesLength = touches.length
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
EventHandler.on(map.container, 'touchstart', handleTouchEvent)
|
|
84
|
+
EventHandler.on(map.container, 'touchmove', handleTouchEvent)
|
|
85
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { getElement } from '../util'
|
|
2
|
+
import EventHandler from '../eventHandler'
|
|
3
|
+
import Events from '../defaults/events'
|
|
4
|
+
|
|
5
|
+
const parseEvent = (map, selector, isTooltip) => {
|
|
6
|
+
const element = getElement(selector)
|
|
7
|
+
const type = element.getAttribute('class').indexOf('jvm-region') === -1 ? 'marker' : 'region'
|
|
8
|
+
const isRegion = type === 'region'
|
|
9
|
+
const code = isRegion ? element.getAttribute('data-code') : element.getAttribute('data-index')
|
|
10
|
+
let event = isRegion ? Events.onRegionSelected : Events.onMarkerSelected
|
|
11
|
+
|
|
12
|
+
// Init tooltip event
|
|
13
|
+
if (isTooltip) {
|
|
14
|
+
event = isRegion ? Events.onRegionTooltipShow : Events.onMarkerTooltipShow
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
type,
|
|
19
|
+
code,
|
|
20
|
+
event,
|
|
21
|
+
element: isRegion ? map.regions[code].element : map._markers[code].element,
|
|
22
|
+
tooltipText: isRegion ? map._mapData.paths[code].name || '' : (map._markers[code].config.name || '')
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default function setupElementEvents() {
|
|
27
|
+
const map = this
|
|
28
|
+
const container = this.container
|
|
29
|
+
let pageX, pageY, mouseMoved
|
|
30
|
+
|
|
31
|
+
EventHandler.on(container, 'mousemove', (event) => {
|
|
32
|
+
if (Math.abs(pageX - event.pageX) + Math.abs(pageY - event.pageY) > 2) {
|
|
33
|
+
mouseMoved = true
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// When the mouse is pressed
|
|
38
|
+
EventHandler.delegate(container, 'mousedown', '.jvm-element', (event) => {
|
|
39
|
+
pageX = event.pageX
|
|
40
|
+
pageY = event.pageY
|
|
41
|
+
mouseMoved = false
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// When the mouse is over the region/marker | When the mouse is out the region/marker
|
|
45
|
+
EventHandler.delegate(container, 'mouseover mouseout', '.jvm-element', function (event) {
|
|
46
|
+
const data = parseEvent(map, this, true)
|
|
47
|
+
const { showTooltip } = map.params
|
|
48
|
+
|
|
49
|
+
if (event.type === 'mouseover') {
|
|
50
|
+
data.element.hover(true)
|
|
51
|
+
|
|
52
|
+
if (showTooltip) {
|
|
53
|
+
map._tooltip.text(data.tooltipText)
|
|
54
|
+
map._emit(data.event, [event, map._tooltip, data.code])
|
|
55
|
+
if (!event.defaultPrevented) {
|
|
56
|
+
map._tooltip.show()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
data.element.hover(false)
|
|
61
|
+
|
|
62
|
+
if (showTooltip) {
|
|
63
|
+
map._tooltip.hide()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// When the click is released
|
|
69
|
+
EventHandler.delegate(container, 'mouseup', '.jvm-element', function (event) {
|
|
70
|
+
const data = parseEvent(map, this)
|
|
71
|
+
|
|
72
|
+
if (mouseMoved) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
(data.type === 'region' && map.params.regionsSelectable) ||
|
|
78
|
+
(data.type === 'marker' && map.params.markersSelectable)
|
|
79
|
+
) {
|
|
80
|
+
const element = data.element
|
|
81
|
+
|
|
82
|
+
// We're checking if regions/markers|SelectableOne option is presented
|
|
83
|
+
if (map.params[`${data.type}sSelectableOne`]) {
|
|
84
|
+
data.type === 'region' ? map.clearSelectedRegions() : map.clearSelectedMarkers()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (data.element.isSelected) {
|
|
88
|
+
element.select(false)
|
|
89
|
+
} else {
|
|
90
|
+
element.select(true)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
map._emit(data.event, [
|
|
94
|
+
data.code,
|
|
95
|
+
element.isSelected,
|
|
96
|
+
data.type === 'region'
|
|
97
|
+
? map.getSelectedRegions()
|
|
98
|
+
: map.getSelectedMarkers()
|
|
99
|
+
])
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
// When region/marker is clicked
|
|
104
|
+
EventHandler.delegate(container, 'click', '.jvm-element', function (event) {
|
|
105
|
+
const { type, code } = parseEvent(map, this)
|
|
106
|
+
|
|
107
|
+
map._emit(
|
|
108
|
+
type === 'region' ? Events.onRegionClick : Events.onMarkerClick,
|
|
109
|
+
[event, code]
|
|
110
|
+
)
|
|
111
|
+
})
|
|
112
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createElement } from '../util'
|
|
2
|
+
import EventHandler from '../eventHandler'
|
|
3
|
+
|
|
4
|
+
export default function setupZoomButtons() {
|
|
5
|
+
const zoomInOption = this.params.zoomInButton
|
|
6
|
+
const zoomOutOption = this.params.zoomOutButton
|
|
7
|
+
|
|
8
|
+
const getZoomButton = (zoomOption) => typeof zoomOption === 'string'
|
|
9
|
+
? document.querySelector(zoomOption)
|
|
10
|
+
: zoomOption
|
|
11
|
+
|
|
12
|
+
const zoomIn = zoomInOption
|
|
13
|
+
? getZoomButton(zoomInOption)
|
|
14
|
+
: createElement('div', 'jvm-zoom-btn jvm-zoomin', '+', true)
|
|
15
|
+
|
|
16
|
+
const zoomOut = zoomOutOption
|
|
17
|
+
? getZoomButton(zoomOutOption)
|
|
18
|
+
: createElement('div', 'jvm-zoom-btn jvm-zoomout', '−', true)
|
|
19
|
+
|
|
20
|
+
if (!zoomInOption) {
|
|
21
|
+
this.container.appendChild(zoomIn)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!zoomOutOption) {
|
|
25
|
+
this.container.appendChild(zoomOut)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const handler = (zoomin = true) => {
|
|
29
|
+
return () => this._setScale(
|
|
30
|
+
zoomin ? this.scale * this.params.zoomStep : this.scale / this.params.zoomStep,
|
|
31
|
+
this._width / 2,
|
|
32
|
+
this._height / 2,
|
|
33
|
+
false,
|
|
34
|
+
this.params.zoomAnimate
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
EventHandler.on(zoomIn, 'click', handler())
|
|
39
|
+
EventHandler.on(zoomOut, 'click', handler(false))
|
|
40
|
+
}
|