From ad6abcd5fc5e4e66062c8a01b511a1bd4bda2e94 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 9 Aug 2020 08:37:18 +0200 Subject: Export as CSV --- src/View/Map.ml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/View/Map.ml') 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 -- cgit v1.2.3