make geopub/leaflet a separate library
This commit is contained in:
commit
2fe7c1450d
18 changed files with 352 additions and 0 deletions
7
src/dune
Normal file
7
src/dune
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(library
|
||||
(name leaflet)
|
||||
(public_name leaflet)
|
||||
(modules leaflet)
|
||||
(libraries brr js_of_ocaml)
|
||||
(js_of_ocaml
|
||||
(javascript_files leaflet.js)))
|
||||
6
src/leaflet.js
Normal file
6
src/leaflet.js
Normal file
File diff suppressed because one or more lines are too long
3
src/leaflet.js.license
Normal file
3
src/leaflet.js.license
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
SPDX-FileCopyrightText: 2010-2021 Vladimir Agafonkin
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause
|
||||
83
src/leaflet.ml
Normal file
83
src/leaflet.ml
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
(*
|
||||
* SPDX-FileCopyrightText: 2021 pukkamustard <pukkamustard@posteo.net>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*)
|
||||
open Brr
|
||||
|
||||
let leaflet =
|
||||
match Jv.(find global "L") with
|
||||
| Some l -> l
|
||||
| None -> failwith "Could not load Leaflet"
|
||||
|
||||
module LatLng = struct
|
||||
type t = Jv.t
|
||||
|
||||
let create lat lng =
|
||||
Jv.call leaflet "latLng" [| Jv.of_float lat; Jv.of_float lng |]
|
||||
|
||||
let lat latlng = Jv.get latlng "lat" |> Jv.to_float
|
||||
let lng latlng = Jv.get latlng "lng" |> Jv.to_float
|
||||
end
|
||||
|
||||
module Ev = struct
|
||||
module MouseEvent = struct
|
||||
type t = Jv.t
|
||||
|
||||
let latlng e = Jv.get e "latlng"
|
||||
end
|
||||
end
|
||||
|
||||
module Map = struct
|
||||
type t = Jv.t
|
||||
|
||||
let create ?(options = Jv.null) el =
|
||||
Jv.call leaflet "map" [| El.to_jv el; options |]
|
||||
|
||||
let invalidate_size map =
|
||||
ignore @@ Jv.call map "invalidateSize" [| Jv.true' |]
|
||||
|
||||
let fit_world map = ignore @@ Jv.call map "fitWorld" [||]
|
||||
let get_container map = Jv.call map "getContainer" [||] |> El.of_jv
|
||||
|
||||
let set_view latlng ~zoom map =
|
||||
ignore @@ Jv.call map "setView" [| latlng; Jv.of_int zoom |];
|
||||
map
|
||||
|
||||
let as_target map = Brr.Ev.target_of_jv map
|
||||
let click = Brr.Ev.Type.create (Jstr.v "click")
|
||||
end
|
||||
|
||||
module TileLayer = struct
|
||||
type t = Jv.t
|
||||
|
||||
let create_osm () =
|
||||
Jv.call leaflet "tileLayer"
|
||||
[|
|
||||
Jv.of_string "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
|
||||
Jv.obj
|
||||
[|
|
||||
( "attribution",
|
||||
Jv.of_string
|
||||
"© <a \
|
||||
href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> \
|
||||
contributors" );
|
||||
|];
|
||||
|]
|
||||
|
||||
let add_to tile_layer map = ignore @@ Jv.call tile_layer "addTo" [| map |]
|
||||
end
|
||||
|
||||
module Marker = struct
|
||||
type t = Jv.t
|
||||
|
||||
let create latlng = Jv.call leaflet "marker" [| latlng |]
|
||||
let add_to marker map = ignore @@ Jv.call marker "addTo" [| map |]
|
||||
|
||||
let bind_popup el marker =
|
||||
ignore @@ Jv.call marker "bindPopup" [| El.to_jv el |];
|
||||
marker
|
||||
|
||||
let open_popup marker = ignore @@ Jv.call marker "openPopup" [||]
|
||||
end
|
||||
|
||||
67
src/leaflet.mli
Normal file
67
src/leaflet.mli
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
(*
|
||||
* SPDX-FileCopyrightText: 2021 pukkamustard <pukkamustard@posteo.net>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*)
|
||||
|
||||
open Brr
|
||||
(** {1 Leaflet}
|
||||
|
||||
This module provides bindings to the Leaflet JavaScript library for
|
||||
mobile-friendly interactive maps.
|
||||
|
||||
See also the [Leaflet API reference](https://leafletjs.com/reference.html).
|
||||
*)
|
||||
|
||||
module LatLng : sig
|
||||
type t
|
||||
|
||||
val create : float -> float -> t
|
||||
val lat : t -> float
|
||||
val lng : t -> float
|
||||
end
|
||||
|
||||
module Ev : sig
|
||||
module MouseEvent : sig
|
||||
type t
|
||||
|
||||
val latlng : t -> LatLng.t
|
||||
end
|
||||
end
|
||||
|
||||
module Map : sig
|
||||
type t
|
||||
|
||||
val create : ?options:Jv.t -> El.t -> t
|
||||
val invalidate_size : t -> unit
|
||||
val set_view : LatLng.t -> zoom:int -> t -> t
|
||||
val fit_world : t -> unit
|
||||
val get_container : t -> El.t
|
||||
|
||||
(** {1 Events} **)
|
||||
|
||||
val as_target : t -> Brr.Ev.target
|
||||
|
||||
(** {2 Interaction events} **)
|
||||
|
||||
val click : Ev.MouseEvent.t Brr.Ev.type'
|
||||
end
|
||||
|
||||
module TileLayer : sig
|
||||
type t
|
||||
|
||||
val create_osm : unit -> t
|
||||
val add_to : t -> Map.t -> unit
|
||||
end
|
||||
|
||||
module Marker : sig
|
||||
type t
|
||||
|
||||
val create : LatLng.t -> t
|
||||
val add_to : t -> Map.t -> unit
|
||||
|
||||
(** {2 Popup methods} *)
|
||||
|
||||
val bind_popup : El.t -> t -> t
|
||||
val open_popup : t -> unit
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue