Skip to content

Commit b2924a7

Browse files
committed
feat: Add documentation comments for various components and update version to 0.8.2
1 parent 0f04698 commit b2924a7

File tree

18 files changed

+162
-6
lines changed

18 files changed

+162
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ For now only a few of the components are ported, and events must be set in the S
88

99
NOTE: Current version support leptos 0.6.x, that removes all Scope usages from signals and effects.
1010

11+
Support for leptos 0.7.x exists in the `leptos-0.7` branch. When Leptos 0.7 is released, this branch will be merged into main.
12+
1113
## Features
1214
- CSR/HYDRATE/SSR support
1315

1416
### Components
1517
- MapContainer
18+
- Control
1619
- TileLayer
1720
- TileLayerWms
1821
- ImageOverlay

leptos-leaflet/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "leptos-leaflet"
33
authors = ["Daniel Santana <danielgsantana@gmail.com>", "Artur Leao <artur.leao@gmail.com>", "Lewin Probst <info@emirror.de>"]
4-
version = "0.8.1"
4+
version = "0.8.2"
55
edition = "2021"
66
license = "MIT"
77
repository = "https://github.com/headless-studio/leptos-leaflet"

leptos-leaflet/src/components/bounds.rs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,92 @@
1-
use crate::Position;
21
use leaflet::LatLng;
32
use leaflet::LatLngBounds;
43

4+
use crate::Position;
5+
6+
/// Represents a geographical area defined by its northeast and southwest corners.
7+
///
8+
/// The `Bounds` struct is used to define rectangular areas on a map. It provides methods to calculate
9+
/// the center, size, and check for containment or intersection with other bounds.
10+
///
11+
/// # Fields
12+
///
13+
/// - `ne_corner`: The northeast corner of the bounds.
14+
/// - `sw_corner`: The southwest corner of the bounds.
515
#[derive(Debug, Default, Clone, Copy, PartialEq)]
616
pub struct Bounds {
717
pub ne_corner: Position,
818
pub sw_corner: Position,
919
}
1020

1121
impl Bounds {
22+
/// Creates a new `Bounds` instance with the given northeast and southwest corners.
23+
///
24+
/// # Arguments
25+
///
26+
/// - `ne_corner`: The northeast corner of the bounds.
27+
/// - `sw_corner`: The southwest corner of the bounds.
1228
pub fn new(ne_corner: Position, sw_corner: Position) -> Self {
1329
Self {
1430
ne_corner,
1531
sw_corner,
1632
}
1733
}
1834

35+
/// Gets the center of the bounds.
1936
pub fn get_center(&self) -> Position {
2037
Position {
2138
lat: (self.ne_corner.lat + self.sw_corner.lat) / 2.0,
2239
lng: (self.ne_corner.lng + self.sw_corner.lng) / 2.0,
2340
}
2441
}
2542

43+
/// Gets the southwest corner of the bounds.
2644
pub fn get_bottom_left(&self) -> Position {
2745
Position::new(self.sw_corner.lat, self.sw_corner.lng)
2846
}
2947

48+
/// Gets the northeast corner of the bounds.
3049
pub fn get_top_right(&self) -> Position {
3150
Position::new(self.ne_corner.lat, self.ne_corner.lng)
3251
}
3352

53+
/// Gets the northwest corner of the bounds.
3454
pub fn get_top_left(&self) -> Position {
3555
Position::new(self.ne_corner.lat, self.sw_corner.lng)
3656
}
3757

58+
/// Gets the southeast corner of the bounds.
3859
pub fn get_bottom_right(&self) -> Position {
3960
Position::new(self.sw_corner.lat, self.ne_corner.lng)
4061
}
4162

63+
/// Gets the size of the bounds.
4264
pub fn get_size(&self) -> Position {
4365
Position {
4466
lat: (self.ne_corner.lat - self.sw_corner.lat).abs(),
4567
lng: (self.ne_corner.lng - self.sw_corner.lng).abs(),
4668
}
4769
}
4870

71+
/// Returns true if the rectangle contains the given bounds.
72+
/// A rectangle contains another bounds if it contains all of its points.
73+
///
74+
/// # Arguments
75+
///
76+
/// - `position`: The position to check for containment.
4977
pub fn contains(&self, position: Position) -> bool {
5078
self.sw_corner.lat <= position.lat
5179
&& self.ne_corner.lat >= position.lat
5280
&& self.sw_corner.lng <= position.lng
5381
&& self.ne_corner.lng >= position.lng
5482
}
5583

56-
// Returns true if the rectangle intersects the given bounds. Two bounds intersect if they have at least one point in common.
84+
/// Returns true if the rectangle intersects the given bounds.
85+
/// Two bounds intersect if they have at least one point in common.
86+
///
87+
/// # Arguments
88+
///
89+
/// - `other`: The bounds to check for intersection.
5790
pub fn intersects(&self, other: Bounds) -> bool {
5891
let lat_overlap =
5992
self.ne_corner.lat >= other.sw_corner.lat && self.sw_corner.lat <= other.ne_corner.lat;
@@ -63,7 +96,12 @@ impl Bounds {
6396
lat_overlap && lng_overlap
6497
}
6598

66-
// Returns true if the rectangle overlaps the given bounds. Two bounds overlap if their intersection is an area.
99+
/// Returns true if the rectangle overlaps the given bounds.
100+
/// Two bounds overlap if their intersection is an area.
101+
///
102+
/// # Arguments
103+
///
104+
/// - `other`: The bounds to check for overlap.
67105
pub fn overlaps(&self, other: Bounds) -> bool {
68106
let lat_overlap =
69107
self.ne_corner.lat > other.sw_corner.lat && self.sw_corner.lat < other.ne_corner.lat;
@@ -73,6 +111,7 @@ impl Bounds {
73111
lat_overlap && lng_overlap
74112
}
75113

114+
/// Returns true if the bounds are valid.
76115
pub fn is_valid(&self) -> bool {
77116
self.ne_corner.lat <= 90.0
78117
&& self.ne_corner.lat >= -90.0
@@ -86,6 +125,7 @@ impl Bounds {
86125
&& self.ne_corner.lng >= self.sw_corner.lng
87126
}
88127

128+
/// Returns a new bounds padded by the given ratio.
89129
pub fn pad(&self, buffer_ratio: f64) -> Bounds {
90130
let lat_diff = self.ne_corner.lat - self.sw_corner.lat;
91131
let lng_diff = self.ne_corner.lng - self.sw_corner.lng;
@@ -97,6 +137,7 @@ impl Bounds {
97137
}
98138
}
99139

140+
/// Checks if the bounds are equal to the given bounds.
100141
pub fn equals(&self, other: Bounds) -> bool {
101142
self.ne_corner == other.ne_corner && self.sw_corner == other.sw_corner
102143
}

leptos-leaflet/src/components/circle.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use crate::{
99
use leaflet::CircleOptions;
1010
use leptos::*;
1111

12+
/// A circle overlay that represents a circle on the map.
13+
///
14+
/// The `Circle` component is used to create a circle overlay on the map. It provides options to customize
15+
/// the appearance of the circle, such as the stroke color, fill color, and radius.
1216
#[component(transparent)]
1317
pub fn Circle(
1418
#[prop(into)] center: MaybeSignal<Position>,

leptos-leaflet/src/components/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
use leptos::*;
22
use wasm_bindgen::JsCast;
33

4+
/// A context struct for the Leaflet map.
5+
///
6+
/// This struct provides a way to access the current state of the Leaflet map.
47
#[derive(Debug, Clone, Copy)]
58
pub struct LeafletMapContext {
69
map: RwSignal<Option<leaflet::Map>>,
710
}
811

912
impl LeafletMapContext {
13+
/// Creates a new `LeafletMapContext` instance.
1014
pub fn new() -> Self {
1115
Self {
1216
map: create_rw_signal(None),

leptos-leaflet/src/components/image_overlay.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::components::context::LeafletMapContext;
33
use leptos::logging::log;
44
use leptos::*;
55

6+
/// An image overlay component.
67
#[component(transparent)]
78
pub fn ImageOverlay(
89
#[prop(into)] url: String,

leptos-leaflet/src/components/map_container.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use crate::components::context::provide_leaflet_context;
99
use crate::components::position::Position;
1010
use crate::{MapEvents, PopupEvents, TooltipEvents};
1111

12+
/// A container for the Leaflet map.
13+
///
14+
/// This is the main container for the Leaflet map. It provides a way to add child nodes to the map.
15+
/// It also provides a signal to access the map instance, allowing to interact with the map from other components.
1216
#[component]
1317
pub fn MapContainer(
1418
#[prop(into, optional)] class: MaybeSignal<String>,

leptos-leaflet/src/components/marker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
MouseEvents, MoveEvents, PopupEvents, TooltipEvents,
1111
};
1212

13+
/// A marker component.
1314
#[component(transparent)]
1415
pub fn Marker(
1516
/// Position for the Marker

leptos-leaflet/src/components/path_options.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fmt::{Display, Formatter};
22

3+
/// Options for configuring the appearance of a path join.
34
#[derive(Debug, Copy, Clone)]
45
pub enum LineJoin {
56
Arcs,
@@ -39,6 +40,7 @@ impl AsRef<str> for LineJoin {
3940
}
4041
}
4142

43+
/// Options for configuring the appearance of a path cap.
4244
#[derive(Debug, Copy, Clone)]
4345
pub enum LineCap {
4446
Butt,
@@ -72,6 +74,7 @@ impl AsRef<str> for LineCap {
7274
}
7375
}
7476

77+
/// Options for configuring the appearance of a path fill.
7578
#[derive(Debug, Copy, Clone)]
7679
pub enum FillRule {
7780
NonZero,

leptos-leaflet/src/components/polygon.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
PopupEvents, TooltipEvents,
1414
};
1515

16+
/// A polygon overlay that represents a polygon on the map.
1617
#[component(transparent)]
1718
pub fn Polygon(
1819
#[prop(into)] positions: MaybeSignal<Vec<Position>>,

0 commit comments

Comments
 (0)