add of_jv, on, ?options for bind_popup

This commit is contained in:
Swrup 2022-06-20 06:52:05 +02:00
parent 10aaf21209
commit 5fecae013c
2 changed files with 40 additions and 4 deletions

View file

@ -6,6 +6,12 @@ type _ t =
| Marker : Jv.t -> [> `Marker ] t | Marker : Jv.t -> [> `Marker ] t
| Tile : Jv.t -> [> `Tile ] t | Tile : Jv.t -> [> `Tile ] t
type _ sub =
| Basic : [> `Basic ] sub
| Geojson : [> `Geojson ] sub
| Marker : [> `Marker ] sub
| Tile : [> `Tile ] sub
(** Basic layers *) (** Basic layers *)
let add_to : type kind. Map.t -> kind t -> unit = let add_to : type kind. Map.t -> kind t -> unit =
@ -25,10 +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 (_ : Jv.t) = Jv.call l "removeFrom" [| Map.to_jv map |] in
() ()
let bind_popup : type kind. Brr.El.t -> kind t -> unit = let bind_popup : type kind. Brr.El.t -> ?options:Jv.t -> kind t -> unit =
fun el -> function fun el ?(options = Jv.null) -> function
| Basic l | Geojson l | Marker l | Tile l -> | Basic l | Geojson l | Marker l | Tile l ->
let (_ : Jv.t) = Jv.call l "bindPopup" [| Brr.El.to_jv el |] in let (_ : Jv.t) = Jv.call l "bindPopup" [| Brr.El.to_jv el; options |] in
() ()
let unbind_popup : type kind. kind t -> unit = function let unbind_popup : type kind. kind t -> unit = function
@ -53,6 +59,23 @@ let get_popup : type kind. kind t -> Popup.t = function
let to_jv : type kind. kind t -> Jv.t = function let to_jv : type kind. kind t -> Jv.t = function
| Basic l | Geojson l | Marker l | Tile l -> l | Basic l | Geojson l | Marker l | Tile l -> l
let of_jv : type kind. kind sub -> Jv.t -> kind t =
fun tag l ->
match tag with
| Basic -> Basic l
| Geojson -> Geojson l
| Marker -> Marker l
| Tile -> Tile l
let on : type kind. kind Event.sub -> (kind Event.t -> 'b) -> 'c t -> unit =
fun event handler layer ->
let name = Event.sub_to_string event in
let handler v = handler @@ Event.of_jv event v in
let (_ : Jv.t) =
Jv.call (to_jv layer) "on" [| Jv.of_string name; Jv.repr handler |]
in
()
(** Geojson layers *) (** Geojson layers *)
let create_geojson : ?options:Jv.t -> Jv.t -> [ `Geojson ] t = let create_geojson : ?options:Jv.t -> Jv.t -> [ `Geojson ] t =

View file

@ -6,6 +6,12 @@ type _ t =
| Marker : Jv.t -> [> `Marker ] t | Marker : Jv.t -> [> `Marker ] t
| Tile : Jv.t -> [> `Tile ] t | Tile : Jv.t -> [> `Tile ] t
type _ sub =
| Basic : [> `Basic ] sub
| Geojson : [> `Geojson ] sub
| Marker : [> `Marker ] sub
| Tile : [> `Tile ] sub
(** Basic layers *) (** Basic layers *)
(** [add_to map layer] adds [layer] to [map] *) (** [add_to map layer] adds [layer] to [map] *)
@ -18,7 +24,7 @@ val remove : _ t -> unit
val remove_from : Map.t -> _ t -> unit val remove_from : Map.t -> _ t -> unit
(** [bind_popup popup layer] binds [popup] to [layer] *) (** [bind_popup popup layer] binds [popup] to [layer] *)
val bind_popup : Brr.El.t -> _ t -> unit val bind_popup : Brr.El.t -> ?options:Jv.t -> _ t -> unit
(** [unbind_popup layer] unbinds the popup bound to [layer] *) (** [unbind_popup layer] unbinds the popup bound to [layer] *)
val unbind_popup : _ t -> unit val unbind_popup : _ t -> unit
@ -35,6 +41,13 @@ val get_popup : _ t -> Popup.t
(** [to_jv o] is [o] as a {!Jv.t} *) (** [to_jv o] is [o] as a {!Jv.t} *)
val to_jv : _ t -> Jv.t val to_jv : _ t -> Jv.t
(** [of_jv tag o] is [o] as a [tag t] *)
val of_jv : 'a sub -> Jv.t -> 'a t
(** [on event handler layer] add an event listener on [layer] for event [event]
with handler [handler] *)
val on : 'a Event.sub -> ('a Event.t -> 'b) -> 'c t -> unit
(** Geojson layers *) (** Geojson layers *)
(** [create_geojson geojson] is a new geojson layer *) (** [create_geojson geojson] is a new geojson layer *)