From ce9cdc206dc890cb282e1df923a23eb2494f296e Mon Sep 17 00:00:00 2001 From: Swrup Date: Mon, 29 Jan 2024 22:07:41 +0100 Subject: [PATCH] move marker to separate module --- src/dune | 2 +- src/layer.ml | 77 ------------------------------------------------- src/layer.mli | 39 ------------------------- src/marker.ml | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/marker.mli | 38 ++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 117 deletions(-) create mode 100644 src/marker.ml create mode 100644 src/marker.mli diff --git a/src/dune b/src/dune index 52d85ee..c29d930 100644 --- a/src/dune +++ b/src/dune @@ -1,6 +1,6 @@ (library (public_name leaflet) - (modules event global latlng layer map popup point icon) + (modules event global latlng layer map marker popup point icon) (private_modules global) (libraries brr) (js_of_ocaml diff --git a/src/layer.ml b/src/layer.ml index f98de08..e6ac275 100644 --- a/src/layer.ml +++ b/src/layer.ml @@ -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 - () diff --git a/src/layer.mli b/src/layer.mli index 84586d7..10cedc2 100644 --- a/src/layer.mli +++ b/src/layer.mli @@ -68,42 +68,3 @@ val create_geojson : Jv.t -> geojson_opt list -> [ `Geojson ] t by [url]. Tile server default to [openstreetmap.org]. See {:https://wiki.openstreetmap.org/wiki/Tile_servers} *) val create_tile_osm : string option -> [ `Tile ] t - -(** Marker layers *) - -(** type for marker option, used to create marker *) -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 - -(** [create_marker latlng options] is a new marker with the same position as - [latlng] and with options set to [options] *) -val create_marker : Latlng.t -> marker_opt list -> [ `Marker ] t - -(** Returns the current geographical position of the marker. *) -val get_latlng : [ `Marker ] t -> Latlng.t - -(** Changes the marker position to the given point. *) -val set_latlng : Latlng.t -> [ `Marker ] t -> unit - -(** Changes the zIndex offset of the marker. *) -val set_z_index_offset : int -> [ `Marker ] t -> unit - -(** Returns the current icon used by the marker *) -val get_icon : [ `Marker ] t -> Icon.t - -(** Changes the marker icon. *) -val set_icon : Icon.t -> [ `Marker ] t -> unit - -(** Changes the opacity of the marker. *) -val set_opacity : int -> [ `Marker ] t -> unit diff --git a/src/marker.ml b/src/marker.ml new file mode 100644 index 0000000..16a99c0 --- /dev/null +++ b/src/marker.ml @@ -0,0 +1,78 @@ +(** Marker layers *) +include Layer + +type t = [ `Marker ] Layer.t + +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 -> 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 : 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 + () diff --git a/src/marker.mli b/src/marker.mli new file mode 100644 index 0000000..538ac95 --- /dev/null +++ b/src/marker.mli @@ -0,0 +1,38 @@ +type t = [ `Marker ] Layer.t + +(** type for marker option, used to create marker *) +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 + +(** [create_marker latlng options] is a new marker with the same position as + [latlng] and with options set to [options] *) +val create_marker : Latlng.t -> marker_opt list -> t + +(** Returns the current geographical position of the marker. *) +val get_latlng : t -> Latlng.t + +(** Changes the marker position to the given point. *) +val set_latlng : Latlng.t -> t -> unit + +(** Changes the zIndex offset of the marker. *) +val set_z_index_offset : int -> t -> unit + +(** Returns the current icon used by the marker *) +val get_icon : t -> Icon.t + +(** Changes the marker icon. *) +val set_icon : Icon.t -> t -> unit + +(** Changes the opacity of the marker. *) +val set_opacity : int -> t -> unit