@nomadle/rescript-react-leaflet
v0.1.0
Published
ReScript bindings for React-Leaflet
Maintainers
Readme
@nomadle/rescript-react-leaflet
ReScript bindings for React-Leaflet.
Installation
npm install @nomadle/rescript-react-leafletRequires @nomadle/rescript-leaflet as a peer dependency:
npm install @nomadle/rescript-leafletUsage
Add @nomadle/rescript-leaflet and @nomadle/rescript-react-leaflet to your bs-dependencies in rescript.json:
{
"bs-dependencies": [
"@rescript/react",
"@nomadle/rescript-leaflet",
"@nomadle/rescript-react-leaflet"
]
}Example
open ReactLeaflet
open Leaflet
let mapElement = <MapContainer
center=(51.505, -0.09)
zoom=13
style={ReactDOM.Style.make(~width="100%", ~height="500px", ())}
>
<TileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution="© OpenStreetMap contributors"
/>
<Marker position=(51.505, -0.09) />
</MapContainer>API
Components
MapContainer- Main map componentTileLayer- Tile map layerMarker- Marker componentPopup- Popup componentTooltip- Tooltip componentCircle,CircleMarker,Rectangle- Shape componentsPolyline,Polygon- Line/polygon componentsLayerGroup,FeatureGroup- Layer containersWMSTileLayer,ImageOverlay- Additional layer typesGeoJSON- GeoJSON layerScaleControl,ZoomControl,AttributionControl- Map controls
Hooks
Hooks.useMap()- Get the Leaflet map instanceHooks.useMapEvents(MapEvents.t)- Subscribe to map eventsHooks.useMapEvent(string, handler)- Subscribe to a single event type
Types
Leaflet.position- Tuple of (lat, lng)Leaflet.bounds- Array of positionsPathOptions.t- Path styling optionsEventHandlers.t- Event handler objectMapEvents.t- Map event handler object
