Rescript bindings for React Leaflet
npm install rescript-leaflet-react1. Install the package
``json`
npm i rescript-leaflet-reactbsconfig.json
1. Add this to you :`json`
"bs-dependencies": [
"@rescript/react",
"rescript-leaflet-react"
]`
1. Import into your Rescript projectrescript`
open RescriptLeafletReact
5. Access the LeafletReact module
`rescript
open RescriptLeafletReact
let s = React.string
module EventLogger = {
@react.component
let make = () => {
open LeafletHooks
let map = useMap()
let mapEvents = useMapEvents(EventHandlers.make(
~click = (event) => {
Js.log("Mouse Click:")
Js.log(event)
},
()
))
let onSingleEvent = useMapEvent("drag", (pos) => {
Js.log("Drag Event:")
Js.log(pos)
})
Js.log("Center:")
Js.log(map.getCenter(.))
<>>
}
}
@react.component
let make = () => {
open LeafletReact
let logMouseEvent = (t) => {
Js.log(t)
}
let logPopupEvent = (t) => {
Js.log(t)
}
let logDragEvent = (t) => {
Js.log(t)
}
let bounds = create_bounds(
(39.043705, -95.692240), (40.043705, -93.692240)
)
let pathOptions = PathOptions.make(
~color="#00ff00",
()
)
eventHandlers={EventHandlers.make(
~click = logMouseEvent,
~popupopen = logPopupEvent,
~drag = logDragEvent,
()
)}
>
{s("You clicked on the marker")}
radius={5000.}
pathOptions={pathOptions}
/>
(39.043705, -95.692240),
(38.043705, -95.692240)
]}
/>
(40.043705, -93.692240),
(39.043705, -93.692240),
(39.043705, -92.692240),
(40.043705, -93.692240),
]}
/>
bounds={bounds}
/>
This snippet of code generates this map:
!Example Map
Limitations:
This is not a complete binding, if anyone wants to chip away at the library
I would happily merge it in.Because of some weirdness with
this binding and rescript's currying system, all the hook functions (getCenter, zoomIn, etc.) must be called in the uncurried way
(using func(. param)` notation)