|
@@ -4,15 +4,6 @@ import Marker from 'pigeon-marker'
|
|
|
import Overlay from 'pigeon-overlay'
|
|
|
|
|
|
export default class Pigeon extends React.Component{
|
|
|
-
|
|
|
- constructor(props) {
|
|
|
- super(props)
|
|
|
-
|
|
|
- this.state = {
|
|
|
- zoom: 15
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
providers = {
|
|
|
osm: (x, y, z) => {
|
|
|
// use 3 urls to download the tiles faster
|
|
@@ -25,40 +16,66 @@ export default class Pigeon extends React.Component{
|
|
|
}
|
|
|
|
|
|
zoomIn = () => {
|
|
|
- this.setState({
|
|
|
- zoom: Math.min(this.state.zoom + 1, 22),
|
|
|
- })
|
|
|
+ let newZoom = Math.min(this.props.mapConfig.zoom + 1, 22)
|
|
|
+ this.props.updateMapState("zoom", newZoom)
|
|
|
}
|
|
|
|
|
|
zoomOut = () => {
|
|
|
- this.setState({
|
|
|
- zoom: Math.max(this.state.zoom - 1, 0),
|
|
|
- })
|
|
|
+ let newZoom = Math.max(this.props.mapConfig.zoom - 1, 0)
|
|
|
+ this.props.updateMapState("zoom", newZoom)
|
|
|
}
|
|
|
|
|
|
- render(){
|
|
|
+ removeMarkers = () => {
|
|
|
+ this.props.updateMapState("path", [])
|
|
|
+ }
|
|
|
|
|
|
+ addMarker = (event) => {
|
|
|
+ const lat = event.latLng[0]
|
|
|
+ const lng = event.latLng[1]
|
|
|
+ console.log("Clicked at", lat, "/", lng, event)
|
|
|
+ let pathCopy = this.props.mapConfig.path.slice();
|
|
|
+ pathCopy.push([lat, lng]);
|
|
|
+ this.props.updateMapState("path", pathCopy)
|
|
|
+ this.props.calcDistance()
|
|
|
+ }
|
|
|
+
|
|
|
+ render(){
|
|
|
+ const mapConfig = this.props.mapConfig;
|
|
|
return (
|
|
|
<div>
|
|
|
<Map
|
|
|
- center={[48.336950, 14.320570]}
|
|
|
- defaultZoom={15}
|
|
|
- zoom={this.state.zoom}
|
|
|
- width={600}
|
|
|
- height={400}
|
|
|
+ center={mapConfig.coords}
|
|
|
+ defaultZoom={mapConfig.defaultZoom}
|
|
|
+ zoom={mapConfig.zoom}
|
|
|
+ width={mapConfig.width}
|
|
|
+ height={mapConfig.height}
|
|
|
attribution="Pigeon Map"
|
|
|
attributionPrefix={false}
|
|
|
- animation={true}
|
|
|
- provider={this.providers["osm"]}>
|
|
|
- {/* animation: for example when switching between different markers */}
|
|
|
- <Marker anchor={[48.336950, 14.320570]} payload={1} onClick={({ event, anchor, payload }) => {}} />
|
|
|
-
|
|
|
+ animation={true}
|
|
|
+ provider={this.providers["osm"]}
|
|
|
+ dprs={[1, 2]}
|
|
|
+ onClick={(event) => this.addMarker(event)}
|
|
|
+ >
|
|
|
+ <Marker anchor={[48.336950, 14.320570]} payload={1} onClick={({ event, anchor, payload }) => {}} />
|
|
|
+
|
|
|
+ {mapConfig.path.map((pos, idx) =>
|
|
|
+ <Marker anchor={pos} key={idx}/>
|
|
|
+ )}
|
|
|
+
|
|
|
<Overlay anchor={[48.337069, 14.319570]} offset={[120, 79]}>
|
|
|
{/*<img src='pigeon.png' width={240} height={158} alt='pigeon' />*/}
|
|
|
</Overlay>
|
|
|
</Map>
|
|
|
- <button onClick={this.zoomIn}>+</button>
|
|
|
- <button onClick={this.zoomOut}>-</button>
|
|
|
+
|
|
|
+ <div>
|
|
|
+ <button onClick={this.zoomIn}>+</button>
|
|
|
+ <button onClick={this.zoomOut}>-</button>
|
|
|
+ <button onClick={this.removeMarkers}>Clear path</button>
|
|
|
+ <button onClick={this.props.calcDistance}>Calculate Distance</button>
|
|
|
+ <p>
|
|
|
+ Distanz: {Math.round(mapConfig.distance*100)/100} km
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
);
|
|
|
}
|