전단지에 두 점 사이의 경로를 표시하려고합니다. 그 목적을 위해 리플릿 라우팅 머신을 사용하고 있습니다. 하지만지도 객체를 전단 경로 구성 요소에 전달하는 데 문제가 있습니다.MapLayer 구성 요소에서지도에 액세스하기 (이전 반응 전단지 버전에서 작동)
이 map_container.js
...
return (
<Map ref='map' center={position} zoom={this.state.zoom}>
<TileLayer
attribution="&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors"
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Routing map={this.refs.map} from={[51.599684, 15.27539]} to={[51.602292, 15.295128]} />
</Map>
)
...
routing.js
import {MapLayer} from 'react-leaflet';
import L from 'leaflet';
import 'leaflet-routing-machine';
export default class RoutingMachine extends MapLayer {
componentWillMount() {
super.componentWillMount();
this.leafletElement.addTo(this.props.map);
}
render() {
return null;
}
createLeafletElement (props) {
const {from, to} = this.props;
console.log(this.props)
var leafletElement = L.Routing.control({
waypoints: [
L.latLng(from[0], from[1]),
L.latLng(to[0], to[1]),
],
});
return leafletElement;
}
}
오류 내가 얻을 :
{map: undefined, from: Array(2), to: Array(2)}
bundle.js:69506 Uncaught TypeError: Cannot read property 'getSize' of undefined
at NewClass.onAdd (bundle.js:69506)
at NewClass.onAdd (bundle.js:68679)
at NewClass.addTo (bundle.js:26718)
그러나 가장 흥미로운 것입니다 - 모든 react- "완벽하게 작동 하는가 leaflet ":"1.1.0 "버전이지만 1.1.1 이상에서는 중단됩니다.
아이디어가 있으십니까?