leaflet/src/popup.ml

80 lines
2 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-04-07 14:45:11 +02:00
let popup = Jv.call Global.leaflet "popup" [||]
let set_latlng latlng =
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
let set_content content =
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-04-09 22:21:22 +02:00
let open_on map =
let (_ : Jv.t) = Jv.call popup "openOn" [| Map.to_jv map |] in
()
2022-04-07 14:45:11 +02:00
2022-04-09 22:21:22 +02:00
let close map =
let (_ : Jv.t) = Jv.call (Map.to_jv map) "closePopup" [||] in
()
2022-04-08 13:21:20 +02:00
2022-04-09 22:21:22 +02:00
let of_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
let create options =
let l =
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
in
Jv.call Global.leaflet "popup" [| Jv.obj l |]