-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFullscreenComponent.js
More file actions
36 lines (27 loc) · 914 Bytes
/
Copy pathFullscreenComponent.js
File metadata and controls
36 lines (27 loc) · 914 Bytes
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
import React from 'react';
import { createControlComponent } from '@react-leaflet/core';
import { useMapEvents } from 'react-leaflet';
import * as L from 'leaflet';
import 'leaflet.fullscreen';
import screenfull from 'screenfull';
import './Control.FullScreen.css';
function createLeafletControl(props) {
window.screenfull = screenfull;
return L.control.fullscreen(props);
}
const Fullscreen = createControlComponent(createLeafletControl);
const getEventsFromProps = ({ enterFullscreen, exitFullscreen }) => {
const events = {};
if (enterFullscreen) {
events.enterFullscreen = enterFullscreen;
}
if (exitFullscreen) {
events.exitFullscreen = exitFullscreen;
}
return events;
};
const FullscreenWithEvents = ({ eventHandlers = {}, ...props }) => {
useMapEvents({ ...getEventsFromProps(eventHandlers) });
return <Fullscreen {...props} />;
};
export default FullscreenWithEvents;