An interactive map widget for js_top_worker notebooks, built on Leaflet. Provides a typed OCaml API for creating maps, placing markers, drawing bounding boxes, and overlaying images.
Quick start
Register the widget adapter, then create a map:
#require "js_top_worker-widget-leaflet";;
open Widget_leaflet;;
register ();;let map = Leaflet_map.create
~center:(51.505, -0.09) ~zoom:13 ~height:"400px"
~on_click:(fun pt ->
Printf.printf "Clicked: %.4f, %.4f\n" pt.lat pt.lng)
()Adding markers
Place coloured markers with optional labels:
let () =
Leaflet_map.add_marker map
{ lat = 51.505; lng = -0.09 }
~color:"#e74c3c" ~label:"Hello" ();
Leaflet_map.add_marker map
{ lat = 51.51; lng = -0.08 }
~color:"#2ecc71" ~label:"World" ()Navigation
Fly to a new location with animation:
let () =
Leaflet_map.fly_to map { lat = 48.8566; lng = 2.3522 } ~zoom:12 ()Fit the map to a bounding box:
let () =
Leaflet_map.fit_bounds map
{ south = 51.3; west = -0.5; north = 51.7; east = 0.3 }Drawing bounding boxes
Enable interactive rectangle drawing. The callback receives the bounds when the user finishes drawing:
let () =
Printf.printf "Draw a rectangle on the map...\n";
Leaflet_map.enable_bbox_draw mapAPI reference
See Widget_leaflet.Leaflet_map for the full API, and Widget_leaflet for adapter registration.