|
@@ -2,17 +2,18 @@ import React from "react";
|
|
|
import ReactMapGL from "react-map-gl";
|
|
|
import {
|
|
|
Marker,
|
|
|
- NavigationControl,
|
|
|
+ NavigationControl,
|
|
|
FullscreenControl,
|
|
|
ScaleControl,
|
|
|
GeolocateControl,
|
|
|
// Layer,
|
|
|
// Source,
|
|
|
} from "react-map-gl";
|
|
|
-import "./css/maps.css";
|
|
|
-import mapboxToken from './config/mapboxToken.js';
|
|
|
-import {calcDistance} from './helpers/distance';
|
|
|
-import {longitude, latitude, mapWidth, mapHeight, markerIcon} from "./config/variables";
|
|
|
+//import {Polyline} from "@mapbox/polyline";
|
|
|
+import "./../css/maps.css";
|
|
|
+import mapboxToken from "./../config/mapboxToken.js";
|
|
|
+import {calcDistance} from "./../helpers/distance";
|
|
|
+import {longitude, latitude, mapWidth, mapHeight, markerIcon} from "./../config/variables";
|
|
|
import {Button} from "reactstrap";
|
|
|
|
|
|
export default class MapGL extends React.Component{
|
|
@@ -35,7 +36,6 @@ export default class MapGL extends React.Component{
|
|
|
const lat = event.lngLat[1]
|
|
|
console.log("Clicked at", lng, "/", lat);
|
|
|
this.getRoute(lng, lat);
|
|
|
- this.getDistance()
|
|
|
}
|
|
|
|
|
|
updateMarker = (idx, event) => {
|
|
@@ -49,6 +49,7 @@ export default class MapGL extends React.Component{
|
|
|
}
|
|
|
|
|
|
getDistance = () => {
|
|
|
+ console.log(this.state.path)
|
|
|
let dst = calcDistance(this.state.path)
|
|
|
this.setState({distance: dst})
|
|
|
}
|
|
@@ -63,10 +64,11 @@ export default class MapGL extends React.Component{
|
|
|
if (this.state.path.length < 1){
|
|
|
pathCopy.push(end)
|
|
|
this.setState({path: pathCopy})
|
|
|
+ this.getDistance()
|
|
|
} else {
|
|
|
var start = this.state.path[this.state.path.length-1];
|
|
|
var baseUrl = "https://api.mapbox.com/directions/v5/mapbox/"
|
|
|
- var url = baseUrl + "driving/" + start[0] + "," + start[1] + ";" + end[0] + "," + end[1] + "?alternatives=true&geometries=geojson&steps=true&access_token=" + mapboxToken;
|
|
|
+ var url = baseUrl + "walking/" + start[0] + "," + start[1] + ";" + end[0] + "," + end[1] + "?alternatives=true&geometries=geojson&steps=true&access_token=" + mapboxToken;
|
|
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
req.open('GET', url, true);
|
|
@@ -77,6 +79,7 @@ export default class MapGL extends React.Component{
|
|
|
route.map((pos) => pathCopy.push(pos))
|
|
|
pathCopy.push(end)
|
|
|
this.setState({path: pathCopy})
|
|
|
+ this.getDistance()
|
|
|
};
|
|
|
req.send();
|
|
|
}
|
|
@@ -104,7 +107,6 @@ export default class MapGL extends React.Component{
|
|
|
mapStyle="mapbox://styles/mapbox/streets-v11"
|
|
|
onClick={this.addMarker}
|
|
|
>
|
|
|
-
|
|
|
{/*
|
|
|
<Source id="my-data" type="geojson" data={this.geojson}>
|
|
|
<Layer
|