forked from PaulLeCam/react-leaflet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoOverlay.js
58 lines (51 loc) · 1.65 KB
/
VideoOverlay.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
57
58
// @flow
import { VideoOverlay as LeafletVideoOverlay, latLngBounds } from 'leaflet'
import { withLeaflet } from './context'
import MapLayer from './MapLayer'
import type { LatLngBounds, MapLayerProps } from './types'
type LeafletElement = LeafletVideoOverlay
type Props = {
attribution?: string,
bounds: LatLngBounds,
opacity?: number,
play?: boolean,
url: string | string[] | HTMLVideoElement,
zIndex?: number,
} & MapLayerProps
class VideoOverlay extends MapLayer<LeafletElement, Props> {
createLeafletElement(props: Props): LeafletElement {
return new LeafletVideoOverlay(
props.url,
props.bounds,
this.getOptions(props),
)
}
componentDidMount() {
super.componentDidMount()
if (this.props.play === true) {
this.leafletElement.getElement().play()
}
}
updateLeafletElement(fromProps: Props, toProps: Props) {
if (toProps.url !== fromProps.url) {
this.leafletElement.setUrl(toProps.url)
}
if (toProps.bounds !== fromProps.bounds) {
this.leafletElement.setBounds(latLngBounds(toProps.bounds))
}
if (toProps.opacity !== fromProps.opacity) {
this.leafletElement.setOpacity(toProps.opacity)
}
if (toProps.zIndex !== fromProps.zIndex) {
this.leafletElement.setZIndex(toProps.zIndex)
}
// flowlint-next-line sketchy-null-bool:off
if (toProps.play === true && !fromProps.play) {
this.leafletElement.getElement().play()
// flowlint-next-line sketchy-null-bool:off
} else if (!toProps.play && fromProps.play === true) {
this.leafletElement.getElement().pause()
}
}
}
export default withLeaflet<Props, VideoOverlay>(VideoOverlay)