better popups
This commit is contained in:
parent
23ea827e40
commit
7effdcc577
4 changed files with 57 additions and 16 deletions
|
|
@ -50,5 +50,9 @@ let wrap_latlng latlng map =
|
||||||
let open_popup popup map =
|
let open_popup popup map =
|
||||||
ignore @@ Jv.call map "openPopup" [| Popup.to_jv popup |]
|
ignore @@ Jv.call map "openPopup" [| Popup.to_jv popup |]
|
||||||
|
|
||||||
let close_popup popup map =
|
let close_popup ~popup map =
|
||||||
ignore @@ Jv.call map "closePopup" [| Popup.to_jv popup |]
|
ignore
|
||||||
|
@@
|
||||||
|
match popup with
|
||||||
|
| None -> Jv.call map "closePopup" [||]
|
||||||
|
| Some popup -> Jv.call map "closePopup" [| Popup.to_jv popup |]
|
||||||
|
|
|
||||||
|
|
@ -51,5 +51,5 @@ val to_jv : t -> Jv.t
|
||||||
(* [open_popup popup map] opens [popup] on [map] *)
|
(* [open_popup popup map] opens [popup] on [map] *)
|
||||||
val open_popup : Popup.t -> t -> unit
|
val open_popup : Popup.t -> t -> unit
|
||||||
|
|
||||||
(* [close_popup popup map] closes [popup] on [map] *)
|
(* [close_popup opt map] if [opt] is [Some popup] closes [popup] else closes previously opened popup *)
|
||||||
val close_popup : Popup.t -> t -> unit
|
val close_popup : popup:Popup.t option -> t -> unit
|
||||||
|
|
|
||||||
41
src/popup.ml
41
src/popup.ml
|
|
@ -2,16 +2,18 @@
|
||||||
|
|
||||||
type t = Jv.t
|
type t = Jv.t
|
||||||
|
|
||||||
let popup = Jv.call Global.leaflet "popup" [||]
|
let set_latlng latlng popup =
|
||||||
|
|
||||||
let set_latlng latlng =
|
|
||||||
let (_ : Jv.t) = Jv.call popup "setLatLng" [| Latlng.to_jv latlng |] in
|
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 (_ : 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 of_jv = Fun.id
|
||||||
|
|
||||||
let to_jv = Fun.id
|
let to_jv = Fun.id
|
||||||
|
|
@ -66,8 +68,35 @@ let opt_to_jv = function
|
||||||
Jv.of_bool b
|
Jv.of_bool b
|
||||||
| Pane s | Class_name s -> Jv.of_string s
|
| Pane s | Class_name s -> Jv.of_string s
|
||||||
|
|
||||||
let create options =
|
let create content_opt ~latlng options =
|
||||||
let l =
|
let l =
|
||||||
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
|
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
|
||||||
in
|
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
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,14 @@ type opt =
|
||||||
| Close_on_click of bool
|
| Close_on_click of bool
|
||||||
| Class_name of string
|
| Class_name of string
|
||||||
|
|
||||||
(** [set_latlng latlng] changes the popup position to the given point*)
|
(** [set_latlng latlng popup] sets [popup] position to the given point*)
|
||||||
val set_latlng : Latlng.t -> unit
|
val set_latlng : Latlng.t -> t -> unit
|
||||||
|
|
||||||
(** [set_content s] changes the popup content to [s]*)
|
(** [set_content s popup] sets [popup] content to [s]*)
|
||||||
val set_content : string -> unit
|
val set_content : string -> t -> unit
|
||||||
|
|
||||||
|
(** [set_content_to_el el s] sets [popup] content to [el]*)
|
||||||
|
val set_content_to_el : Brr.El.t -> t -> unit
|
||||||
|
|
||||||
(** [of_jv jv] is [jv] as {!t} *)
|
(** [of_jv jv] is [jv] as {!t} *)
|
||||||
val of_jv : Jv.t -> t
|
val of_jv : Jv.t -> t
|
||||||
|
|
@ -38,5 +41,10 @@ val opt_to_string : opt -> string
|
||||||
(** [opt_to_jv opt] is [opt] as {!Jv.t} *)
|
(** [opt_to_jv opt] is [opt] as {!Jv.t} *)
|
||||||
val opt_to_jv : opt -> Jv.t
|
val opt_to_jv : opt -> Jv.t
|
||||||
|
|
||||||
(** [create options] is a new popup setup withs [options] *)
|
(** [create s latlng options] is a new popup setup with [options], position set
|
||||||
val create : opt list -> t
|
to [latlng] and content to [s] *)
|
||||||
|
val create : string option -> latlng:Latlng.t option -> opt list -> t
|
||||||
|
|
||||||
|
(** [create_from_el el latlng options] is a new popup setup with [options],
|
||||||
|
position set to [latlng] and content to [el] *)
|
||||||
|
val create_from_el : Brr.El.t -> latlng:Latlng.t option -> opt list -> t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue