more marker function

This commit is contained in:
Swrup 2022-11-24 19:22:18 +01:00
parent 6f1e93eab6
commit be85daf71b
2 changed files with 70 additions and 25 deletions

View file

@ -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
"&copy; <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
"&copy; <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
()