useMapEventHandler
function CustomFeature() {
useMapEventHandler({
onClick: ({ event, lonlat }) => {
console.log("event", event);
console.log("lonlat", lonlat);
},
onHover: ({ event, lonlat }) => {
console.log("event", event);
console.log("lonlat", lonlat);
},
onLoaded: (event) => {
console.log("event", event);
},
onLoadStart: (event) => {
console.log("event", event);
},
});
return <></>;
}
<div>
<MapContainer center={[126.841784, 35.191406]} width="100%" height="500px">
<CustomFeature />
</MapContainer>
</div>;
useMapEventHandler
을 사용하게 되면 openlayers 이벤트중 "singleclick" 이벤트가 추가됩니다.- 클릭한 어노테이션을 상태로 반환합니다.
value | type | description |
---|---|---|
onClick | ({ event, lonlat }) => void | 마우스 클릭한 좌표와 이벤트를 반환하고, annotation 위에서 클릭했다면 event에서 annotation feature 를 확인할 수 있습니다. |
onHover | ({ event, lonlat }) => void | 마우스를 호버링하고 있는 좌표와 이벤트를 반환하고, annotation 위에서 클릭했다면 event에서 annotation feature 를 확인할 수 있습니다. |
onLoaded | (event) => void | 지도의 로딩이 마무리되면 발생하는 이벤트 입니다. |
onLoadStart | (event) => void | 지도의 로딩을 시작하면서 발생하는 이벤트 입니다. |