split modules and fix Ev

This commit is contained in:
Swrup 2022-04-07 14:45:11 +02:00
parent 2154a10db4
commit 82d74ad985
18 changed files with 208 additions and 225 deletions

46
src/map.ml Normal file
View file

@ -0,0 +1,46 @@
type t = Jv.t
module Event = struct
let to_brr s = s |> Jstr.v |> Brr.Ev.Type.create
let click = to_brr "click"
let moveend = to_brr "moveend"
let zoomend = to_brr "zoomend"
end
let of_jv_t = Fun.id
let to_jv_t = Fun.id
let create ?(options = Jv.null) container_id =
Jv.call Global.leaflet "map" [| Jv.of_string container_id; options |]
let invalidate_size map = ignore @@ Jv.call map "invalidateSize" [| Jv.true' |]
let fit_world map = ignore @@ Jv.call map "fitWorld" [||]
let get_container map =
Jv.call (to_jv_t map) "getContainer" [||] |> Brr.El.of_jv
let set_view latlng ?zoom map =
let latlng = Latlng.to_jv_t latlng in
ignore
@@
match zoom with
| None -> Jv.call map "setView" [| latlng |]
| Some zoom -> Jv.call map "setView" [| latlng; Jv.of_int zoom |]
let as_target map = Brr.Ev.target_of_jv map
let on ~event ~handler map =
let name = Brr.Ev.Type.name event |> Jv.of_jstr in
ignore @@ Jv.call map "on" [| name; Jv.repr handler |]
let get_center map = Latlng.of_jv_t @@ Jv.call map "getCenter" [||]
let get_zoom map = Jv.call map "getZoom" [||] |> Jv.to_int
let wrapped_latlng latlng map =
Latlng.of_jv_t @@ Jv.call map "wrapLatLng" [| Latlng.to_jv_t latlng |]