diff --git a/doc/index.mld b/doc/index.mld index c248edf..1676769 100644 --- a/doc/index.mld +++ b/doc/index.mld @@ -1,17 +1,7 @@ -{0 leaflet} +{0 Leaflet} -{{:https://TODO/leaflet} leaflet} is an {{:https://ocaml.org} OCaml} library/executable to TODO. - -{1:api API} +Leaflet is an [OCaml] bindings library for the {{:https://leafletjs.com} Leaflet} JavaScript library. {!modules: Leaflet } - -{1:private_api Private API} - -You shouldn't have to use any of these modules, they're used internally only. - -{!modules: -TODO -} diff --git a/src/latlng.mli b/src/latlng.mli index 9097890..120d165 100644 --- a/src/latlng.mli +++ b/src/latlng.mli @@ -2,14 +2,22 @@ type t +(** [create lat lng] is an object representing a geographical point with the + given latitude and longitude *) val create : float -> float -> t +(** [lat o] is the latitude of [o] *) val lat : t -> float +(** [lng o] is the longitude of [o] *) 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 +(** [of_jv jv] is [jv] as a [Latlng.t] *) val of_jv : Jv.t -> t +(** [to_jv o] is [o] as a {!Jv.t} *) val to_jv : t -> Jv.t diff --git a/src/layer.ml b/src/layer.ml index 9808ebb..b1e8977 100644 --- a/src/layer.ml +++ b/src/layer.ml @@ -71,7 +71,6 @@ let create_marker : Latlng.t -> [ `Marker ] t = let create_tile_osm : string option -> [ `Tile ] t = fun url -> - (* see https://wiki.openstreetmap.org/wiki/Tile_servers *) let url = Option.value url ~default:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" diff --git a/src/layer.mli b/src/layer.mli index b3816e6..d049182 100644 --- a/src/layer.mli +++ b/src/layer.mli @@ -8,32 +8,46 @@ type _ t = (** Basic layers *) +(** [add_to map layer] adds [layer] to [map] *) val add_to : Map.t -> _ t -> unit +(** [remove layer] removes [layer] from the map it is currently active on *) val remove : _ t -> unit +(** [remove_from map layer] removes [layer] from [map] *) val remove_from : Map.t -> _ t -> unit +(** [bind_popup popup layer] binds [popup] to [layer] *) val bind_popup : Brr.El.t -> _ t -> unit +(** [unbind_popup layer] unbinds the popup bound to [layer] *) val unbind_popup : _ t -> unit +(** [open_popup layer] opens the popup bound to [layer] *) val open_popup : _ t -> unit +(** [close_popup layer] closes the popup bound to [layer] *) val close_popup : _ t -> unit +(** [get_popup layer] is the popup bound to [layer] *) val get_popup : _ t -> Popup.t +(** [to_jv o] is [o] as a {!Jv.t} *) val to_jv : _ t -> Jv.t (** Geojson layers *) +(** [create_geojson geojson] is a new geojson layer *) val create_geojson : ?options:Jv.t -> Jv.t -> [ `Geojson ] t (** Marker layers *) +(** [create_marker latlng] is a new marker with the same position as latlng *) val create_marker : Latlng.t -> [ `Marker ] t (** 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 diff --git a/src/map.ml b/src/map.ml index 8277a9a..bbd5da3 100644 --- a/src/map.ml +++ b/src/map.ml @@ -30,8 +30,6 @@ let set_view latlng ~zoom map = in () -let as_target map = Brr.Ev.target_of_jv map - let on : type kind. kind Event.sub -> (kind Event.t -> 'b) -> t -> unit = fun event handler map -> 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 wrapped_latlng latlng map = +let wrap_latlng latlng map = Latlng.of_jv @@ Jv.call map "wrapLatLng" [| Latlng.to_jv latlng |] diff --git a/src/map.mli b/src/map.mli index 15c1f2b..d027da4 100644 --- a/src/map.mli +++ b/src/map.mli @@ -2,26 +2,43 @@ 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 +(** [invalidate_size map] checks if the map container size changed and updates + the map if so *) 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 +(** [fit_world map] sets a map view that mostly contains the whole world with + the maximum zoom level possible *) val fit_world : t -> unit +(** [get_container map] is the HTML element that contains [map] *) 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 +(** [get_center map] is the geographical center of the map view *) val get_center : t -> Latlng.t +(** [get_zoom map] is the current zoom level of the map view *) val get_zoom : t -> int -val wrapped_latlng : Latlng.t -> t -> Latlng.t - -val as_target : t -> Brr.Ev.target +(** [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 + 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 +(** [to_jv o] is [o] as {!Jv.t} *) val to_jv : t -> Jv.t diff --git a/src/popup.mli b/src/popup.mli index ee5df35..9983c5c 100644 --- a/src/popup.mli +++ b/src/popup.mli @@ -2,12 +2,17 @@ type t +(** [set_latlng latlng] changes the popup position to the given point*) val set_latlng : Latlng.t -> unit +(** [set_content s] changes the popup content to [s]*) val set_content : string -> unit +(** [open_on map] * Adds the popup to [map] and closes the previous one. *) val open_on : Map.t -> unit +(** [close map] * closes the popup of [map]*) val close : Map.t -> unit +(** [of_jv jv] is [jv] as {!t} *) val of_jv : Jv.t -> t