add popup options
This commit is contained in:
parent
a438e54f42
commit
ede9b2076d
6 changed files with 101 additions and 9 deletions
|
|
@ -45,5 +45,5 @@ let opt_to_jv = function
|
||||||
|
|
||||||
let create icon_url options =
|
let create icon_url options =
|
||||||
let l = List.map (fun o -> (to_string o, opt_to_jv o)) options in
|
let l = List.map (fun o -> (to_string o, opt_to_jv o)) options in
|
||||||
let tab = Array.of_list @@ (("iconUrl", Jv.of_string icon_url) :: l) in
|
let l = Array.of_list @@ (("iconUrl", Jv.of_string icon_url) :: l) in
|
||||||
Jv.call Global.leaflet "icon" [| Jv.obj tab |]
|
Jv.call Global.leaflet "icon" [| Jv.obj l |]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ type t
|
||||||
(** [to_jv o] is [o] as {!Jv.t} *)
|
(** [to_jv o] is [o] as {!Jv.t} *)
|
||||||
val to_jv : t -> Jv.t
|
val to_jv : t -> Jv.t
|
||||||
|
|
||||||
(* type for icon option used to create an icon*)
|
(** type for icon option used to create an icon*)
|
||||||
type opt =
|
type opt =
|
||||||
| Icon_retina_url of string
|
| Icon_retina_url of string
|
||||||
| Icon_size of Point.t
|
| Icon_size of Point.t
|
||||||
|
|
|
||||||
19
src/layer.ml
19
src/layer.ml
|
|
@ -31,10 +31,16 @@ 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 -> ?options:Jv.t -> kind t -> unit =
|
let bind_popup : type kind. Brr.El.t -> Popup.opt list -> kind t -> unit =
|
||||||
fun el ?(options = Jv.null) -> function
|
fun el options -> function
|
||||||
| Basic l | Geojson l | Marker l | Tile l ->
|
| Basic layer | Geojson layer | Marker layer | Tile layer ->
|
||||||
let (_ : Jv.t) = Jv.call l "bindPopup" [| Brr.El.to_jv el; options |] in
|
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 unbind_popup : type kind. kind t -> unit = function
|
let unbind_popup : type kind. kind t -> unit = function
|
||||||
|
|
@ -98,7 +104,10 @@ let geojson_opt_to_jv = function
|
||||||
| Markers_inherit_options b -> Jv.of_bool b
|
| Markers_inherit_options b -> Jv.of_bool b
|
||||||
| Point_to_layer f -> Jv.repr f
|
| Point_to_layer f -> Jv.repr f
|
||||||
| Style f -> Jv.repr f
|
| Style f -> Jv.repr f
|
||||||
| On_each_feature f -> Jv.repr f
|
| On_each_feature f ->
|
||||||
|
(* we need to wrap the Jv.t *)
|
||||||
|
let f feature jv = jv |> of_jv Geojson |> f feature in
|
||||||
|
Jv.repr f
|
||||||
| Filter f -> Jv.repr f
|
| Filter f -> Jv.repr f
|
||||||
| Coords_to_latlng f -> Jv.repr f
|
| Coords_to_latlng f -> Jv.repr f
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,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 -> ?options:Jv.t -> _ t -> unit
|
val bind_popup : Brr.El.t -> Popup.opt list -> _ 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
|
||||||
|
|
|
||||||
56
src/popup.ml
56
src/popup.ml
|
|
@ -21,3 +21,59 @@ let close map =
|
||||||
()
|
()
|
||||||
|
|
||||||
let of_jv = Fun.id
|
let of_jv = Fun.id
|
||||||
|
|
||||||
|
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 |]
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,24 @@
|
||||||
|
|
||||||
type t
|
type t
|
||||||
|
|
||||||
|
(** type for popup option used to create an popup*)
|
||||||
|
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
|
||||||
|
|
||||||
(** [set_latlng latlng] changes the popup position to the given point*)
|
(** [set_latlng latlng] changes the popup position to the given point*)
|
||||||
val set_latlng : Latlng.t -> unit
|
val set_latlng : Latlng.t -> unit
|
||||||
|
|
||||||
|
|
@ -16,3 +34,12 @@ val close : Map.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
|
||||||
|
|
||||||
|
(** [opt_to_string opt] is [opt] as {!string} *)
|
||||||
|
val opt_to_string : opt -> string
|
||||||
|
|
||||||
|
(** [opt_to_jv opt] is [opt] as {!Jv.t} *)
|
||||||
|
val opt_to_jv : opt -> Jv.t
|
||||||
|
|
||||||
|
(** [create options] is a new popup setup withs [options] *)
|
||||||
|
val create : opt list -> t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue