-
Notifications
You must be signed in to change notification settings - Fork 432
/
Copy pathZoomableGeo.js
56 lines (49 loc) · 1.13 KB
/
ZoomableGeo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React, { useContext } from "react"
import PropTypes from "prop-types"
import { MapContext } from "./MapProvider"
import useZoomGeo from "./useZoomGeo"
const ZoomableGeo = ({
bounds = null,
boundsMargin = 0.1,
duration = 750,
minZoom = 1,
maxZoom = 8,
onMoveStart,
onMove,
onMoveEnd,
className,
...restProps
}) => {
const { width, height } = useContext(MapContext)
const {
mapRef,
transformString,
style
} = useZoomGeo({
bounds,
boundsMargin,
duration,
onMoveStart,
onMove,
onMoveEnd,
scaleExtent: [minZoom, maxZoom],
});
return (
<g ref={mapRef}>
<rect width={width} height={height} fill="transparent" />
<g transform={transformString} style={style} className={`rsm-zoomable-geo ${className}`} {...restProps} />
</g>
)
}
ZoomableGeo.propTypes = {
bounds: PropTypes.object,
boundsMargin: PropTypes.number,
duration: PropTypes.number,
minZoom: PropTypes.number,
maxZoom: PropTypes.number,
onMoveStart: PropTypes.func,
onMove: PropTypes.func,
onMoveEnd: PropTypes.func,
className: PropTypes.string,
}
export default ZoomableGeo