package leaflet

  1. Overview
  2. Docs

Source file event.ml

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
(* BSD-2-Clause License *)

type _ t =
  | Keyboard : Jv.t -> [> `Keyboard ] t
  | Mouse : Jv.t -> [> `Mouse ] t
  | Error : Jv.t -> [> `Error ] t
  | Basic : Jv.t -> [> `Basic ] t

type _ sub =
  | Click : [> `Mouse ] sub
  | Move_end : [> `Basic ] sub
  | Zoom_end : [> `Basic ] sub

let of_jv : type kind. kind sub -> Jv.t -> kind t =
 fun tag e ->
  match tag with Click -> Mouse e | Move_end -> Basic e | Zoom_end -> Basic e

let sub_to_string : type kind. kind sub -> string = function
  | Click -> "click"
  | Move_end -> "moveend"
  | Zoom_end -> "zoomend"

(** Basic events *)

let get_type : type kind. kind t -> string = function
  | Keyboard e | Mouse e | Error e | Basic e -> Jv.get e "type" |> Jv.to_string

let target : type kind. kind t -> Brr.Ev.target = function
  | Keyboard e | Mouse e | Error e | Basic e ->
    Jv.get e "target" |> Brr.Ev.target_of_jv

let source_target : type kind. kind t -> Brr.Ev.target = function
  | Keyboard e | Mouse e | Error e | Basic e ->
    Jv.get e "sourceTarget" |> Brr.Ev.target_of_jv

let propagated_from : type kind. kind t -> Jv.t = function
  | Keyboard e | Mouse e | Error e | Basic e -> Jv.get e "propagatedFrom"

(** Keyboard & Mouse events *)

let original_event : [ `Keyboard | `Mouse ] t -> Jv.t = function
  | Keyboard e | Mouse e -> Jv.get e "originalEvent"

(** Mouse events *)

let container_point : [ `Mouse ] t -> Point.t = function
  | Mouse e -> Jv.get e "containerPoint" |> Point.of_jv

let layer_point : [ `Mouse ] t -> Point.t = function
  | Mouse e -> Jv.get e "layerPoint" |> Point.of_jv

let latlng : [ `Mouse ] t -> Latlng.t = function
  | Mouse e -> Jv.get e "latlng" |> Latlng.of_jv

(** Error events *)

let code : [ `Error ] t -> int = function
  | Error e -> Jv.get e "code" |> Jv.to_int

let message : [ `Error ] t -> string = function
  | Error e -> Jv.get e "message" |> Jv.to_string
OCaml

Innovation. Community. Security.