|
@@ -91,11 +91,11 @@ export default class Google extends React.Component{
|
|
const lng = event.lng
|
|
const lng = event.lng
|
|
const lat = event.lat
|
|
const lat = event.lat
|
|
|
|
|
|
-// let pathCopy = this.state.path.slice();
|
|
|
|
-// pathCopy.push([lat, lng])
|
|
|
|
-// this.setState({path: pathCopy})
|
|
|
|
|
|
+ let pathCopy = this.state.path.slice();
|
|
|
|
+ pathCopy.push([lat, lng])
|
|
|
|
+ this.setState({path: pathCopy})
|
|
|
|
|
|
- this.getRoute(lng, lat);
|
|
|
|
|
|
+// this.getRoute(lng, lat);
|
|
this.getDistance()
|
|
this.getDistance()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -119,19 +119,21 @@ export default class Google extends React.Component{
|
|
}
|
|
}
|
|
|
|
|
|
drawPath = () => {
|
|
drawPath = () => {
|
|
- let path = this.state.path.map(p => {
|
|
|
|
- return {lat: p[0], lng: p[1]}
|
|
|
|
- })
|
|
|
|
- let map = this.state.map
|
|
|
|
- let maps = this.state.maps
|
|
|
|
- new maps.Polyline({
|
|
|
|
- path: path,
|
|
|
|
- geodesic: true,
|
|
|
|
- strokeColor: "#212529",
|
|
|
|
- strokeOpacity: 1.0,
|
|
|
|
- strokeWeight: 4,
|
|
|
|
- map,
|
|
|
|
- });
|
|
|
|
|
|
+ if (!this.props.markers){
|
|
|
|
+ let path = this.state.path.map(p => {
|
|
|
|
+ return {lat: p[0], lng: p[1]}
|
|
|
|
+ })
|
|
|
|
+ let map = this.state.map
|
|
|
|
+ let maps = this.state.maps
|
|
|
|
+ new maps.Polyline({
|
|
|
|
+ path: path,
|
|
|
|
+ geodesic: true,
|
|
|
|
+ strokeColor: "#212529",
|
|
|
|
+ strokeOpacity: 1.0,
|
|
|
|
+ strokeWeight: 4,
|
|
|
|
+ map,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
handleApiLoaded = (map, maps) => {
|
|
handleApiLoaded = (map, maps) => {
|
|
@@ -140,6 +142,28 @@ export default class Google extends React.Component{
|
|
|
|
|
|
render() {
|
|
render() {
|
|
const position = [this.state.latitude, this.state.longitude]
|
|
const position = [this.state.latitude, this.state.longitude]
|
|
|
|
+ let testMarkers = this.props.markers
|
|
|
|
+ let markers = <></>
|
|
|
|
+ if (testMarkers){
|
|
|
|
+ markers = this.props.markers.map((pos, idx) =>
|
|
|
|
+ <Marker
|
|
|
|
+ lat={pos[0]}
|
|
|
|
+ lng={pos[1]}
|
|
|
|
+ key={idx}
|
|
|
|
+ />
|
|
|
|
+ )
|
|
|
|
+ }else{
|
|
|
|
+ markers = this.state.path.map((pos, idx) =>
|
|
|
|
+ <Marker
|
|
|
|
+ lat={pos[0]}
|
|
|
|
+ lng={pos[1]}
|
|
|
|
+ text={idx}
|
|
|
|
+ key={idx}
|
|
|
|
+ draggable={true}
|
|
|
|
+ onDragEnd={(e) => this.updateMarker(idx, e)}
|
|
|
|
+ />
|
|
|
|
+ )}
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div>
|
|
<div>
|
|
<div className="map" style={{height: mapHeight, width: mapWidth}}>
|
|
<div className="map" style={{height: mapHeight, width: mapWidth}}>
|
|
@@ -155,16 +179,8 @@ export default class Google extends React.Component{
|
|
onChildMouseUp={this.updateMarker}
|
|
onChildMouseUp={this.updateMarker}
|
|
onGoogleApiLoaded={({map, maps}) => this.handleApiLoaded(map, maps)}
|
|
onGoogleApiLoaded={({map, maps}) => this.handleApiLoaded(map, maps)}
|
|
>
|
|
>
|
|
- {this.state.path.map((pos, idx) =>
|
|
|
|
- <Marker
|
|
|
|
- lat={pos[0]}
|
|
|
|
- lng={pos[1]}
|
|
|
|
- text={idx}
|
|
|
|
- key={idx}
|
|
|
|
- draggable={true}
|
|
|
|
- onDragEnd={(e) => this.updateMarker(idx, e)}
|
|
|
|
- />
|
|
|
|
- )}
|
|
|
|
|
|
+
|
|
|
|
+ {markers}
|
|
|
|
|
|
</GoogleMapReact>
|
|
</GoogleMapReact>
|
|
</div>
|
|
</div>
|