aboutsummaryrefslogtreecommitdiff
path: root/src/View/Map.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/View/Map.ml')
-rw-r--r--src/View/Map.ml19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/View/Map.ml b/src/View/Map.ml
index eda934c..8f74b76 100644
--- a/src/View/Map.ml
+++ b/src/View/Map.ml
@@ -1,4 +1,4 @@
-let mapView =
+let mapView state =
H.div
[| HA.class_ "g-Layout__Page" |]
[| H.div
@@ -8,6 +8,9 @@ let mapView =
; HA.href "#"
|]
[| H.text "Map" |]
+ ; Button.text
+ [| HE.on_click (fun _ -> File.download "map.csv" (State.to_csv_string !state)) |]
+ [| H.text "Export" |]
|]
; H.div
[| HA.class_ "g-Map" |]
@@ -19,10 +22,9 @@ let mapView =
let state_from_hash () =
let hash = Js.String.sliceToEnd ~from:1 (Location.hash Document.location) in
- State.from_string hash
+ State.from_url_string hash
-let installMap () =
- let state = ref (state_from_hash ()) in
+let installMap state =
let map = Leaflet.map "g-Map__Content" in
let title_layer = Leaflet.title_layer "http://{s}.tile.osm.org/{z}/{x}/{y}.png" in
let markers = Leaflet.feature_group [| |] in
@@ -31,7 +33,7 @@ let installMap () =
let rec reload_from_hash focus =
let update_state new_state =
- let () = History.push_state "" "" ("#" ^ State.to_string new_state) () in
+ let () = History.push_state "" "" ("#" ^ State.to_url_string new_state) () in
reload_from_hash false
in
@@ -74,7 +76,7 @@ let installMap () =
let add_marker pos name color icon =
let new_marker = { State.pos = pos; name = name; color = color; icon = icon } in
let new_state = State.update !state pos new_marker in
- let () = History.push_state "" "" ("#" ^ State.to_string new_state) () in
+ let () = History.push_state "" "" ("#" ^ State.to_url_string new_state) () in
reload_from_hash false
in
@@ -96,5 +98,6 @@ let installMap () =
|])
let render () =
- let _ = Js.Global.setTimeout installMap 0 in
- mapView
+ let state = ref (state_from_hash ()) in
+ let _ = Js.Global.setTimeout (fun _ -> installMap state) 0 in
+ mapView state