|
@@ -5,13 +5,16 @@ import ReactMapboxGl, {
|
|
|
ZoomControl,
|
|
|
ScaleControl,
|
|
|
RotationControl,
|
|
|
+ Source,
|
|
|
+ Marker,
|
|
|
} from "react-mapbox-gl";
|
|
|
import mapboxToken from "./../config/mapboxToken.js";
|
|
|
import {calcDistance} from "./../helpers/distance";
|
|
|
-import {longitude, latitude, mapWidth, mapHeight} from "./../config/variables";
|
|
|
+import {longitude, latitude, mapWidth, mapHeight, markerIcon} from "./../config/variables";
|
|
|
import {Button} from "reactstrap";
|
|
|
import {getRoute} from "./../helpers/mapboxHelper";
|
|
|
import PathButtons from "./../PathButtons";
|
|
|
+import {GeoJSONLayer} from "react-mapbox-gl";
|
|
|
|
|
|
const Map = ReactMapboxGl({ accessToken: mapboxToken });
|
|
|
|
|
@@ -21,7 +24,7 @@ export default class Mapbox extends React.Component{
|
|
|
this.state = {
|
|
|
latitude: latitude,
|
|
|
longitude: longitude,
|
|
|
- zoom: [15],
|
|
|
+ zoom: [14],
|
|
|
path: [[longitude, latitude], [longitude+0.003, latitude]],
|
|
|
distance: 0,
|
|
|
center: [longitude, latitude]
|
|
@@ -63,6 +66,32 @@ export default class Mapbox extends React.Component{
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
+ let testMarkers = this.props.markers
|
|
|
+ let markers = <></>
|
|
|
+ if (testMarkers){
|
|
|
+ markers = testMarkers.map((pos, idx) =>
|
|
|
+ <Feature
|
|
|
+ coordinates={pos}
|
|
|
+ key={idx}
|
|
|
+ />
|
|
|
+// <Marker
|
|
|
+// coordinates={pos}
|
|
|
+// key={idx}
|
|
|
+// anchor="bottom">
|
|
|
+// <img src={markerIcon}/>
|
|
|
+// </Marker>
|
|
|
+ )
|
|
|
+ }else{
|
|
|
+ markers = this.state.path.map((pos, idx) =>
|
|
|
+ <Feature
|
|
|
+ coordinates={pos}
|
|
|
+ key={idx}
|
|
|
+ draggable={true}
|
|
|
+ onDragEnd={(e) => this.updateMarker(idx, e)}
|
|
|
+ />
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<div>
|
|
|
<div className="map">
|
|
@@ -76,15 +105,42 @@ export default class Mapbox extends React.Component{
|
|
|
zoom={this.state.zoom}
|
|
|
onClick={(e, c) => this.addMarker(e, c)}
|
|
|
>
|
|
|
+
|
|
|
+ {/*<Layer type="line" layout={{'line-join': 'round', 'line-cap': 'round'}}
|
|
|
+ paint={{"line-color": "#888", "line-width": 3}}
|
|
|
+ source="routeSource"
|
|
|
+ id="routeSource"
|
|
|
+ type="line"
|
|
|
+ data={{type: "LineString", coordinates: this.state.path}}
|
|
|
+>
|
|
|
+ <Feature
|
|
|
+ source="routeSource"
|
|
|
+ id="route"
|
|
|
+ type="line"
|
|
|
+ data={{type: "line", coordinates: this.state.path}}
|
|
|
+ paint={{"line-color": "#888", "line-width": 3}}
|
|
|
+ layout= {{"line-join": "round", "line-cap": "round"}}
|
|
|
+ />
|
|
|
+</Layer>*/}
|
|
|
+
|
|
|
+ <Source
|
|
|
+ id="routeSource"
|
|
|
+ type="geojson"
|
|
|
+ data={{type: "LineString", coordinates: this.state.path}}
|
|
|
+ >
|
|
|
+ <Layer
|
|
|
+ source="routeSource"
|
|
|
+ id="route"
|
|
|
+ type="line"
|
|
|
+ paint={{"line-color": "#888", "line-width": 3}}
|
|
|
+ layout= {{"line-join": "round", "line-cap": "round"}}
|
|
|
+ />
|
|
|
+ </Source>
|
|
|
+
|
|
|
<Layer type="symbol" id="marker" layout={{"icon-image": "marker-15" }}>
|
|
|
- {this.state.path.map((pos, idx) =>
|
|
|
- <Feature
|
|
|
- coordinates={pos}
|
|
|
- key={idx} draggable={true}
|
|
|
- onDragEnd={(e) => this.updateMarker(idx, e)}
|
|
|
- />
|
|
|
- )}
|
|
|
+ {markers}
|
|
|
</Layer>
|
|
|
+
|
|
|
<ZoomControl position={"top-right"}/>
|
|
|
<ScaleControl position={"bottom-right"}/>
|
|
|
<RotationControl position={"top-right"}/>
|