move marker to separate module
This commit is contained in:
parent
2177dec31e
commit
4ef2368dc7
5 changed files with 117 additions and 117 deletions
2
src/dune
2
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
|
||||
|
|
|
|||
77
src/layer.ml
77
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
|
||||
()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
78
src/marker.ml
Normal file
78
src/marker.ml
Normal file
|
|
@ -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
|
||||
()
|
||||
38
src/marker.mli
Normal file
38
src/marker.mli
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue