add layer
This commit is contained in:
parent
d99eafccbf
commit
d9f25e4d8d
11 changed files with 123 additions and 35 deletions
2
src/dune
2
src/dune
|
|
@ -1,7 +1,7 @@
|
||||||
(library
|
(library
|
||||||
(name leaflet)
|
(name leaflet)
|
||||||
(public_name leaflet)
|
(public_name leaflet)
|
||||||
(modules ev latlng geojson_layer tile_layer popup marker map global)
|
(modules ev latlng geojson_layer tile_layer popup marker map global layer)
|
||||||
(libraries brr js_of_ocaml)
|
(libraries brr js_of_ocaml)
|
||||||
(js_of_ocaml
|
(js_of_ocaml
|
||||||
(javascript_files leaflet.js)))
|
(javascript_files leaflet.js)))
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
(*TODO merge with TileLayer*)
|
include Layer
|
||||||
type t = Jv.t
|
|
||||||
|
|
||||||
let create ?(options = Jv.null) geojson =
|
let create ?(options = Jv.null) geojson =
|
||||||
Jv.call Global.leaflet "geoJSON" [| geojson; options |]
|
of_jv_t @@ Jv.call Global.leaflet "geoJSON" [| geojson; options |]
|
||||||
|
|
||||||
let add_to layer map = ignore @@ Jv.call layer "addTo" [| Map.to_jv_t map |]
|
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,22 @@ type t
|
||||||
|
|
||||||
val create : ?options:Jv.t -> Jv.t -> t
|
val create : ?options:Jv.t -> Jv.t -> t
|
||||||
|
|
||||||
val add_to : t -> Map.t -> unit
|
val add_to : Map.t -> t -> unit
|
||||||
|
|
||||||
|
val remove : t -> unit
|
||||||
|
|
||||||
|
val remove_from : Map.t -> t -> unit
|
||||||
|
|
||||||
|
val bind_popup : Brr.El.t -> t -> unit
|
||||||
|
|
||||||
|
val unbind_popup : t -> unit
|
||||||
|
|
||||||
|
val open_popup : t -> unit
|
||||||
|
|
||||||
|
val close_popup : t -> unit
|
||||||
|
|
||||||
|
val get_popup : t -> Popup.t
|
||||||
|
|
||||||
|
val of_jv_t : Jv.t -> t
|
||||||
|
|
||||||
|
val to_jv_t : t -> Jv.t
|
||||||
|
|
|
||||||
23
src/layer.ml
Normal file
23
src/layer.ml
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
type t = Jv.t
|
||||||
|
|
||||||
|
let add_to map layer = ignore @@ Jv.call layer "addTo" [| Map.to_jv_t map |]
|
||||||
|
|
||||||
|
let remove layer = ignore @@ Jv.call layer "remove" [||]
|
||||||
|
|
||||||
|
let remove_from map layer =
|
||||||
|
ignore @@ Jv.call layer "removeFrom" [| Map.to_jv_t map |]
|
||||||
|
|
||||||
|
let bind_popup el layer =
|
||||||
|
ignore @@ Jv.call layer "bindPopup" [| Brr.El.to_jv el |]
|
||||||
|
|
||||||
|
let unbind_popup layer = ignore @@ Jv.call layer "unbindPopup" [||]
|
||||||
|
|
||||||
|
let open_popup layer = ignore @@ Jv.call layer "openPopup" [||]
|
||||||
|
|
||||||
|
let close_popup layer = ignore @@ Jv.call layer "closePopup" [||]
|
||||||
|
|
||||||
|
let get_popup layer = Popup.of_jv_t @@ Jv.call layer "getPopup" [||]
|
||||||
|
|
||||||
|
let of_jv_t = Fun.id
|
||||||
|
|
||||||
|
let to_jv_t = Fun.id
|
||||||
21
src/layer.mli
Normal file
21
src/layer.mli
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
type t
|
||||||
|
|
||||||
|
val add_to : Map.t -> t -> unit
|
||||||
|
|
||||||
|
val remove : t -> unit
|
||||||
|
|
||||||
|
val remove_from : Map.t -> t -> unit
|
||||||
|
|
||||||
|
val bind_popup : Brr.El.t -> t -> unit
|
||||||
|
|
||||||
|
val unbind_popup : t -> unit
|
||||||
|
|
||||||
|
val open_popup : t -> unit
|
||||||
|
|
||||||
|
val close_popup : t -> unit
|
||||||
|
|
||||||
|
val get_popup : t -> Popup.t
|
||||||
|
|
||||||
|
val of_jv_t : Jv.t -> t
|
||||||
|
|
||||||
|
val to_jv_t : t -> Jv.t
|
||||||
|
|
@ -1,11 +1,4 @@
|
||||||
type t = Jv.t
|
include Layer
|
||||||
|
|
||||||
let create latlng = Jv.call Global.leaflet "marker" [| Latlng.to_jv_t latlng |]
|
let create latlng =
|
||||||
|
of_jv_t @@ Jv.call Global.leaflet "marker" [| Latlng.to_jv_t latlng |]
|
||||||
let add_to marker map = ignore @@ Jv.call marker "addTo" [| Map.to_jv_t map |]
|
|
||||||
|
|
||||||
let bind_popup el marker =
|
|
||||||
ignore @@ Jv.call marker "bindPopup" [| Brr.El.to_jv el |];
|
|
||||||
marker
|
|
||||||
|
|
||||||
let open_popup marker = ignore @@ Jv.call marker "openPopup" [||]
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,22 @@ type t
|
||||||
|
|
||||||
val create : Latlng.t -> t
|
val create : Latlng.t -> t
|
||||||
|
|
||||||
val add_to : t -> Map.t -> unit
|
val add_to : Map.t -> t -> unit
|
||||||
|
|
||||||
(** {2 Popup methods} *)
|
val remove : t -> unit
|
||||||
|
|
||||||
val bind_popup : Brr.El.t -> t -> t
|
val remove_from : Map.t -> t -> unit
|
||||||
|
|
||||||
|
val bind_popup : Brr.El.t -> t -> unit
|
||||||
|
|
||||||
|
val unbind_popup : t -> unit
|
||||||
|
|
||||||
val open_popup : t -> unit
|
val open_popup : t -> unit
|
||||||
|
|
||||||
|
val close_popup : t -> unit
|
||||||
|
|
||||||
|
val get_popup : t -> Popup.t
|
||||||
|
|
||||||
|
val of_jv_t : Jv.t -> t
|
||||||
|
|
||||||
|
val to_jv_t : t -> Jv.t
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
type t = Jv.t
|
||||||
|
|
||||||
let popup = Jv.call Global.leaflet "popup" [||]
|
let popup = Jv.call Global.leaflet "popup" [||]
|
||||||
|
|
||||||
let set_latlng latlng =
|
let set_latlng latlng =
|
||||||
|
|
@ -9,3 +11,5 @@ let set_content content =
|
||||||
let open_on map = ignore @@ Jv.call popup "openOn" [| Map.to_jv_t map |]
|
let open_on map = ignore @@ Jv.call popup "openOn" [| Map.to_jv_t map |]
|
||||||
|
|
||||||
let close map = ignore @@ Jv.call (Map.to_jv_t map) "closePopup" [||]
|
let close map = ignore @@ Jv.call (Map.to_jv_t map) "closePopup" [||]
|
||||||
|
|
||||||
|
let of_jv_t = Fun.id
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
type t
|
||||||
|
|
||||||
val set_latlng : Latlng.t -> unit
|
val set_latlng : Latlng.t -> unit
|
||||||
|
|
||||||
val set_content : string -> unit
|
val set_content : string -> unit
|
||||||
|
|
@ -5,3 +7,5 @@ val set_content : string -> unit
|
||||||
val open_on : Map.t -> unit
|
val open_on : Map.t -> unit
|
||||||
|
|
||||||
val close : Map.t -> unit
|
val close : Map.t -> unit
|
||||||
|
|
||||||
|
val of_jv_t : Jv.t -> t
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
type t = Jv.t
|
include Layer
|
||||||
|
|
||||||
let create_osm ?tile_url () =
|
let create_osm ?tile_url () =
|
||||||
(* see https://wiki.openstreetmap.org/wiki/Tile_servers *)
|
(* see https://wiki.openstreetmap.org/wiki/Tile_servers *)
|
||||||
|
|
@ -6,7 +6,8 @@ let create_osm ?tile_url () =
|
||||||
Option.fold ~some:Fun.id
|
Option.fold ~some:Fun.id
|
||||||
~none:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" tile_url
|
~none:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" tile_url
|
||||||
in
|
in
|
||||||
Jv.call Global.leaflet "tileLayer"
|
of_jv_t
|
||||||
|
@@ Jv.call Global.leaflet "tileLayer"
|
||||||
[| Jv.of_string tile_url
|
[| Jv.of_string tile_url
|
||||||
; Jv.obj
|
; Jv.obj
|
||||||
[| ( "attribution"
|
[| ( "attribution"
|
||||||
|
|
@ -16,6 +17,3 @@ let create_osm ?tile_url () =
|
||||||
contributors" )
|
contributors" )
|
||||||
|]
|
|]
|
||||||
|]
|
|]
|
||||||
|
|
||||||
let add_to tile_layer map =
|
|
||||||
ignore @@ Jv.call tile_layer "addTo" [| Map.to_jv_t map |]
|
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,22 @@ type t
|
||||||
|
|
||||||
val create_osm : ?tile_url:string -> unit -> t
|
val create_osm : ?tile_url:string -> unit -> t
|
||||||
|
|
||||||
val add_to : t -> Map.t -> unit
|
val add_to : Map.t -> t -> unit
|
||||||
|
|
||||||
|
val remove : t -> unit
|
||||||
|
|
||||||
|
val remove_from : Map.t -> t -> unit
|
||||||
|
|
||||||
|
val bind_popup : Brr.El.t -> t -> unit
|
||||||
|
|
||||||
|
val unbind_popup : t -> unit
|
||||||
|
|
||||||
|
val open_popup : t -> unit
|
||||||
|
|
||||||
|
val close_popup : t -> unit
|
||||||
|
|
||||||
|
val get_popup : t -> Popup.t
|
||||||
|
|
||||||
|
val of_jv_t : Jv.t -> t
|
||||||
|
|
||||||
|
val to_jv_t : t -> Jv.t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue