better popups
This commit is contained in:
parent
38d846cf29
commit
57ee0a2ca8
4 changed files with 57 additions and 16 deletions
41
src/popup.ml
41
src/popup.ml
|
|
@ -2,16 +2,18 @@
|
|||
|
||||
type t = Jv.t
|
||||
|
||||
let popup = Jv.call Global.leaflet "popup" [||]
|
||||
|
||||
let set_latlng latlng =
|
||||
let set_latlng latlng popup =
|
||||
let (_ : Jv.t) = Jv.call popup "setLatLng" [| Latlng.to_jv latlng |] in
|
||||
()
|
||||
|
||||
let set_content content =
|
||||
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
|
||||
|
|
@ -66,8 +68,35 @@ let opt_to_jv = function
|
|||
Jv.of_bool b
|
||||
| Pane s | Class_name s -> Jv.of_string s
|
||||
|
||||
let create options =
|
||||
let create content_opt ~latlng 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 |]
|
||||
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_opt 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue