add geojson options

This commit is contained in:
Swrup 2022-06-20 09:17:23 +02:00
parent 96a7307bf3
commit 323891efef
2 changed files with 46 additions and 5 deletions

View file

@ -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 *)