better Layer.bind_popup and add Map.open/close_popup
This commit is contained in:
parent
8579b9aeed
commit
9c54ddab97
6 changed files with 21 additions and 24 deletions
12
src/layer.ml
12
src/layer.ml
|
|
@ -31,16 +31,10 @@ let remove_from : type kind. Map.t -> kind t -> unit =
|
|||
let (_ : Jv.t) = Jv.call l "removeFrom" [| Map.to_jv map |] in
|
||||
()
|
||||
|
||||
let bind_popup : type kind. Brr.El.t -> Popup.opt list -> kind t -> unit =
|
||||
fun el options -> function
|
||||
let bind_popup : type kind. Popup.t -> kind t -> unit =
|
||||
fun popup -> function
|
||||
| Basic layer | Geojson layer | Marker layer | Tile layer ->
|
||||
let l =
|
||||
Array.of_list
|
||||
@@ List.map (fun o -> (Popup.opt_to_string o, Popup.opt_to_jv o)) options
|
||||
in
|
||||
let (_ : Jv.t) =
|
||||
Jv.call layer "bindPopup" [| Brr.El.to_jv el; Jv.obj l |]
|
||||
in
|
||||
let (_ : Jv.t) = Jv.call layer "bindPopup" [| Popup.to_jv popup |] in
|
||||
()
|
||||
|
||||
let unbind_popup : type kind. kind t -> unit = function
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ val remove : _ t -> unit
|
|||
val remove_from : Map.t -> _ t -> unit
|
||||
|
||||
(** [bind_popup popup layer] binds [popup] to [layer] *)
|
||||
val bind_popup : Brr.El.t -> Popup.opt list -> _ t -> unit
|
||||
val bind_popup : Popup.t -> _ t -> unit
|
||||
|
||||
(** [unbind_popup layer] unbinds the popup bound to [layer] *)
|
||||
val unbind_popup : _ t -> unit
|
||||
|
|
|
|||
|
|
@ -46,3 +46,9 @@ let get_zoom map = Jv.call map "getZoom" [||] |> Jv.to_int
|
|||
|
||||
let wrap_latlng latlng map =
|
||||
Latlng.of_jv @@ Jv.call map "wrapLatLng" [| Latlng.to_jv latlng |]
|
||||
|
||||
let open_popup popup map =
|
||||
ignore @@ Jv.call map "openPopup" [| Popup.to_jv popup |]
|
||||
|
||||
let close_popup popup map =
|
||||
ignore @@ Jv.call map "closePopup" [| Popup.to_jv popup |]
|
||||
|
|
|
|||
|
|
@ -47,3 +47,9 @@ val of_jv : Jv.t -> t
|
|||
|
||||
(** [to_jv o] is [o] as {!Jv.t} *)
|
||||
val to_jv : t -> Jv.t
|
||||
|
||||
(* [open_popup popup map] opens [popup] on [map] *)
|
||||
val open_popup : Popup.t -> t -> unit
|
||||
|
||||
(* [close_popup popup map] closes [popup] on [map] *)
|
||||
val close_popup : Popup.t -> t -> unit
|
||||
|
|
|
|||
10
src/popup.ml
10
src/popup.ml
|
|
@ -12,16 +12,10 @@ let set_content content =
|
|||
let (_ : Jv.t) = Jv.call popup "setContent" [| Jv.of_string content |] in
|
||||
()
|
||||
|
||||
let open_on map =
|
||||
let (_ : Jv.t) = Jv.call popup "openOn" [| Map.to_jv map |] in
|
||||
()
|
||||
|
||||
let close map =
|
||||
let (_ : Jv.t) = Jv.call (Map.to_jv map) "closePopup" [||] in
|
||||
()
|
||||
|
||||
let of_jv = Fun.id
|
||||
|
||||
let to_jv = Fun.id
|
||||
|
||||
type opt =
|
||||
| Pane of string
|
||||
| Offset of Point.t
|
||||
|
|
|
|||
|
|
@ -26,15 +26,12 @@ val set_latlng : Latlng.t -> unit
|
|||
(** [set_content s] changes the popup content to [s]*)
|
||||
val set_content : string -> unit
|
||||
|
||||
(** [open_on map] * Adds the popup to [map] and closes the previous one. *)
|
||||
val open_on : Map.t -> unit
|
||||
|
||||
(** [close map] * closes the popup of [map]*)
|
||||
val close : Map.t -> unit
|
||||
|
||||
(** [of_jv jv] is [jv] as {!t} *)
|
||||
val of_jv : Jv.t -> t
|
||||
|
||||
(** [to_jv o] is [o] as {!Jv.t} *)
|
||||
val to_jv : t -> Jv.t
|
||||
|
||||
(** [opt_to_string opt] is [opt] as {!string} *)
|
||||
val opt_to_string : opt -> string
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue