add popup options

This commit is contained in:
Swrup 2022-06-20 10:05:35 +02:00
parent 323891efef
commit 9a0cec96c6
6 changed files with 101 additions and 9 deletions

View file

@ -31,10 +31,16 @@ let remove_from : type kind. Map.t -> kind t -> unit =
let (_ : Jv.t) = Jv.call l "removeFrom" [| Map.to_jv map |] in
()
let bind_popup : type kind. Brr.El.t -> ?options:Jv.t -> kind t -> unit =
fun el ?(options = Jv.null) -> function
| Basic l | Geojson l | Marker l | Tile l ->
let (_ : Jv.t) = Jv.call l "bindPopup" [| Brr.El.to_jv el; options |] in
let bind_popup : type kind. Brr.El.t -> Popup.opt list -> kind t -> unit =
fun el options -> function
| Basic layer | Geojson layer | Marker layer | Tile layer ->
let l =
Array.of_list
@@ List.map (fun o -> (Popup.opt_to_string o, Popup.opt_to_jv o)) options
in
let (_ : Jv.t) =
Jv.call layer "bindPopup" [| Brr.El.to_jv el; Jv.obj l |]
in
()
let unbind_popup : type kind. kind t -> unit = function
@ -98,7 +104,10 @@ let geojson_opt_to_jv = function
| Markers_inherit_options b -> Jv.of_bool b
| Point_to_layer f -> Jv.repr f
| Style f -> Jv.repr f
| On_each_feature f -> Jv.repr f
| On_each_feature f ->
(* we need to wrap the Jv.t *)
let f feature jv = jv |> of_jv Geojson |> f feature in
Jv.repr f
| Filter f -> Jv.repr f
| Coords_to_latlng f -> Jv.repr f