admin管理员组文章数量:1326322
I'm trying to subscribe on zoom change event, but can't get updates on each zoom change.
My goal is to reach markers scaling on zoom levels. Something like in this case React-Leaflet: Scale markers after zooming
But react-leaflet in v3 doesn't have onZoomChange event for MapContainer. So i can't get zoom updates for scaling my DivIcon
I'm trying to subscribe on zoom change event, but can't get updates on each zoom change.
My goal is to reach markers scaling on zoom levels. Something like in this case React-Leaflet: Scale markers after zooming
But react-leaflet in v3 doesn't have onZoomChange event for MapContainer. So i can't get zoom updates for scaling my DivIcon
Share Improve this question asked Dec 17, 2020 at 9:21 BaoTheMastrBaoTheMastr 1211 silver badge8 bronze badges1 Answer
Reset to default 9found the solution with useMapEvents hook provided in react-leaflet v3:
https://react-leaflet.js/docs/api-map#usemapevents
import {useMapEvents} from "react-leaflet";
import {useState} from "react";
function MyComponent() {
const [zoomLevel, setZoomLevel] = useState(5); // initial zoom level provided for MapContainer
const mapEvents = useMapEvents({
zoomend: () => {
setZoomLevel(mapEvents.getZoom());
},
});
console.log(zoomLevel);
return null
}
function MyMapComponent() {
return (
<MapContainer center={[50.5, 30.5]} zoom={5}>
<MyComponent />
</MapContainer>
)
}
本文标签: javascriptreactleaflet v3 zoom listenerStack Overflow
版权声明:本文标题:javascript - react-leaflet v3 zoom listener - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742202331a2432193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论