您对将绘图功能实现到 react-leafletV3 有任何想法吗?我添加了一个事件侦听器,但它无法正常工作并对任何事情做出反应。
useEffect(() => {
if (!map) return;
map.addEventListener("mousemove", function (event) {
setCoords({ lat: event.latlng.lat, lng: event.latlng.lng });
});
map.on("draw:drawstart", function (event) {
console.log("event here", event);
});
const drawControl = new L.Control.Draw({
position: "topleft",
});
drawControl.addTo(map);
const leftLayer = L.tileLayer(
layers[leftLayerIndex].url,
layerOptions
).addTo(map);
const rightLayer = L.tileLayer(
layers[rightLayerIndex].url,
layerOptions
).addTo(map);
const sbs = L.control.sideBySide(leftLayer, rightLayer).addTo(map);
setSideBySide(sbs);
}, [map]);
useEffect(() => {
if (sideBySide) {
sideBySide.setLeftLayers(
L.tileLayer(layers[leftLayerIndex].url, layerOptions).addTo(map)
);
}
}, [leftLayerIndex, rightLayerIndex, sideBySide]);