add geolocalize button
This commit is contained in:
parent
cef345b59c
commit
07de8eb30e
4 changed files with 50 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ let f ~board request =
|
||||||
<a href=<%s url %>>[New Thread]</a>
|
<a href=<%s url %>>[New Thread]</a>
|
||||||
% end;
|
% end;
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
<button onclick="geolocalize()">Geolocalize me</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div id="thread_preview_div"></div>
|
<div id="thread_preview_div"></div>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
let log = Format.printf
|
let log = Format.printf
|
||||||
|
|
||||||
(*TODO fix duplicate module *)
|
(*TODO fix duplicate modules *)
|
||||||
module Leaflet = struct
|
module Leaflet = struct
|
||||||
(* get the leaflet object *)
|
(* get the leaflet object *)
|
||||||
let leaflet =
|
let leaflet =
|
||||||
|
|
@ -96,6 +96,29 @@ module Leaflet = struct
|
||||||
()
|
()
|
||||||
end
|
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
|
module Marker = struct
|
||||||
let board =
|
let board =
|
||||||
let board_div = Jv.get Jv.global "board" in
|
let board_div = Jv.get Jv.global "board" in
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
let log = Format.printf
|
let log = Format.printf
|
||||||
|
|
||||||
(*TODO fix duplicate module *)
|
(*TODO fix duplicate modules *)
|
||||||
module Leaflet = struct
|
module Leaflet = struct
|
||||||
(* get the leaflet object *)
|
(* get the leaflet object *)
|
||||||
let leaflet =
|
let leaflet =
|
||||||
|
|
@ -96,6 +96,29 @@ module Leaflet = struct
|
||||||
()
|
()
|
||||||
end
|
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
|
module Marker = struct
|
||||||
let board =
|
let board =
|
||||||
let board_div = Jv.get Jv.global "board" in
|
let board_div = Jv.get Jv.global "board" in
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ Login to make a new thread.
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
<button onclick="geolocalize()">Geolocalize me</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-6" id="newthread-form">
|
<div class="col-md-6" id="newthread-form">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue