-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathApp.jsx
107 lines (96 loc) · 3.83 KB
/
App.jsx
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React, { Component } from 'react';
import { render } from 'react-dom';
import { Map, TileLayer } from 'react-leaflet';
import Control from 'react-leaflet-control';
const stamenTonerTiles = 'http://stamen-tiles-{s}.a.ssl.fastly.net/toner-background/{z}/{x}/{y}.png';
const stamenTonerAttr = 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>';
const mapCenter = [39.9528, -75.1638];
const zoomLevel = 12;
export default class App extends Component {
constructor(props) {
super(props);
this.state = { currentZoomLevel: zoomLevel };
this.handleUpPanClick = this.handleUpPanClick.bind(this);
this.handleRightPanClick = this.handleRightPanClick.bind(this);
this.handleLeftPanClick = this.handleLeftPanClick.bind(this);
this.handleDownPanClick = this.handleDownPanClick.bind(this);
}
componentDidMount() {
const leafletMap = this.leafletMap.leafletElement;
leafletMap.on('zoomend', () => {
const updatedZoomLevel = leafletMap.getZoom();
this.handleZoomLevelChange(updatedZoomLevel);
});
}
handleZoomLevelChange(newZoomLevel) {
this.setState({ currentZoomLevel: newZoomLevel });
}
handleUpPanClick() {
const leafletMap = this.leafletMap.leafletElement;
leafletMap.panBy([0, -100]);
window.console.log('Panning up');
}
handleRightPanClick() {
const leafletMap = this.leafletMap.leafletElement;
leafletMap.panBy([100, 0]);
window.console.log('Panning right');
}
handleLeftPanClick() {
const leafletMap = this.leafletMap.leafletElement;
leafletMap.panBy([-100, 0]);
window.console.log('Panning left');
}
handleDownPanClick() {
const leafletMap = this.leafletMap.leafletElement;
leafletMap.panBy([0, 100]);
window.console.log('Panning down');
}
render() {
window.console.log('this.state.currentZoomLevel ->', this.state.currentZoomLevel);
return (
<div>
<Map
ref={m => { this.leafletMap = m; }}
center={mapCenter}
zoom={zoomLevel}
>
<TileLayer
attribution={stamenTonerAttr}
url={stamenTonerTiles}
/>
<Control position="topright">
<div
style={{
backgroundColor: 'black',
padding: '5px',
}}
>
<div style={{ marginLeft: '37px' }}>
<button onClick={this.handleUpPanClick}>
Pan up
</button>
</div>
<div>
<button onClick={this.handleLeftPanClick}>
Pan left
</button>
<button onClick={this.handleRightPanClick}>
Pan right
</button>
</div>
<div style={{ marginLeft: '30px' }}>
<button onClick={this.handleDownPanClick}>
Pan down
</button>
</div>
</div>
</Control>
</Map>
</div>
);
}
}
render(
<App />,
document.getElementById('mount')
);