list -> array
This commit is contained in:
parent
d7de66c1be
commit
59e22333e7
9 changed files with 30 additions and 39 deletions
|
|
@ -4,7 +4,7 @@ let map = Leaflet.Map.create_on "map"
|
||||||
(* setup map *)
|
(* setup map *)
|
||||||
let () =
|
let () =
|
||||||
(* set osm layer *)
|
(* set osm layer *)
|
||||||
let osm_layer = Leaflet.Layer.create_tile_osm [] in
|
let osm_layer = Leaflet.Layer.create_tile_osm [||] in
|
||||||
Leaflet.Layer.add_to map osm_layer;
|
Leaflet.Layer.add_to map osm_layer;
|
||||||
|
|
||||||
(* set view *)
|
(* set view *)
|
||||||
|
|
|
||||||
10
src/icon.ml
10
src/icon.ml
|
|
@ -46,12 +46,12 @@ let opt_to_jv = function
|
||||||
match o with Some s -> Jv.of_string s | None -> Jv.of_bool false )
|
match o with Some s -> Jv.of_string s | None -> Jv.of_bool false )
|
||||||
|
|
||||||
let create icon_url options =
|
let create icon_url options =
|
||||||
let l = List.map (fun o -> (to_string o, opt_to_jv o)) options in
|
let l = Array.map (fun o -> (to_string o, opt_to_jv o)) options in
|
||||||
let l = Array.of_list @@ (("iconUrl", Jv.of_string icon_url) :: l) in
|
let l = Array.append [| ("iconUrl", Jv.of_string icon_url) |] l in
|
||||||
Jv.call Global.leaflet "icon" [| Jv.obj l |]
|
Jv.call Global.leaflet "icon" [| Jv.obj l |]
|
||||||
|
|
||||||
let create_div ~html ~bg_pos options =
|
let create_div ~html ~bg_pos options =
|
||||||
let l = List.map (fun o -> (to_string o, opt_to_jv o)) options in
|
let l = Array.map (fun o -> (to_string o, opt_to_jv o)) options in
|
||||||
let div_options =
|
let div_options =
|
||||||
let html =
|
let html =
|
||||||
match html with
|
match html with
|
||||||
|
|
@ -63,9 +63,9 @@ let create_div ~html ~bg_pos options =
|
||||||
| None -> []
|
| None -> []
|
||||||
| Some bg_pos -> [ ("bgPos", Point.to_jv bg_pos) ]
|
| Some bg_pos -> [ ("bgPos", Point.to_jv bg_pos) ]
|
||||||
in
|
in
|
||||||
html @ bg_pos
|
html @ bg_pos |> Array.of_list
|
||||||
in
|
in
|
||||||
let l = Array.of_list @@ div_options @ l in
|
let l = Array.append div_options l in
|
||||||
Jv.call Global.leaflet "divIcon" [| Jv.obj l |]
|
Jv.call Global.leaflet "divIcon" [| Jv.obj l |]
|
||||||
|
|
||||||
let set_default_image_path s =
|
let set_default_image_path s =
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,13 @@ type opt =
|
||||||
|
|
||||||
(** [create icon_url options] Creates an icon instance with the given [options],
|
(** [create icon_url options] Creates an icon instance with the given [options],
|
||||||
and the required `iconUrl` option set to [icon_url] *)
|
and the required `iconUrl` option set to [icon_url] *)
|
||||||
val create : string -> opt list -> t
|
val create : string -> opt array -> t
|
||||||
|
|
||||||
(** [create_div ~html ~bg_pos options] Creates an DivIcon instance with the
|
(** [create_div ~html ~bg_pos options] Creates an DivIcon instance with the
|
||||||
given [options], [bg_pos] is the optional relative position of the
|
given [options], [bg_pos] is the optional relative position of the
|
||||||
background, in pixels [html] is custom HTML code to put inside the div
|
background, in pixels [html] is custom HTML code to put inside the div
|
||||||
element, empty by default. *)
|
element, empty by default. *)
|
||||||
val create_div : html:string option -> bg_pos:Point.t option -> opt list -> t
|
val create_div : html:string option -> bg_pos:Point.t option -> opt array -> t
|
||||||
|
|
||||||
(** Sets the path of the default icon *)
|
(** Sets the path of the default icon *)
|
||||||
val set_default_image_path : string -> unit
|
val set_default_image_path : string -> unit
|
||||||
|
|
|
||||||
23
src/layer.ml
23
src/layer.ml
|
|
@ -110,13 +110,10 @@ let geojson_opt_to_jv = function
|
||||||
| Filter f -> Jv.repr f
|
| Filter f -> Jv.repr f
|
||||||
| Coords_to_latlng f -> Jv.repr f
|
| Coords_to_latlng f -> Jv.repr f
|
||||||
|
|
||||||
let create_geojson : Jv.t -> geojson_opt list -> [ `Geojson ] t =
|
let create_geojson : Jv.t -> geojson_opt array -> [ `Geojson ] t =
|
||||||
fun geojson options ->
|
fun geojson options ->
|
||||||
let l =
|
let l =
|
||||||
Array.of_list
|
Array.map (fun o -> (geojson_opt_to_string o, geojson_opt_to_jv o)) options
|
||||||
@@ List.map
|
|
||||||
(fun o -> (geojson_opt_to_string o, geojson_opt_to_jv o))
|
|
||||||
options
|
|
||||||
in
|
in
|
||||||
let jv_t = Jv.call Global.leaflet "geoJSON" [| geojson; Jv.obj l |] in
|
let jv_t = Jv.call Global.leaflet "geoJSON" [| geojson; Jv.obj l |] in
|
||||||
Geojson jv_t
|
Geojson jv_t
|
||||||
|
|
@ -205,21 +202,21 @@ let tile_layer_opt_to_jv = function
|
||||||
Jv.call Global.leaflet "latLngBounds" [| Latlng.to_jv a; Latlng.to_jv b |]
|
Jv.call Global.leaflet "latLngBounds" [| Latlng.to_jv a; Latlng.to_jv b |]
|
||||||
|
|
||||||
let create_tile :
|
let create_tile :
|
||||||
string -> attribution:string -> tile_layer_opt list -> [ `Tile ] t =
|
string -> attribution:string -> tile_layer_opt array -> [ `Tile ] t =
|
||||||
fun url ~attribution options ->
|
fun url ~attribution options ->
|
||||||
let arr =
|
let arr =
|
||||||
Array.of_list
|
Array.append
|
||||||
@@ ("attribution", Jv.of_string attribution)
|
[| ("attribution", Jv.of_string attribution) |]
|
||||||
:: List.map
|
(Array.map
|
||||||
(fun o -> (tile_layer_opt_to_string o, tile_layer_opt_to_jv o))
|
(fun o -> (tile_layer_opt_to_string o, tile_layer_opt_to_jv o))
|
||||||
options
|
options )
|
||||||
in
|
in
|
||||||
let jv_t =
|
let jv_t =
|
||||||
Jv.call Global.leaflet "tileLayer" [| Jv.of_string url; Jv.obj arr |]
|
Jv.call Global.leaflet "tileLayer" [| Jv.of_string url; Jv.obj arr |]
|
||||||
in
|
in
|
||||||
Tile jv_t
|
Tile jv_t
|
||||||
|
|
||||||
let create_tile_osm : tile_layer_opt list -> [ `Tile ] t =
|
let create_tile_osm : tile_layer_opt array -> [ `Tile ] t =
|
||||||
fun options ->
|
fun options ->
|
||||||
let url = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" in
|
let url = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" in
|
||||||
let attribution =
|
let attribution =
|
||||||
|
|
@ -231,8 +228,8 @@ let create_tile_osm : tile_layer_opt list -> [ `Tile ] t =
|
||||||
|
|
||||||
(* Vector Layers *)
|
(* Vector Layers *)
|
||||||
|
|
||||||
let create_polyline : Latlng.t list -> [ `Vector ] t =
|
let create_polyline : Latlng.t array -> [ `Vector ] t =
|
||||||
fun l ->
|
fun l ->
|
||||||
let l = Jv.of_list Latlng.to_jv l in
|
let l = Jv.of_array Latlng.to_jv l in
|
||||||
let jv_t = Jv.call Global.leaflet "polyline" [| l |] in
|
let jv_t = Jv.call Global.leaflet "polyline" [| l |] in
|
||||||
Vector jv_t
|
Vector jv_t
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ type geojson_opt =
|
||||||
| Markers_inherit_options of bool
|
| Markers_inherit_options of bool
|
||||||
|
|
||||||
(** [create_geojson geojson] is a new geojson layer *)
|
(** [create_geojson geojson] is a new geojson layer *)
|
||||||
val create_geojson : Jv.t -> geojson_opt list -> [ `Geojson ] t
|
val create_geojson : Jv.t -> geojson_opt array -> [ `Geojson ] t
|
||||||
|
|
||||||
(** Tile layers *)
|
(** Tile layers *)
|
||||||
|
|
||||||
|
|
@ -93,12 +93,12 @@ type tile_layer_opt =
|
||||||
|
|
||||||
(** [create_tile url attribution opts] create a new tile layer *)
|
(** [create_tile url attribution opts] create a new tile layer *)
|
||||||
val create_tile :
|
val create_tile :
|
||||||
string -> attribution:string -> tile_layer_opt list -> [ `Tile ] t
|
string -> attribution:string -> tile_layer_opt array -> [ `Tile ] t
|
||||||
|
|
||||||
(** [create_tile_osm opts] create a new tile layer with tile server and
|
(** [create_tile_osm opts] create a new tile layer with tile server and
|
||||||
attribution set to [openstreetmap.org]. See
|
attribution set to [openstreetmap.org]. See
|
||||||
{:https://wiki.openstreetmap.org/wiki/Tile_servers} *)
|
{:https://wiki.openstreetmap.org/wiki/Tile_servers} *)
|
||||||
val create_tile_osm : tile_layer_opt list -> [ `Tile ] t
|
val create_tile_osm : tile_layer_opt array -> [ `Tile ] t
|
||||||
|
|
||||||
(** [create_polyline l] create a polyline layer from [l] *)
|
(** [create_polyline l] create a polyline layer from [l] *)
|
||||||
val create_polyline : Latlng.t list -> [ `Vector ] t
|
val create_polyline : Latlng.t array -> [ `Vector ] t
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,9 @@ let opt_to_jv = function
|
||||||
| Z_index_offset i | Rise_offset i -> Jv.of_int i
|
| Z_index_offset i | Rise_offset i -> Jv.of_int i
|
||||||
| Opacity f -> Jv.of_float f
|
| Opacity f -> Jv.of_float f
|
||||||
|
|
||||||
let create : Latlng.t -> opt list -> t =
|
let create : Latlng.t -> opt array -> t =
|
||||||
fun latlng options ->
|
fun latlng options ->
|
||||||
let l =
|
let l = Array.map (fun o -> (opt_to_string o, opt_to_jv o)) options in
|
||||||
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
|
|
||||||
in
|
|
||||||
let jv_t =
|
let jv_t =
|
||||||
Jv.call Global.leaflet "marker" [| Latlng.to_jv latlng; Jv.obj l |]
|
Jv.call Global.leaflet "marker" [| Latlng.to_jv latlng; Jv.obj l |]
|
||||||
in
|
in
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ type opt =
|
||||||
|
|
||||||
(** [create latlng options] is a new marker with the same position as [latlng]
|
(** [create latlng options] is a new marker with the same position as [latlng]
|
||||||
and with options set to [options] *)
|
and with options set to [options] *)
|
||||||
val create : Latlng.t -> opt list -> t
|
val create : Latlng.t -> opt array -> t
|
||||||
|
|
||||||
(** Returns the current geographical position of the marker. *)
|
(** Returns the current geographical position of the marker. *)
|
||||||
val get_latlng : t -> Latlng.t
|
val get_latlng : t -> Latlng.t
|
||||||
|
|
|
||||||
|
|
@ -69,9 +69,7 @@ let opt_to_jv = function
|
||||||
| Pane s | Class_name s -> Jv.of_string s
|
| Pane s | Class_name s -> Jv.of_string s
|
||||||
|
|
||||||
let create ~content ~latlng options =
|
let create ~content ~latlng options =
|
||||||
let l =
|
let l = Array.map (fun o -> (opt_to_string o, opt_to_jv o)) options in
|
||||||
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
|
|
||||||
in
|
|
||||||
let popup = Jv.call Global.leaflet "popup" [| Jv.obj l |] in
|
let popup = Jv.call Global.leaflet "popup" [| Jv.obj l |] in
|
||||||
let popup =
|
let popup =
|
||||||
match latlng with
|
match latlng with
|
||||||
|
|
@ -87,9 +85,7 @@ let create ~content ~latlng options =
|
||||||
popup
|
popup
|
||||||
|
|
||||||
let create_from_el el ~latlng options =
|
let create_from_el el ~latlng options =
|
||||||
let l =
|
let l = Array.map (fun o -> (opt_to_string o, opt_to_jv o)) options in
|
||||||
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
|
|
||||||
in
|
|
||||||
let popup = Jv.call Global.leaflet "popup" [| Jv.obj l |] in
|
let popup = Jv.call Global.leaflet "popup" [| Jv.obj l |] in
|
||||||
let popup =
|
let popup =
|
||||||
match latlng with
|
match latlng with
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ val opt_to_jv : opt -> Jv.t
|
||||||
|
|
||||||
(** [create ~content ~latlng options] is a new popup setup with [options],
|
(** [create ~content ~latlng options] is a new popup setup with [options],
|
||||||
position set to [latlng] and content to [s] *)
|
position set to [latlng] and content to [s] *)
|
||||||
val create : content:string option -> latlng:Latlng.t option -> opt list -> t
|
val create : content:string option -> latlng:Latlng.t option -> opt array -> t
|
||||||
|
|
||||||
(** [create_from_el el latlng options] is a new popup setup with [options],
|
(** [create_from_el el latlng options] is a new popup setup with [options],
|
||||||
position set to [latlng] and content to [el] *)
|
position set to [latlng] and content to [el] *)
|
||||||
val create_from_el : Brr.El.t -> latlng:Latlng.t option -> opt list -> t
|
val create_from_el : Brr.El.t -> latlng:Latlng.t option -> opt array -> t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue