add geolocalize button

This commit is contained in:
Swrup 2022-02-08 22:39:13 +01:00
parent bf12a66eda
commit 37446d9e1f
4 changed files with 50 additions and 2 deletions

View file

@ -1,6 +1,6 @@
let log = Format.printf
(*TODO fix duplicate module *)
(*TODO fix duplicate modules *)
module Leaflet = struct
(* get the leaflet object *)
let leaflet =
@ -96,6 +96,29 @@ module Leaflet = struct
()
end
module Geolocalize = struct
let update_location geo =
log "update_location@.";
match geo with
| Error _ -> failwith "error in geolocation"
| Ok geo ->
let lat = Brr_io.Geolocation.Pos.latitude geo in
let lng = Brr_io.Geolocation.Pos.longitude geo in
let latlng =
Jv.call Leaflet.leaflet "latLng" [| Jv.of_float lat; Jv.of_float lng |]
in
ignore @@ Jv.call Leaflet.map "setView" [| latlng; Jv.of_int 13 |];
()
let geolocalize () =
log "geolocalize@.";
let l = Brr_io.Geolocation.of_navigator Brr.G.navigator in
ignore @@ Fut.await (Brr_io.Geolocation.get l) update_location;
()
let () = Jv.set Jv.global "geolocalize" (Jv.repr geolocalize)
end
module Marker = struct
let board =
let board_div = Jv.get Jv.global "board" in