aboutsummaryrefslogtreecommitdiff
path: root/src/View/Map/Marker.ml
blob: a96af86d5fe6b221d44035b917ab34ade3d57207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
let create on_remove on_update pos init_name init_color init_icon =
  let marker =
        Leaflet.marker pos
          { title = init_name
          ; icon = Icon.create init_icon init_color
          ; draggable = true
          }
  in
  let form on_remove on_update =
    let name = ref init_name in
    let color = ref init_color in
    let icon = ref init_icon in
    let on_update () =
          let () = on_update pos pos !name !color !icon in
          Modal.hide ()
    in
    H.div
      [| |]
      [| Layout.section
          [| |]
          [| H.form
              [| HA.class_ "g-MarkerForm"
              ;  HE.on_submit (fun e ->
                  let () = Event.preventDefault e in
                  on_update ())
              |]
              [| Form.section "Modification"
              ;  Layout.section
                  [| |]
                  [| Form.input "g-MarkerForm__Name" "Name" init_name (fun newName -> name := newName)
                  ;  Form.color_input "g-MarkerForm__Color" "Color" init_color (fun newColor -> color := newColor)
                  ;  Autocomplete.create
                      "g-MarkerForm__Icon"
                      "Icon"
                      FontAwesome.icons
                      (fun newIcon -> let () = Js.log newIcon in icon := newIcon)
                      [| HA.value init_icon |]
                  |]
              ;  Button.action (fun _ -> on_update ()) "Modify"
              |]
          |]
      ;  Layout.section
          [| |]
          [| Form.section "Deletion"
          ;  Button.danger (fun _ ->
                let () = on_remove pos in
                Modal.hide ()) "Remove"
          |]
      |]
  in

  (* Open a modification / deletion modal on click *)
  let () = Leaflet.on marker "click" (fun _ ->
    Modal.show (form on_remove on_update)) in

  (* Move the cursor on drag *)
  let () = Leaflet.on marker "dragend" (fun e ->
    let newPos = Leaflet.get_lat_lng (Leaflet.target e) () in
    on_update pos newPos init_name init_color init_icon) in

  marker