From 37446d9e1fed6c0e22afe5fd23c4675c245e1990 Mon Sep 17 00:00:00 2001 From: Swrup Date: Tue, 8 Feb 2022 22:39:13 +0100 Subject: [PATCH] add geolocalize button --- src/babillard_page.eml.html | 1 + src/js_babillard.ml | 25 ++++++++++++++++++++++++- src/js_newthread.ml | 25 ++++++++++++++++++++++++- src/newthread_page.eml.html | 1 + 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/babillard_page.eml.html b/src/babillard_page.eml.html index 4f587f1..930bc04 100644 --- a/src/babillard_page.eml.html +++ b/src/babillard_page.eml.html @@ -14,6 +14,7 @@ let f ~board request = >[New Thread] % end;
+
diff --git a/src/js_babillard.ml b/src/js_babillard.ml index de7a33f..0bab74d 100644 --- a/src/js_babillard.ml +++ b/src/js_babillard.ml @@ -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 diff --git a/src/js_newthread.ml b/src/js_newthread.ml index 71590c8..768f661 100644 --- a/src/js_newthread.ml +++ b/src/js_newthread.ml @@ -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 diff --git a/src/newthread_page.eml.html b/src/newthread_page.eml.html index b905abe..ecc7743 100644 --- a/src/newthread_page.eml.html +++ b/src/newthread_page.eml.html @@ -10,6 +10,7 @@ Login to make a new thread.
+