Skip to content

Commit

Permalink
Merge pull request #5 from dgsantana/main
Browse files Browse the repository at this point in the history
Refactoring of workspace and more
  • Loading branch information
dgsantana authored May 6, 2023
2 parents cad36c1 + e18e61b commit 6b267b4
Show file tree
Hide file tree
Showing 52 changed files with 1,242 additions and 1,064 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
target/
dist/
/Cargo.lock
/examples/simple-map/Cargo.lock
/examples/with-server/Cargo.lock
28 changes: 2 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
[workspace]
members = [".", "leaflet", "examples/simple-map", "examples/with-server"]

[package]
name = "leptos-leaflet"
version = "0.1.0"
edition = "2021"

[dependencies]
leaflet = { path = "./leaflet" }
leptos = { git = "https://github.com/leptos-rs/leptos", default-features = false }
leptos_meta = { git = "https://github.com/leptos-rs/leptos", default-features = false }
getrandom = { version = "0.2", features = ["js"] }
rand = "0.8"

[dependencies.wasm-bindgen]
version = "0.2"
features = ["serde-serialize"]

[dependencies.web-sys]
version = "0.3"
features = ["console", "HtmlElement", "HtmlDivElement"]

[features]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate"]
csr = ["leptos/csr", "leptos_meta/csr"]
ssr = ["leptos/ssr", "leptos_meta/ssr"]
members = ["leptos-leaflet", "leaflet"]
exclude = ["examples/simple-map", "examples/with-server"]
2 changes: 1 addition & 1 deletion examples/simple-map/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ console_error_panic_hook = "0.1"
leptos = { git = "https://github.com/leptos-rs/leptos", default-features = false, "features" = [
"csr",
] }
leptos-leaflet = { path = "../../", default-features = false, features = [
leptos-leaflet = { path = "../../leptos-leaflet", default-features = false, features = [
"csr",
] }

Expand Down
22 changes: 11 additions & 11 deletions examples/simple-map/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
use std::time::Duration;

use leptos::*;
use leptos_leaflet::{components::*, pos_opt, position, positions};
use leptos_leaflet::*;

#[component]
pub fn App(cx: Scope) -> impl IntoView {
let mut purpleOptions = PolylineOptions::new();
purpleOptions.color("purple");

let (marker_position, set_marker_position) = create_signal(cx, Position::new(51.49, -0.08));

let (marker_opacity, set_marker_opacity) = create_signal(cx, 1.0_f64);

create_effect(cx, move |_| {
set_interval_with_handle(move || {
set_marker_position.update(|pos| { pos.lat += 0.001; pos.lng += 0.001; });
set_marker_opacity.update(|opacity| *opacity += 0.1 );
}, Duration::from_millis(200)).ok()
});
let mut blueOptions = CircleOptions::new();
blueOptions.color("blue");

let opacity = Signal::derive(cx, move || (marker_opacity.get().sin() + 1.0) * 0.5);

view! { cx,
<MapContainer style="height: 400px" center=pos_opt!(51.505, -0.09) zoom=13.0 set_view=true>
<MapContainer style="height: 400px" center=position!(51.505, -0.09) zoom=13.0 set_view=true>
<TileLayer url="https://tile.openstreetmap.org/{z}/{x}/{y}.png" attribution="&copy; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"/>
<Marker position=marker_position >
<Marker position=marker_position opacity=opacity>
<Popup>
<strong>{"A pretty CSS3 popup"}</strong>
</Popup>
Expand All @@ -35,12 +35,12 @@ pub fn App(cx: Scope) -> impl IntoView {
<strong>{"And a tooltip"}</strong>
</Tooltip>
<Polyline positions=positions(&[(51.505, -0.09), (51.51, -0.1), (51.51, -0.12)])/>
<Polygon options=purpleOptions positions=positions(&[ (51.515, -0.09), (51.52, -0.1), (51.52, -0.12)]) >
<Polygon color="purple" positions=positions(&[ (51.515, -0.09), (51.52, -0.1), (51.52, -0.12)]) >
<Tooltip sticky=true direction="top">
<strong>{"I'm a polygon"}</strong>
</Tooltip>
</Polygon>
<Circle center=position!(51.505, -0.09) options=blueOptions radius=200.0>
<Circle center=position!(51.505, -0.09) color="blue" radius=200.0>
<Tooltip sticky=true>{"I'm a circle"}</Tooltip>
</Circle>
</MapContainer>
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-map/trunk.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[build]

[watch]
watch = ["../../src/", "./"]
watch = ["../../leaflet", "../../leptos-leaflet", "./"]
2 changes: 1 addition & 1 deletion examples/with-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ leptos = { git = "https://github.com/leptos-rs/leptos", default-features = false
leptos_axum = { git = "https://github.com/leptos-rs/leptos", optional = true }
leptos_meta = { git = "https://github.com/leptos-rs/leptos", default-features = false }
leptos_router = { git = "https://github.com/leptos-rs/leptos", default-features = false }
leptos-leaflet = { path = "../../", default-features = false }
leptos-leaflet = { path = "../../leptos-leaflet", default-features = false }
log = "0.4"
simple_logger = "4"
tokio = { version = "1.25.0", optional = true }
Expand Down
5 changes: 2 additions & 3 deletions examples/with-server/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use leptos::*;
use leptos_leaflet::{components::*, LocationEvent, pos_opt, position, positions, MapEvents};
use leptos_leaflet::*;
use leptos_meta::*;
use leptos_router::*;
use std::time::Duration;

#[component]
pub fn App(cx: Scope) -> impl IntoView {
Expand Down Expand Up @@ -65,7 +64,7 @@ fn HomePage(cx: Scope) -> impl IntoView {
let events = MapEvents::new().with_location_found(location_found);

view! { cx,
<MapContainer style="height: 400px" center=pos_opt!(51.505, -0.09) zoom=13.0 set_view=true map=set_map locate=true watch=true events>
<MapContainer style="height: 400px" center=position!(51.505, -0.09) zoom=13.0 set_view=true map=set_map locate=true watch=true events>
<TileLayer url="https://tile.openstreetmap.org/{z}/{x}/{y}.png" attribution="&copy; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"/>
<Marker position=marker_position >
<Popup>
Expand Down
4 changes: 2 additions & 2 deletions leaflet/src/control.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Map;
use wasm_bindgen::prelude::*;
use web_sys::HtmlElement;
use crate::Map;

#[wasm_bindgen]
extern "C" {
Expand All @@ -22,4 +22,4 @@ extern "C" {

#[wasm_bindgen(method)]
pub fn remove(this: &Control) -> Control;
}
}
2 changes: 1 addition & 1 deletion leaflet/src/div_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ extern "C" {

#[wasm_bindgen(method)]
pub fn openOn(this: &DivOverlay, map: &Map);
}
}
4 changes: 2 additions & 2 deletions leaflet/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use wasm_bindgen::prelude::*;
use js_sys::Object;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
Expand Down Expand Up @@ -39,4 +39,4 @@ extern "C" {

#[wasm_bindgen(method, setter, js_name = layer)]
pub fn setLayer(this: &Event, value: &Object);
}
}
2 changes: 1 addition & 1 deletion leaflet/src/evented.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Event;
use js_sys::Object;
use wasm_bindgen::prelude::*;
use crate::Event;

#[wasm_bindgen]
extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions leaflet/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use js_sys::Object;
use js_sys::Object;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
Expand All @@ -18,4 +18,4 @@ extern "C" {
/// Check if the handler is enabled
#[wasm_bindgen(method)]
pub fn enabled(this: &Handler) -> bool;
}
}
10 changes: 6 additions & 4 deletions leaflet/src/icon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use js_sys::Object;
use wasm_bindgen::prelude::*;
use crate::{object_constructor, object_property_set, Point};
use js_sys::Object;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
Expand All @@ -16,7 +16,9 @@ extern "C" {
pub fn new(options: &IconOptions) -> Icon;
}

#[wasm_bindgen(inline_js = "export function setDefaultIconOptions(options) { L.Marker.prototype.options.icon = L.icon(options); }")]
#[wasm_bindgen(
inline_js = "export function setDefaultIconOptions(options) { L.Marker.prototype.options.icon = L.icon(options); }"
)]
extern "C" {
pub fn setDefaultIconOptions(options: &IconOptions);
}
Expand All @@ -40,4 +42,4 @@ impl Default for IconOptions {
fn default() -> Self {
Self::new()
}
}
}
2 changes: 1 addition & 1 deletion leaflet/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extern "C" {
/// [`bindTooltip`](https://leafletjs.com/reference.html#layer-bindtooltip)
#[wasm_bindgen(method)]
pub fn bindTooltip(this: &Layer, tooltip: &Tooltip) -> Layer;

#[wasm_bindgen(method)]
pub fn bindTooltipWithContent(this: &Layer, content: &JsValue, options: &JsValue) -> Layer;

Expand Down
4 changes: 2 additions & 2 deletions leaflet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod control;
mod div_overlay;
mod event;
mod evented;
mod grid_layer;
mod handler;
Expand All @@ -14,15 +15,14 @@ mod popup;
mod raster;
mod shapes;
mod tooltip;
mod event;

use js_sys::{Array, Object};
use wasm_bindgen::prelude::*;

pub use control::Control;
pub use div_overlay::DivOverlay;
pub use evented::Evented;
pub use event::Event;
pub use evented::Evented;
pub use grid_layer::{GridLayer, GridLayerOptions};
pub use handler::Handler;
pub use icon::{setDefaultIconOptions, Icon, IconOptions};
Expand Down
4 changes: 2 additions & 2 deletions leaflet/src/map/events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use wasm_bindgen::prelude::*;
use crate::{Event, LocationEvent, Point, Popup};
use wasm_bindgen::prelude::*;

use super::Map;

Expand Down Expand Up @@ -129,4 +129,4 @@ impl Map {
let closure = Closure::wrap(callback);
self.on("popupclose", &closure.into_js_value());
}
}
}
2 changes: 1 addition & 1 deletion leaflet/src/map/geolocation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use js_sys::{Object, Reflect};
use wasm_bindgen::prelude::*;

use crate::{Map, object_constructor};
use crate::{object_constructor, Map};

#[wasm_bindgen]
extern "C" {
Expand Down
6 changes: 3 additions & 3 deletions leaflet/src/map/location_event.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use wasm_bindgen::prelude::*;
use crate::{Event, LatLng, LatLngBounds};
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen (extends = Event, js_name = LocationEvent)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub type LocationEvent;

#[wasm_bindgen(constructor)]
pub fn new() -> LocationEvent;

Expand Down Expand Up @@ -57,4 +57,4 @@ extern "C" {

#[wasm_bindgen(method, setter,js_name = timestamp)]
pub fn setTimestamp(this: &LocationEvent, value: f64);
}
}
4 changes: 2 additions & 2 deletions leaflet/src/map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod events;
mod geolocation;
mod location_event;
mod other;
mod events;

use js_sys::{Array, Object};
use wasm_bindgen::prelude::*;
Expand All @@ -11,9 +11,9 @@ use crate::{
object_constructor, object_property_set, object_property_set_with, Control, Evented, LatLng,
LatLngBounds, Layer, Point, Popup, Tooltip,
};
pub use events::*;
pub use geolocation::*;
pub use location_event::*;
pub use events::*;
pub use other::*;

#[wasm_bindgen]
Expand Down
10 changes: 5 additions & 5 deletions leaflet/src/marker.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use js_sys::Object;
use crate::{object_constructor, object_property_set, Handler, Icon, LatLng, Layer, Point};
use js_sys::Object;
use wasm_bindgen::prelude::*;
use crate::{Handler, Icon, LatLng, Layer, object_constructor, object_property_set, Point};

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object, js_name = MarkerOptions)]
#[derive(Debug, Clone)]
pub type MarkerOptions;

// Marker
#[derive(Debug, Clone)]
#[wasm_bindgen(extends = Layer)]
Expand Down Expand Up @@ -40,7 +40,7 @@ extern "C" {
/// ['on'](https://leafletjs.com/reference.html#marker-on)
#[wasm_bindgen(method)]
pub fn on(this: &Marker, event_name: &str, handler: &JsValue);

/// ['dragging'](https://leafletjs.com/reference.html#marker-dragging)
#[wasm_bindgen(method, getter)]
pub fn dragging(this: &Marker) -> Handler;
Expand Down Expand Up @@ -91,4 +91,4 @@ impl Default for MarkerOptions {
fn default() -> Self {
Self::new()
}
}
}
10 changes: 7 additions & 3 deletions leaflet/src/popup.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use js_sys::Object;
use wasm_bindgen::prelude::*;

use crate::{LatLng, Layer, object_constructor, object_property_set, Point, DivOverlay};
use crate::{object_constructor, object_property_set, DivOverlay, LatLng, Layer, Point};

#[wasm_bindgen]
extern "C" {
Expand Down Expand Up @@ -34,7 +34,11 @@ impl PopupOptions {
object_property_set!(max_height, maxHeight, f64);
object_property_set!(auto_pan, autoPan, bool);
object_property_set!(auto_pan_padding_top_left, autoPanPaddingTopLeft, Point);
object_property_set!(auto_pan_padding_bottom_right, autoPanPaddingBottomRight, Point);
object_property_set!(
auto_pan_padding_bottom_right,
autoPanPaddingBottomRight,
Point
);
object_property_set!(auto_pan_padding, autoPanPadding, Point);
object_property_set!(keep_in_view, keepInView, bool);
object_property_set!(close_button, closeButton, bool);
Expand All @@ -48,4 +52,4 @@ impl Default for PopupOptions {
fn default() -> Self {
Self::new()
}
}
}
6 changes: 3 additions & 3 deletions leaflet/src/raster/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod tile_layer;
mod image_overlay;
mod tile_layer;
mod video_overlay;

pub use tile_layer::{TileLayer, TileLayerOptions};
pub use image_overlay::{ImageOverlay, ImageOverlayOptions};
pub use video_overlay::{VideoOverlay, VideoOverlayOptions};
pub use tile_layer::{TileLayer, TileLayerOptions};
pub use video_overlay::{VideoOverlay, VideoOverlayOptions};
Loading

0 comments on commit 6b267b4

Please sign in to comment.