leaflet/src/marker.ml
2024-01-30 16:55:19 +01:00

76 lines
2.1 KiB
OCaml

(** Marker layers *)
include Layer
type t = [ `Marker ] Layer.t
type opt =
| Icon of Icon.t
| Keyboard of bool
| Title of string
| Alt of string
| Z_index_offset of int
| Opacity of float
| Rise_on_hover of bool
| Rise_offset of int
| Pane of string
| Shadow_pane of string
| Bubbling_mouse_events of bool
| Auto_pan_on_focus of bool
let opt_to_string : opt -> string = function
| Icon _ -> "icon"
| Keyboard _ -> "keyboard"
| Title _ -> "title"
| Alt _ -> "alt"
| Z_index_offset _ -> "zIndexOffset"
| Opacity _ -> "opacity"
| Rise_on_hover _ -> "riseOnHover"
| Rise_offset _ -> "riseOffset"
| Pane _ -> "pane"
| Shadow_pane _ -> "shadowPane"
| Bubbling_mouse_events _ -> "bubblingMouseEvents"
| Auto_pan_on_focus _ -> "autoPanOnFocus"
let opt_to_jv = function
| Icon icon -> Icon.to_jv icon
| Keyboard b | Rise_on_hover b | Bubbling_mouse_events b | Auto_pan_on_focus b
->
Jv.of_bool b
| Title s | Alt s | Pane s | Shadow_pane s -> Jv.of_string s
| Z_index_offset i | Rise_offset i -> Jv.of_int i
| Opacity f -> Jv.of_float f
let create : Latlng.t -> opt array -> t =
fun latlng options ->
let l = Array.map (fun o -> (opt_to_string o, opt_to_jv o)) options in
let jv_t =
Jv.call Global.leaflet "marker" [| Latlng.to_jv latlng; Jv.obj l |]
in
Marker jv_t
let get_latlng : t -> Latlng.t = function
| Marker marker -> Jv.call marker "getLatLng" [||] |> Latlng.of_jv
let set_latlng latlng : t -> unit = function
| Marker marker ->
let (_ : Jv.t) = Jv.call marker "setLatLng" [| Latlng.to_jv latlng |] in
()
let set_z_index_offset z_index : t -> unit = function
| Marker marker ->
let (_ : Jv.t) = Jv.call marker "setZIndexOffset" [| Jv.of_int z_index |] in
()
let get_icon : t -> Icon.t = function
| Marker marker -> Jv.call marker "getIcon" [||] |> Icon.of_jv
let set_icon icon : t -> unit = function
| Marker marker ->
let (_ : Jv.t) = Jv.call marker "setIcon" [| Icon.to_jv icon |] in
()
let set_opacity opacity : t -> unit = function
| Marker marker ->
let (_ : Jv.t) = Jv.call marker "setOpacity" [| Jv.of_int opacity |] in
()