move marker to separate module

This commit is contained in:
Swrup 2024-01-29 22:07:41 +01:00
parent 2177dec31e
commit 4ef2368dc7
5 changed files with 117 additions and 117 deletions

View file

@ -139,80 +139,3 @@ let create_tile_osm : string option -> [ `Tile ] t =
|]
in
Tile jv_t
(** Marker layers *)
(* TODO make a Marker module? *)
type marker_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 marker_opt_to_string : marker_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 marker_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_marker : Latlng.t -> marker_opt list -> [ `Marker ] t =
fun latlng options ->
let l =
Array.of_list
@@ List.map (fun o -> (marker_opt_to_string o, marker_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 : [ `Marker ] t -> Latlng.t = function
| Marker marker -> Jv.call marker "getLatLng" [||] |> Latlng.of_jv
let set_latlng latlng : [ `Marker ] t -> unit = function
| Marker marker ->
let (_ : Jv.t) = Jv.call marker "setLatLng" [| Latlng.to_jv latlng |] in
()
let set_z_index_offset z_index : [ `Marker ] t -> unit = function
| Marker marker ->
let (_ : Jv.t) = Jv.call marker "setZIndexOffset" [| Jv.of_int z_index |] in
()
let get_icon : [ `Marker ] t -> Icon.t = function
| Marker marker -> Jv.call marker "getIcon" [||] |> Icon.of_jv
let set_icon icon : [ `Marker ] t -> unit = function
| Marker marker ->
let (_ : Jv.t) = Jv.call marker "setIcon" [| Icon.to_jv icon |] in
()
let set_opacity opacity : [ `Marker ] t -> unit = function
| Marker marker ->
let (_ : Jv.t) = Jv.call marker "setOpacity" [| Jv.of_int opacity |] in
()