(* BSD-2-Clause License *) type t = Jv.t let set_latlng latlng popup = let (_ : Jv.t) = Jv.call popup "setLatLng" [| Latlng.to_jv latlng |] in () let set_content content popup = let (_ : Jv.t) = Jv.call popup "setContent" [| Jv.of_string content |] in () let set_content_to_el el popup = let (_ : Jv.t) = Jv.call popup "setContent" [| Brr.El.to_jv el |] in () let of_jv = Fun.id let to_jv = Fun.id type opt = | Pane of string | Offset of Point.t | Max_width of int | Min_width of int | Max_height of int | Auto_pan of bool | Auto_pan_padding_top_left of Point.t | Auto_pan_padding_bottom_right of Point.t | Auto_pan_padding of Point.t | Keep_in_view of bool | Close_button of bool | Auto_close of bool | Close_on_escape_key of bool | Close_on_click of bool | Class_name of string let opt_to_string = function | Pane _ -> "pane" | Offset _ -> "offset" | Max_width _ -> "maxWidth" | Min_width _ -> "minWidth" | Max_height _ -> "maxHeight" | Auto_pan _ -> "autoPan" | Auto_pan_padding_top_left _ -> "autoPanPaddingTopLeft" | Auto_pan_padding_bottom_right _ -> "autoPanPaddingBottomRight" | Auto_pan_padding _ -> "autoPanPadding" | Keep_in_view _ -> "keepInView" | Close_button _ -> "closeButton" | Auto_close _ -> "autoClose" | Close_on_escape_key _ -> "closeOnEscapeKey" | Close_on_click _ -> "closeOnClick" | Class_name _ -> "className" let opt_to_jv = function | Offset p | Auto_pan_padding_top_left p | Auto_pan_padding_bottom_right p | Auto_pan_padding p -> Point.to_jv p | Max_width i | Min_width i | Max_height i -> Jv.of_int i | Auto_pan b | Keep_in_view b | Close_button b | Auto_close b | Close_on_escape_key b | Close_on_click b -> Jv.of_bool b | Pane s | Class_name s -> Jv.of_string s let create ~content ~latlng options = let l = Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options in let popup = Jv.call Global.leaflet "popup" [| Jv.obj l |] in let popup = match latlng with | None -> popup | Some latlng -> set_latlng latlng popup; popup in match content with | None -> popup | Some content -> set_content content popup; popup let create_from_el el ~latlng options = let l = Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options in let popup = Jv.call Global.leaflet "popup" [| Jv.obj l |] in let popup = match latlng with | None -> popup | Some latlng -> set_latlng latlng popup; popup in set_content_to_el el popup; popup