forked from swrup/leaflet
list -> array
This commit is contained in:
parent
3d91ee4ae6
commit
bbd19599cd
@ -4,7 +4,7 @@ let map = Leaflet.Map.create_on "map"
|
||||
(* setup map *)
|
||||
let () =
|
||||
(* 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;
|
||||
|
||||
(* 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 )
|
||||
|
||||
let create icon_url options =
|
||||
let l = List.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.map (fun o -> (to_string o, opt_to_jv o)) options in
|
||||
let l = Array.append [| ("iconUrl", Jv.of_string icon_url) |] l in
|
||||
Jv.call Global.leaflet "icon" [| Jv.obj l |]
|
||||
|
||||
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 html =
|
||||
match html with
|
||||
@ -63,9 +63,9 @@ let create_div ~html ~bg_pos options =
|
||||
| None -> []
|
||||
| Some bg_pos -> [ ("bgPos", Point.to_jv bg_pos) ]
|
||||
in
|
||||
html @ bg_pos
|
||||
html @ bg_pos |> Array.of_list
|
||||
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 |]
|
||||
|
||||
let set_default_image_path s =
|
||||
|
@ -24,13 +24,13 @@ type opt =
|
||||
|
||||
(** [create icon_url options] Creates an icon instance with the given [options],
|
||||
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
|
||||
given [options], [bg_pos] is the optional relative position of the
|
||||
background, in pixels [html] is custom HTML code to put inside the div
|
||||
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 *)
|
||||
val set_default_image_path : string -> unit
|
||||
|
25
src/layer.ml
25
src/layer.ml
@ -110,13 +110,10 @@ let geojson_opt_to_jv = function
|
||||
| Filter 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 ->
|
||||
let l =
|
||||
Array.of_list
|
||||
@@ List.map
|
||||
(fun o -> (geojson_opt_to_string o, geojson_opt_to_jv o))
|
||||
options
|
||||
Array.map (fun o -> (geojson_opt_to_string o, geojson_opt_to_jv o)) options
|
||||
in
|
||||
let jv_t = Jv.call Global.leaflet "geoJSON" [| geojson; Jv.obj l |] in
|
||||
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 |]
|
||||
|
||||
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 ->
|
||||
let arr =
|
||||
Array.of_list
|
||||
@@ ("attribution", Jv.of_string attribution)
|
||||
:: List.map
|
||||
(fun o -> (tile_layer_opt_to_string o, tile_layer_opt_to_jv o))
|
||||
options
|
||||
Array.append
|
||||
[| ("attribution", Jv.of_string attribution) |]
|
||||
(Array.map
|
||||
(fun o -> (tile_layer_opt_to_string o, tile_layer_opt_to_jv o))
|
||||
options )
|
||||
in
|
||||
let jv_t =
|
||||
Jv.call Global.leaflet "tileLayer" [| Jv.of_string url; Jv.obj arr |]
|
||||
in
|
||||
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 ->
|
||||
let url = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" in
|
||||
let attribution =
|
||||
@ -231,8 +228,8 @@ let create_tile_osm : tile_layer_opt list -> [ `Tile ] t =
|
||||
|
||||
(* Vector Layers *)
|
||||
|
||||
let create_polyline : Latlng.t list -> [ `Vector ] t =
|
||||
let create_polyline : Latlng.t array -> [ `Vector ] t =
|
||||
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
|
||||
Vector jv_t
|
||||
|
@ -62,7 +62,7 @@ type geojson_opt =
|
||||
| Markers_inherit_options of bool
|
||||
|
||||
(** [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 *)
|
||||
|
||||
@ -93,12 +93,12 @@ type tile_layer_opt =
|
||||
|
||||
(** [create_tile url attribution opts] create a new tile layer *)
|
||||
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
|
||||
attribution set to [openstreetmap.org]. See
|
||||
{: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] *)
|
||||
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
|
||||
| Opacity f -> Jv.of_float f
|
||||
|
||||
let create : Latlng.t -> opt list -> t =
|
||||
let create : Latlng.t -> opt array -> t =
|
||||
fun latlng options ->
|
||||
let l =
|
||||
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
|
||||
in
|
||||
let l = Array.map (fun o -> (opt_to_string o, opt_to_jv o)) options in
|
||||
let jv_t =
|
||||
Jv.call Global.leaflet "marker" [| Latlng.to_jv latlng; Jv.obj l |]
|
||||
in
|
||||
|
@ -17,7 +17,7 @@ type opt =
|
||||
|
||||
(** [create latlng options] is a new marker with the same position as [latlng]
|
||||
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. *)
|
||||
val get_latlng : t -> Latlng.t
|
||||
|
@ -69,9 +69,7 @@ let opt_to_jv = function
|
||||
| Pane s | Class_name s -> Jv.of_string s
|
||||
|
||||
let create ~content ~latlng options =
|
||||
let l =
|
||||
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
|
||||
in
|
||||
let l = Array.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 =
|
||||
match latlng with
|
||||
@ -87,9 +85,7 @@ let create ~content ~latlng options =
|
||||
popup
|
||||
|
||||
let create_from_el el ~latlng options =
|
||||
let l =
|
||||
Array.of_list @@ List.map (fun o -> (opt_to_string o, opt_to_jv o)) options
|
||||
in
|
||||
let l = Array.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 =
|
||||
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],
|
||||
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],
|
||||
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…
x
Reference in New Issue
Block a user