leaflet/src/popup.ml

103 lines
2.5 KiB
OCaml
Raw Normal View History

2022-04-12 13:46:37 +02:00
(* BSD-2-Clause License *)
2022-04-08 13:21:20 +02:00
type t = Jv.t
2022-06-26 05:07:45 +02:00
let set_latlng latlng popup =
2022-04-09 22:21:22 +02:00
let (_ : Jv.t) = Jv.call popup "setLatLng" [| Latlng.to_jv latlng |] in
()
2022-04-07 14:45:11 +02:00
2022-06-26 05:07:45 +02:00
let set_content content popup =
2022-04-09 22:21:22 +02:00
let (_ : Jv.t) = Jv.call popup "setContent" [| Jv.of_string content |] in
()
2022-04-07 14:45:11 +02:00
2022-06-26 05:07:45 +02:00
let set_content_to_el el popup =
let (_ : Jv.t) = Jv.call popup "setContent" [| Brr.El.to_jv el |] in
()
2022-04-09 22:21:22 +02:00
let of_jv = Fun.id
2022-06-20 10:05:35 +02:00
let to_jv = Fun.id
2022-06-20 10:05:35 +02:00
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
2022-12-31 02:45:32 +01:00
let create ~content ~latlng options =
2022-06-20 10:05:35 +02:00
let l =
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
in
2022-06-26 05:07:45 +02:00
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
2022-12-31 02:45:32 +01:00
match content with
2022-06-26 05:07:45 +02:00
| 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