add geojson options
This commit is contained in:
parent
6aca93ebe9
commit
502614b9d4
2 changed files with 46 additions and 5 deletions
36
src/layer.ml
36
src/layer.ml
|
|
@ -78,9 +78,39 @@ let on : type kind. kind Event.sub -> (kind Event.t -> 'b) -> 'c t -> unit =
|
|||
|
||||
(** Geojson layers *)
|
||||
|
||||
let create_geojson : ?options:Jv.t -> Jv.t -> [ `Geojson ] t =
|
||||
fun ?(options = Jv.null) geojson ->
|
||||
let jv_t = Jv.call Global.leaflet "geoJSON" [| geojson; options |] in
|
||||
type geojson_opt =
|
||||
| Point_to_layer of (Jv.t -> Latlng.t -> unit)
|
||||
| Style of (Jv.t -> unit)
|
||||
| On_each_feature of (Jv.t -> [ `Geojson ] t -> unit)
|
||||
| Filter of (Jv.t -> bool)
|
||||
| Coords_to_latlng of (Jv.t -> Latlng.t)
|
||||
| Markers_inherit_options of bool
|
||||
|
||||
let geojson_opt_to_string = function
|
||||
| Point_to_layer _ -> "pointToLayer"
|
||||
| Style _ -> "style"
|
||||
| On_each_feature _ -> "onEachFeature"
|
||||
| Filter _ -> "filter"
|
||||
| Coords_to_latlng _ -> "coordsToLatLng"
|
||||
| Markers_inherit_options _ -> "markersInheritOptions"
|
||||
|
||||
let geojson_opt_to_jv = function
|
||||
| Markers_inherit_options b -> Jv.of_bool b
|
||||
| Point_to_layer f -> Jv.repr f
|
||||
| Style f -> Jv.repr f
|
||||
| On_each_feature f -> Jv.repr f
|
||||
| Filter f -> Jv.repr f
|
||||
| Coords_to_latlng f -> Jv.repr f
|
||||
|
||||
let create_geojson : Jv.t -> geojson_opt list -> [ `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
|
||||
in
|
||||
let jv_t = Jv.call Global.leaflet "geoJSON" [| geojson; Jv.obj l |] in
|
||||
Geojson jv_t
|
||||
|
||||
(** Marker layers *)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue