use gadts for layer, clean code
This commit is contained in:
parent
2a760bc98d
commit
dbfbaeda60
17 changed files with 152 additions and 163 deletions
39
src/map.ml
39
src/map.ml
|
|
@ -1,38 +1,43 @@
|
|||
type t = Jv.t
|
||||
|
||||
let of_jv_t = Fun.id
|
||||
let of_jv = Fun.id
|
||||
|
||||
let to_jv_t = Fun.id
|
||||
let to_jv = 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 invalidate_size map =
|
||||
let (_ : Jv.t) = Jv.call map "invalidateSize" [| Jv.true' |] in
|
||||
()
|
||||
|
||||
let fit_world map = ignore @@ Jv.call map "fitWorld" [||]
|
||||
let fit_world map =
|
||||
let (_ : Jv.t) = Jv.call map "fitWorld" [||] in
|
||||
()
|
||||
|
||||
let get_container map =
|
||||
Jv.call (to_jv_t map) "getContainer" [||] |> Brr.El.of_jv
|
||||
let get_container map = Jv.call (to_jv 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 set_view latlng ~zoom map =
|
||||
let latlng = Latlng.to_jv latlng in
|
||||
let (_ : Jv.t) =
|
||||
match zoom with
|
||||
| None -> Jv.call map "setView" [| latlng |]
|
||||
| Some zoom -> Jv.call map "setView" [| latlng; Jv.of_int zoom |]
|
||||
in
|
||||
()
|
||||
|
||||
let as_target map = Brr.Ev.target_of_jv map
|
||||
|
||||
let on : type kind. kind Event.sub -> (kind Event.t -> 'b) -> t -> unit =
|
||||
fun event handler map ->
|
||||
let name = Event.sub_to_string event in
|
||||
let handler v = handler @@ Event.of_jv_t event v in
|
||||
ignore @@ Jv.call map "on" [| Jv.of_string name; Jv.repr handler |]
|
||||
let handler v = handler @@ Event.of_jv event v in
|
||||
let (_ : Jv.t) = Jv.call map "on" [| Jv.of_string name; Jv.repr handler |] in
|
||||
()
|
||||
|
||||
let get_center map = Latlng.of_jv_t @@ Jv.call map "getCenter" [||]
|
||||
let get_center map = Latlng.of_jv @@ 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 |]
|
||||
Latlng.of_jv @@ Jv.call map "wrapLatLng" [| Latlng.to_jv latlng |]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue