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.ml31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/View/Map.ml b/src/View/Map.ml
index 969a95a..b46557d 100644
--- a/src/View/Map.ml
+++ b/src/View/Map.ml
@@ -66,21 +66,32 @@ let installMap () =
let () = reload_from_hash true in
(* Reload the map if the URL changes *)
- let () = Element.addEventListener Window.window "popstate" (fun _ ->
+ let () = Element.add_event_listener Window.window "popstate" (fun _ ->
reload_from_hash true)
in
- (* Add a marker on right click *)
- Leaflet.on map "contextmenu" (fun (event) ->
- let pos = Leaflet.lat_lng event in
- let new_marker =
- match State.last_added !state with
- | Some m -> { m with pos = pos; name = "" }
- | None -> { pos = pos; name = ""; color = "#3f92cf"; icon = "" }
- in
+ 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
- reload_from_hash false)
+ reload_from_hash false
+ in
+
+ (* Context menu *)
+ Leaflet.on map "contextmenu" (fun event ->
+ ContextMenu.show
+ (Leaflet.original_event event)
+ [| { label = "Add a marker"
+ ; action = (fun _ ->
+ let pos = Leaflet.lat_lng event in
+ let marker =
+ match State.last_added !state with
+ | Some m -> { m with pos = pos; name = "" }
+ | _ -> { pos = pos; name = ""; color = "#3f92cf"; icon = "" }
+ in
+ Modal.show (Marker.form (add_marker pos) marker.name marker.color marker.icon))
+ }
+ |])
let render () =
let _ = Js.Global.setTimeout installMap 0 in