add documentation, remove Map.as_target

This commit is contained in:
Swrup 2022-05-19 22:42:28 +02:00
parent 68ee03bead
commit 38c0d5ef53
7 changed files with 50 additions and 19 deletions

View file

@ -1,17 +1,7 @@
{0 leaflet} {0 Leaflet}
{{:https://TODO/leaflet} leaflet} is an {{:https://ocaml.org} OCaml} library/executable to TODO. Leaflet is an [OCaml] bindings library for the {{:https://leafletjs.com} Leaflet} JavaScript library.
{1:api API}
{!modules: {!modules:
Leaflet Leaflet
} }
{1:private_api Private API}
You shouldn't have to use any of these modules, they're used internally only.
{!modules:
TODO
}

View file

@ -2,14 +2,22 @@
type t type t
(** [create lat lng] is an object representing a geographical point with the
given latitude and longitude *)
val create : float -> float -> t val create : float -> float -> t
(** [lat o] is the latitude of [o] *)
val lat : t -> float val lat : t -> float
(** [lng o] is the longitude of [o] *)
val lng : t -> float val lng : t -> float
(** [equals a b] is true iff [a] and [b] is at the same position (within a small
margin of error) *)
val equals : t -> t -> bool val equals : t -> t -> bool
(** [of_jv jv] is [jv] as a [Latlng.t] *)
val of_jv : Jv.t -> t val of_jv : Jv.t -> t
(** [to_jv o] is [o] as a {!Jv.t} *)
val to_jv : t -> Jv.t val to_jv : t -> Jv.t

View file

@ -71,7 +71,6 @@ let create_marker : Latlng.t -> [ `Marker ] t =
let create_tile_osm : string option -> [ `Tile ] t = let create_tile_osm : string option -> [ `Tile ] t =
fun url -> fun url ->
(* see https://wiki.openstreetmap.org/wiki/Tile_servers *)
let url = let url =
Option.value url Option.value url
~default:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" ~default:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"

View file

@ -8,32 +8,46 @@ type _ t =
(** Basic layers *) (** Basic layers *)
(** [add_to map layer] adds [layer] to [map] *)
val add_to : Map.t -> _ t -> unit val add_to : Map.t -> _ t -> unit
(** [remove layer] removes [layer] from the map it is currently active on *)
val remove : _ t -> unit val remove : _ t -> unit
(** [remove_from map layer] removes [layer] from [map] *)
val remove_from : Map.t -> _ t -> unit val remove_from : Map.t -> _ t -> unit
(** [bind_popup popup layer] binds [popup] to [layer] *)
val bind_popup : Brr.El.t -> _ t -> unit val bind_popup : Brr.El.t -> _ t -> unit
(** [unbind_popup layer] unbinds the popup bound to [layer] *)
val unbind_popup : _ t -> unit val unbind_popup : _ t -> unit
(** [open_popup layer] opens the popup bound to [layer] *)
val open_popup : _ t -> unit val open_popup : _ t -> unit
(** [close_popup layer] closes the popup bound to [layer] *)
val close_popup : _ t -> unit val close_popup : _ t -> unit
(** [get_popup layer] is the popup bound to [layer] *)
val get_popup : _ t -> Popup.t val get_popup : _ t -> Popup.t
(** [to_jv o] is [o] as a {!Jv.t} *)
val to_jv : _ t -> Jv.t val to_jv : _ t -> Jv.t
(** Geojson layers *) (** Geojson layers *)
(** [create_geojson geojson] is a new geojson layer *)
val create_geojson : ?options:Jv.t -> Jv.t -> [ `Geojson ] t val create_geojson : ?options:Jv.t -> Jv.t -> [ `Geojson ] t
(** Marker layers *) (** Marker layers *)
(** [create_marker latlng] is a new marker with the same position as latlng *)
val create_marker : Latlng.t -> [ `Marker ] t val create_marker : Latlng.t -> [ `Marker ] t
(** Tile layers *) (** Tile layers *)
(** [create_tile_osm Some(url)] is a new tile layer with tile server specified
by [url]. Tile server default to [openstreetmap.org]. See
{:https://wiki.openstreetmap.org/wiki/Tile_servers} *)
val create_tile_osm : string option -> [ `Tile ] t val create_tile_osm : string option -> [ `Tile ] t

View file

@ -30,8 +30,6 @@ let set_view latlng ~zoom map =
in in
() ()
let as_target map = Brr.Ev.target_of_jv map
let on : type kind. kind Event.sub -> (kind Event.t -> 'b) -> t -> unit = let on : type kind. kind Event.sub -> (kind Event.t -> 'b) -> t -> unit =
fun event handler map -> fun event handler map ->
let name = Event.sub_to_string event in let name = Event.sub_to_string event in
@ -43,5 +41,5 @@ let get_center map = Latlng.of_jv @@ Jv.call map "getCenter" [||]
let get_zoom map = Jv.call map "getZoom" [||] |> Jv.to_int let get_zoom map = Jv.call map "getZoom" [||] |> Jv.to_int
let wrapped_latlng latlng map = let wrap_latlng latlng map =
Latlng.of_jv @@ Jv.call map "wrapLatLng" [| Latlng.to_jv latlng |] Latlng.of_jv @@ Jv.call map "wrapLatLng" [| Latlng.to_jv latlng |]

View file

@ -2,26 +2,43 @@
type t type t
(** [create container] creates a map on [container]. * To have a functional map
you will need to add a tile layer to it. *)
val create : ?options:Jv.t -> Brr.El.t -> t val create : ?options:Jv.t -> Brr.El.t -> t
(** [invalidate_size map] checks if the map container size changed and updates
the map if so *)
val invalidate_size : t -> unit val invalidate_size : t -> unit
(** [set_view latlng Some(zoom) map] sets the view of the [map] (geographical
center and zoom) *)
val set_view : Latlng.t -> zoom:int option -> t -> unit val set_view : Latlng.t -> zoom:int option -> t -> unit
(** [fit_world map] sets a map view that mostly contains the whole world with
the maximum zoom level possible *)
val fit_world : t -> unit val fit_world : t -> unit
(** [get_container map] is the HTML element that contains [map] *)
val get_container : t -> Brr.El.t val get_container : t -> Brr.El.t
(** [on event handler map] add an event listener on [map] for event [event] with
handler [handler] *)
val on : 'a Event.sub -> ('a Event.t -> 'b) -> t -> unit val on : 'a Event.sub -> ('a Event.t -> 'b) -> t -> unit
(** [get_center map] is the geographical center of the map view *)
val get_center : t -> Latlng.t val get_center : t -> Latlng.t
(** [get_zoom map] is the current zoom level of the map view *)
val get_zoom : t -> int val get_zoom : t -> int
val wrapped_latlng : Latlng.t -> t -> Latlng.t (** [wrap_latlng latlng map] returns a new [Latlng.t] where lat and lng has been
wrapped according to the map's CRS's wrapLat and wrapLng properties, if they
val as_target : t -> Brr.Ev.target are outside the CRS's bounds. By default this means longitude is wrapped
around the dateline so its value is between -180 and +180 degrees *)
val wrap_latlng : Latlng.t -> t -> Latlng.t
(** [of_jv jv] is [jv] as {!t} *)
val of_jv : Jv.t -> t val of_jv : Jv.t -> t
(** [to_jv o] is [o] as {!Jv.t} *)
val to_jv : t -> Jv.t val to_jv : t -> Jv.t

View file

@ -2,12 +2,17 @@
type t type t
(** [set_latlng latlng] changes the popup position to the given point*)
val set_latlng : Latlng.t -> unit val set_latlng : Latlng.t -> unit
(** [set_content s] changes the popup content to [s]*)
val set_content : string -> unit val set_content : string -> unit
(** [open_on map] * Adds the popup to [map] and closes the previous one. *)
val open_on : Map.t -> unit val open_on : Map.t -> unit
(** [close map] * closes the popup of [map]*)
val close : Map.t -> unit val close : Map.t -> unit
(** [of_jv jv] is [jv] as {!t} *)
val of_jv : Jv.t -> t val of_jv : Jv.t -> t