more marker function
This commit is contained in:
parent
96f1839680
commit
d0c4f09b11
2 changed files with 70 additions and 25 deletions
67
src/layer.ml
67
src/layer.ml
|
|
@ -118,7 +118,30 @@ let create_geojson : Jv.t -> geojson_opt list -> [ `Geojson ] t =
|
|||
let jv_t = Jv.call Global.leaflet "geoJSON" [| geojson; Jv.obj l |] in
|
||||
Geojson jv_t
|
||||
|
||||
(** Tile layers *)
|
||||
|
||||
let create_tile_osm : string option -> [ `Tile ] t =
|
||||
fun url ->
|
||||
let url =
|
||||
Option.value url
|
||||
~default:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
in
|
||||
let jv_t =
|
||||
Jv.call Global.leaflet "tileLayer"
|
||||
[| Jv.of_string url
|
||||
; Jv.obj
|
||||
[| ( "attribution"
|
||||
, Jv.of_string
|
||||
"© <a \
|
||||
href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> \
|
||||
contributors" )
|
||||
|]
|
||||
|]
|
||||
in
|
||||
Tile jv_t
|
||||
|
||||
(** Marker layers *)
|
||||
(* TODO make a Marker module? *)
|
||||
|
||||
type marker_opt =
|
||||
| Icon of Icon.t
|
||||
|
|
@ -168,24 +191,28 @@ let create_marker : Latlng.t -> marker_opt list -> [ `Marker ] t =
|
|||
in
|
||||
Marker jv_t
|
||||
|
||||
(** Tile layers *)
|
||||
let get_latlng : [ `Marker ] t -> Latlng.t = function
|
||||
| Marker marker -> Jv.call marker "getLatLng" [||] |> Latlng.of_jv
|
||||
|
||||
let create_tile_osm : string option -> [ `Tile ] t =
|
||||
fun url ->
|
||||
let url =
|
||||
Option.value url
|
||||
~default:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
in
|
||||
let jv_t =
|
||||
Jv.call Global.leaflet "tileLayer"
|
||||
[| Jv.of_string url
|
||||
; Jv.obj
|
||||
[| ( "attribution"
|
||||
, Jv.of_string
|
||||
"© <a \
|
||||
href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> \
|
||||
contributors" )
|
||||
|]
|
||||
|]
|
||||
in
|
||||
Tile jv_t
|
||||
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
|
||||
()
|
||||
|
|
|
|||
|
|
@ -62,6 +62,13 @@ type geojson_opt =
|
|||
(** [create_geojson geojson] is a new geojson layer *)
|
||||
val create_geojson : Jv.t -> geojson_opt list -> [ `Geojson ] t
|
||||
|
||||
(** Tile layers *)
|
||||
|
||||
(** [create_tile_osm Some(url)] is a new tile layer with tile server specified
|
||||
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 *)
|
||||
|
|
@ -83,9 +90,20 @@ type marker_opt =
|
|||
[latlng] and with options set to [options] *)
|
||||
val create_marker : Latlng.t -> marker_opt list -> [ `Marker ] t
|
||||
|
||||
(** Tile layers *)
|
||||
(** Returns the current geographical position of the marker. *)
|
||||
val get_latlng : [ `Marker ] t -> Latlng.t
|
||||
|
||||
(** [create_tile_osm Some(url)] is a new tile layer with tile server specified
|
||||
by [url]. Tile server default to [openstreetmap.org]. See
|
||||
{:https://wiki.openstreetmap.org/wiki/Tile_servers} *)
|
||||
val create_tile_osm : string option -> [ `Tile ] 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue