|
@@ -1,6 +1,9 @@
|
|
import React, { Component } from 'react';
|
|
import React, { Component } from 'react';
|
|
import { Marker, /*Popup, */Tooltip, withLeaflet } from "react-leaflet";
|
|
import { Marker, /*Popup, */Tooltip, withLeaflet } from "react-leaflet";
|
|
-import { Icon } from 'leaflet';
|
|
|
|
|
|
+import { Icon, LatLng } from 'leaflet';
|
|
|
|
+import bearing from '@turf/bearing';
|
|
|
|
+import PubSub from 'pubsub-js';
|
|
|
|
+import 'leaflet.marker.slideto/Leaflet.Marker.SlideTo.js'
|
|
|
|
|
|
class MoveableMarker extends Component{
|
|
class MoveableMarker extends Component{
|
|
createInfo(data){
|
|
createInfo(data){
|
|
@@ -16,23 +19,42 @@ class MoveableMarker extends Component{
|
|
return infos;
|
|
return infos;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ componentDidMount(){
|
|
|
|
+ this.card_id = this.props.data.card_id;
|
|
|
|
+
|
|
|
|
+ PubSub.subscribe('map.marker.move', (msg, data) => {
|
|
|
|
+ if(this.card_id === data.id){
|
|
|
|
+ // console.log(this.marker, 'slideTo' in this.marker);
|
|
|
|
+ let oldLatlng = this.marker.leafletElement.getLatLng();
|
|
|
|
+ let newLatlng = new LatLng(data.lat, data.lng);
|
|
|
|
+ let b = bearing([oldLatlng.lat, oldLatlng.lng], [newLatlng.lat, newLatlng.lng]) + 90;
|
|
|
|
+ console.log(b, b * 0.33333);
|
|
|
|
+ this.marker.leafletElement.setRotationAngle(b * 0.33333);
|
|
|
|
+ this.marker.leafletElement.slideTo([data.lat, data.lng], {
|
|
|
|
+ duration: data.duration,
|
|
|
|
+ keepAtCenter: false
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
render(){
|
|
render(){
|
|
return <>
|
|
return <>
|
|
- <Marker position={[this.props.data.lat, this.props.data.lng] } icon={new Icon({
|
|
|
|
- // iconUrl: window.EDITOR_URL + "img/move.png",
|
|
|
|
- iconUrl: window.EDITOR_URL + this.props.data.src,
|
|
|
|
- iconSize: [20,20],
|
|
|
|
- iconAnchor: [10,10]
|
|
|
|
- })} name={`${this.props.data.card}`} key={this.props.key}>
|
|
|
|
|
|
+ <Marker
|
|
|
|
+ position={[this.props.data.lat, this.props.data.lng] }
|
|
|
|
+ icon={new Icon({
|
|
|
|
+ iconUrl: window.EDITOR_URL + this.props.data.src,
|
|
|
|
+ iconSize: [20,20],
|
|
|
|
+ iconAnchor: [10,10]
|
|
|
|
+ })}
|
|
|
|
+ name={`${this.card_id}`} key={this.card_id}
|
|
|
|
+ ref={marker => this.marker = marker}
|
|
|
|
+ >
|
|
{this.props.data.info &&
|
|
{this.props.data.info &&
|
|
<Tooltip>
|
|
<Tooltip>
|
|
{ this.createInfo(this.props.data.info) }
|
|
{ this.createInfo(this.props.data.info) }
|
|
</Tooltip>
|
|
</Tooltip>
|
|
}
|
|
}
|
|
- {/* <Popup>
|
|
|
|
- <span>{}</span>
|
|
|
|
- <button onClick={() => {console.log(`marker-${this.props.data.id}`)}}>点击</button>
|
|
|
|
- </Popup> */}
|
|
|
|
</Marker>;
|
|
</Marker>;
|
|
</>
|
|
</>
|
|
}
|
|
}
|