add polyline layer

This commit is contained in:
Swrup 2024-01-30 00:48:37 +01:00
parent 85181f784a
commit d7de66c1be
2 changed files with 25 additions and 9 deletions

View file

@ -5,59 +5,61 @@ type _ t =
| Geojson : Jv.t -> [> `Geojson ] t
| Marker : Jv.t -> [> `Marker ] t
| Tile : Jv.t -> [> `Tile ] t
| Vector : Jv.t -> [> `Vector ] t
type _ sub =
| Basic : [> `Basic ] sub
| Geojson : [> `Geojson ] sub
| Marker : [> `Marker ] sub
| Tile : [> `Tile ] sub
| Vector : [> `Vector ] sub
(** Basic layers *)
let add_to : type kind. Map.t -> kind t -> unit =
fun map -> function
| Basic l | Geojson l | Marker l | Tile l ->
| Basic l | Geojson l | Marker l | Tile l | Vector l ->
let (_ : Jv.t) = Jv.call l "addTo" [| Map.to_jv map |] in
()
let remove : type kind. kind t -> unit = function
| Basic l | Geojson l | Marker l | Tile l ->
| Basic l | Geojson l | Marker l | Tile l | Vector l ->
let (_ : Jv.t) = Jv.call l "remove" [||] in
()
let remove_from : type kind. Map.t -> kind t -> unit =
fun map -> function
| Basic l | Geojson l | Marker l | Tile l ->
| Basic l | Geojson l | Marker l | Tile l | Vector l ->
let (_ : Jv.t) = Jv.call l "removeFrom" [| Map.to_jv map |] in
()
let bind_popup : type kind. Popup.t -> kind t -> unit =
fun popup -> function
| Basic layer | Geojson layer | Marker layer | Tile layer ->
| Basic layer | Geojson layer | Marker layer | Tile layer | Vector layer ->
let (_ : Jv.t) = Jv.call layer "bindPopup" [| Popup.to_jv popup |] in
()
let unbind_popup : type kind. kind t -> unit = function
| Basic l | Geojson l | Marker l | Tile l ->
| Basic l | Geojson l | Marker l | Tile l | Vector l ->
let (_ : Jv.t) = Jv.call l "unbindPopup" [||] in
()
let open_popup : type kind. kind t -> unit = function
| Basic l | Geojson l | Marker l | Tile l ->
| Basic l | Geojson l | Marker l | Tile l | Vector l ->
let (_ : Jv.t) = Jv.call l "openPopup" [||] in
()
let close_popup : type kind. kind t -> unit = function
| Basic l | Geojson l | Marker l | Tile l ->
| Basic l | Geojson l | Marker l | Tile l | Vector l ->
let (_ : Jv.t) = Jv.call l "closePopup" [||] in
()
let get_popup : type kind. kind t -> Popup.t = function
| Basic l | Geojson l | Marker l | Tile l ->
| Basic l | Geojson l | Marker l | Tile l | Vector l ->
Jv.call l "getPopup" [||] |> Popup.of_jv
let to_jv : type kind. kind t -> Jv.t = function
| Basic l | Geojson l | Marker l | Tile l -> l
| Basic l | Geojson l | Marker l | Tile l | Vector l -> l
let of_jv : type kind. kind sub -> Jv.t -> kind t =
fun tag l ->
@ -66,6 +68,7 @@ let of_jv : type kind. kind sub -> Jv.t -> kind t =
| Geojson -> Geojson l
| Marker -> Marker l
| Tile -> Tile l
| Vector -> Vector l
let on : type kind. kind Event.sub -> (kind Event.t -> 'b) -> 'c t -> unit =
fun event handler layer ->
@ -225,3 +228,11 @@ let create_tile_osm : tile_layer_opt list -> [ `Tile ] t =
contributors"
in
create_tile url ~attribution options
(* Vector Layers *)
let create_polyline : Latlng.t list -> [ `Vector ] t =
fun l ->
let l = Jv.of_list Latlng.to_jv l in
let jv_t = Jv.call Global.leaflet "polyline" [| l |] in
Vector jv_t

View file

@ -5,12 +5,14 @@ type _ t =
| Geojson : Jv.t -> [> `Geojson ] t
| Marker : Jv.t -> [> `Marker ] t
| Tile : Jv.t -> [> `Tile ] t
| Vector : Jv.t -> [> `Vector ] t
type _ sub =
| Basic : [> `Basic ] sub
| Geojson : [> `Geojson ] sub
| Marker : [> `Marker ] sub
| Tile : [> `Tile ] sub
| Vector : [> `Vector ] sub
(** Basic layers *)
@ -97,3 +99,6 @@ val create_tile :
attribution set to [openstreetmap.org]. See
{:https://wiki.openstreetmap.org/wiki/Tile_servers} *)
val create_tile_osm : tile_layer_opt list -> [ `Tile ] t
(** [create_polyline l] create a polyline layer from [l] *)
val create_polyline : Latlng.t list -> [ `Vector ] t