@nomadle/rescript-leaflet
v0.1.0
Published
ReScript bindings for Leaflet
Readme
@nomadle/rescript-leaflet
ReScript bindings for Leaflet - the leading open-source JavaScript library for mobile-friendly interactive maps.
Installation
npm install @nomadle/rescript-leafletUsage
Add @nomadle/rescript-leaflet to your bs-dependencies in rescript.json:
{
"bs-dependencies": [
"@nomadle/rescript-leaflet"
]
}Don't forget to include Leaflet CSS in your HTML:
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />API
Types
position- Tuple of (lat, lng) as(float, float)bounds- Array of positionsarray<position>map- Opaque type for Leaflet map instance
LatLng
let ll = LatLng.make(51.505, -0.09)
let lat = LatLng.lat(ll)
let lng = LatLng.lng(ll)LatLngBounds
let bounds = LatLngBounds.make((51.5, -0.1), (51.51, -0.11))
let center = LatLngBounds.getCenter(bounds)Point
let pt = Point.make(100.0, 200.0)Icon
let icon = Icon.createDefault(~iconUrl="/marker.png", ())
let divIcon = Icon.createDivIcon(~html="<div>Marker</div>", ())PathOptions
let opts = PathOptions.make(
~color="#ff0000",
~weight=3,
~opacity=1.0,
~fillColor="#ff6666",
~fillOpacity=0.5,
()
)EventTypes
Types for Leaflet event objects with accessors:
mouseEvent- Mouse event with latlng, type, targetleafletEvent- Base event typeleafletMouseEvent- Mouse event with additional properties
EventHandlers
let handlers = EventHandlers.make(
~click=event => (),
~mouseover=event => (),
()
)Classes
Map- Create and manipulate Leaflet mapsTileLayer- Tile layersMarker- MarkersCircle,CircleMarker- Circle shapesPolyline,Polygon- Line/polygon shapesRectangle- Rectangle shapeImageOverlay- Image overlayGeoJSON- GeoJSON layerLayerGroup,FeatureGroup- Layer containersControl,ScaleControl- Map controls
Each class provides methods like addTo, remove, setStyle, etc.
React-Leaflet
For React-Leaflet bindings, see @nomadle/rescript-react-leaflet.
License
MIT
