我使用react-leaflet来显示地图。我也使用传单路由机进行路由。路线显示正确,但标记未被汽车图标覆盖。我尝试使用divIcon覆盖路由和反应传单以覆盖标记但尚未成功。
这是我的代码
class CarRouting extends MapLayer {
componentWillMount() {
super.componentWillMount();
const { map, from, to, position, ...props } = this.props;
props.icon = L.divIcon({
className: 'my-div-icon',
});
this.leafletElement =
L.Routing.control({
position: 'topleft',
waypoints: [
L.latLng(from[0], from[1]),
L.latLng(to[0], to[1]),
],
}).addTo(map);
const source = L.marker([from[0], from[1]], props);
const destination = L.marker([to[0], to[1]], props);
const cities = L.layerGroup([source, destination]);
}
render() {
return null;
}
}
export default CarRouting;
轿厢result.js
const icon = divIcon({
className: 'my-div-icon',
iconSize: [30, 30]
});
return (
<Map center={position} zoom={5} style={{ height: 600 }}>
<TileLayer
url='https://mt{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'
subdomains='0123'
/>
<Marker position={position} icon={icon} />
<CarRouting from={[cityOrigenLat, cityOrigenLng]} to={[cityDestinoLat, cityDestinoLng]} />
</Map>
);
};
的main.css
.my-div-icon {
background: url('../../../public/assets/img/icons/shared_car.png');
background-size: contain;
background-repeat: no-repeat;
width: 25px;
height: 25px;
}
我错过了什么吗?
更新
现在路由也会被破坏,并且仍然没有用汽车图像覆盖标记。