import React from "react"; import Map from "pigeon-maps"; import {Marker, Overlay} from "pigeon-maps"; import Draggable from "pigeon-draggable"; import {longitude, latitude, mapWidth, mapHeight} from "./../config/variables"; import {Button} from "reactstrap"; import PathButtons from "./../PathButtons"; import {calcDistance} from "./../helpers/distance"; export default class Pigeon extends React.Component{ constructor(props) { super(props) this.state = { zoom: 15, path: [[latitude, longitude]], coords: [latitude, longitude], defaultZoom: 15, distance: 0, } } providers = { osm: (x, y, z) => { // use 3 urls to download the tiles faster const s = String.fromCharCode(97 + ((x + y + z) % 3)) return `https://${s}.tile.openstreetmap.org/${z}/${x}/${y}.png` }, stamenTerrain: (x, y, z, dpr) => { return `https://stamen-tiles.a.ssl.fastly.net/terrain/${z}/${x}/${y}${dpr >= 2 ? '@2x' : ''}.jpg` } } updateState = (key, value) => { this.setState({[key]: value}) this.getDistance() } zoomIn = () => { let newZoom = Math.min(this.state.zoom + 1, 22) this.setState({zoom: newZoom}) } zoomOut = () => { let newZoom = Math.max(this.state.zoom - 1, 0) this.setState({zoom: newZoom}) } removeMarkers = () => { this.setState({path: []}) } addMarker = (event) => { const lat = event.latLng[0] const lng = event.latLng[1] let pathCopy = this.state.path.slice(); pathCopy.push([lat, lng]); this.setState({path: pathCopy}) this.getDistance() } updateMarker = (event, idx) => { const lat = event[0] const lng = event[1] let pathCopy = this.state.path.slice(); pathCopy[idx] = [lat, lng]; this.setState({path: pathCopy}) this.getDistance() } getDistance = () => { let dst = calcDistance(this.state.path) this.setState({distance: dst}) } render(){ let testMarkers = this.props.markers let markers = <> if (testMarkers){ markers = this.props.markers.map((pos, idx) => ) }else{ markers = this.state.path.map((pos, idx) => this.updateMarker(event, idx)} > ) } return (
this.addMarker(event)} > {markers} {/*pigeon*/} {/*

test overlay

*/}

Distanz: {Math.round(this.state.distance*100)/100} km

); } }