diff --git a/Cargo.toml b/Cargo.toml index cf622ca..dc0ed0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["leptos-leaflet", "leaflet"] +members = ["leptos-leaflet"] exclude = ["examples/simple-map", "examples/with-server"] resolver = "2" @@ -7,7 +7,7 @@ resolver = "2" getrandom = { version = "0.2", features = ["js"] } js-sys = "0.3" -leaflet = { path = "./leaflet" } +leaflet = "0.3" leptos = { version = "0.5", default-features = false } leptos_meta = { version = "0.5", default-features = false } diff --git a/examples/simple-map/Cargo.lock b/examples/simple-map/Cargo.lock index 290c900..73604d8 100644 --- a/examples/simple-map/Cargo.lock +++ b/examples/simple-map/Cargo.lock @@ -637,9 +637,12 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "leaflet" -version = "1.9.3" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e5fa1d484cd483b16a40ce3325cfa21b851337a05a98c3129fdd5f26f5aefe" dependencies = [ "js-sys", + "paste", "wasm-bindgen", "web-sys", ] diff --git a/examples/with-server/Cargo.lock b/examples/with-server/Cargo.lock index 4a8d0a8..90cdd82 100644 --- a/examples/with-server/Cargo.lock +++ b/examples/with-server/Cargo.lock @@ -890,9 +890,12 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "leaflet" -version = "1.9.3" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e5fa1d484cd483b16a40ce3325cfa21b851337a05a98c3129fdd5f26f5aefe" dependencies = [ "js-sys", + "paste", "wasm-bindgen", "web-sys", ] diff --git a/examples/with-server/src/app.rs b/examples/with-server/src/app.rs index 3b44052..4a1565d 100644 --- a/examples/with-server/src/app.rs +++ b/examples/with-server/src/app.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use leptos::logging::log; use leptos::*; use leptos_leaflet::leaflet::{LocationEvent, Map}; @@ -38,16 +40,16 @@ fn HomePage() -> impl IntoView { let (map, set_map) = create_signal(None::); create_effect(move |_| { - // set_interval_with_handle( - // move || { - // set_marker_position.update(|pos| { - // pos.lat += 0.001; - // pos.lng += 0.001; - // }); - // }, - // Duration::from_millis(200), - // ) - // .ok() + set_interval_with_handle( + move || { + set_marker_position.update(|pos| { + pos.lat += 0.001; + pos.lng += 0.001; + }); + }, + Duration::from_secs(1), + ) + .ok() }); create_effect(move |_| { @@ -57,7 +59,7 @@ fn HomePage() -> impl IntoView { }); let location_found = move |loc: LocationEvent| { - log!("hello from {:?}", loc.latlng()); + log!("hello from {:?}", loc.lat_lng()); }; let events = MapEvents::new().location_found(location_found); @@ -75,6 +77,11 @@ fn HomePage() -> impl IntoView { {"A pretty CSS3 popup"} + + + {"A moving marker"} + + {"And a tooltip"} diff --git a/leaflet/Cargo.toml b/leaflet/Cargo.toml deleted file mode 100644 index 7a4053b..0000000 --- a/leaflet/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "leaflet" -version = "1.9.3" -edition = "2021" -publish = false -license = "MIT" - -[dependencies] -wasm-bindgen = "0.2" -js-sys = "0.3" - -[dependencies.web-sys] -version = "0.3" -features = ["Event", "HtmlElement", "MouseEvent"] - diff --git a/leaflet/src/control.rs b/leaflet/src/control.rs deleted file mode 100644 index 0402afc..0000000 --- a/leaflet/src/control.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::Map; -use wasm_bindgen::prelude::*; -use web_sys::HtmlElement; - -#[wasm_bindgen] -extern "C" { - #[derive(Clone, Debug)] - #[wasm_bindgen(js_namespace = L, js_name = Control)] - pub type Control; - - #[wasm_bindgen(method)] - pub fn getPosition(this: &Control) -> String; - - #[wasm_bindgen(method)] - pub fn setPosition(this: &Control, position: &str) -> Control; - - #[wasm_bindgen(method)] - pub fn getContainer(this: &Control) -> HtmlElement; - - #[wasm_bindgen(method)] - pub fn addTo(this: &Control, map: &Map) -> Control; - - #[wasm_bindgen(method)] - pub fn remove(this: &Control) -> Control; -} diff --git a/leaflet/src/crs.rs b/leaflet/src/crs.rs deleted file mode 100644 index b1542a7..0000000 --- a/leaflet/src/crs.rs +++ /dev/null @@ -1,30 +0,0 @@ -use wasm_bindgen::prelude::*; - -use crate::{LatLng, Point}; - -#[wasm_bindgen] -extern "C" { - #[derive(Debug)] - pub type Crs; - - #[wasm_bindgen(constructor, js_namespace = ["L", "CRS"], js_name = "Simple")] - pub fn new_simple() -> Crs; - - #[wasm_bindgen(constructor, js_namespace = ["L", "CRS"], js_name = "Earth")] - pub fn new_earth() -> Crs; - - #[wasm_bindgen(constructor, js_namespace = ["L", "CRS"], js_name = "EPSG3395")] - pub fn new_epsg_3395() -> Crs; - - #[wasm_bindgen(constructor, js_namespace = ["L", "CRS"], js_name = "EPSG3857")] - pub fn new_epsg_3857() -> Crs; - - #[wasm_bindgen(constructor, js_namespace = ["L", "CRS"], js_name = "EPSG4326")] - pub fn new_epsg_4326() -> Crs; - - #[wasm_bindgen(constructor, js_namespace = ["L", "CRS"], js_name = "Base")] - pub fn new_base() -> Crs; - - #[wasm_bindgen(method, js_name = "latLngToPoint")] - pub fn latLngToPoint(this: &Crs, latlng: LatLng, zoom: f32) -> Point; -} diff --git a/leaflet/src/div_icon.rs b/leaflet/src/div_icon.rs deleted file mode 100644 index 5b7e358..0000000 --- a/leaflet/src/div_icon.rs +++ /dev/null @@ -1,35 +0,0 @@ -use crate::{object_constructor, object_property_set, Icon, Point}; -use js_sys::Object; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = Object, js_name = DivIconOptions)] - #[derive(Debug, Clone)] - pub type DivIconOptions; - - #[derive(Debug, Clone)] - #[wasm_bindgen(extends = Icon, js_namespace = L, js_name = Icon)] - pub type DivIcon; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(options: &DivIconOptions) -> DivIcon; -} - -impl DivIconOptions { - object_constructor!(); - object_property_set!(html, &str); - object_property_set!(bg_pos, bgPos, Point); - object_property_set!(icon_size, iconSize, Point); - object_property_set!(icon_anchor, iconAnchor, Point); - object_property_set!(popup_anchor, popupAnchor, Point); - object_property_set!(tooltip_anchor, tooltipAnchor, Point); - object_property_set!(class_name, className, &str); - object_property_set!(cross_origin, crossOrigin, &str); -} - -impl Default for DivIconOptions { - fn default() -> Self { - Self::new() - } -} diff --git a/leaflet/src/div_overlay.rs b/leaflet/src/div_overlay.rs deleted file mode 100644 index 302a95c..0000000 --- a/leaflet/src/div_overlay.rs +++ /dev/null @@ -1,50 +0,0 @@ -use wasm_bindgen::prelude::*; -use web_sys::HtmlElement; - -use crate::{LatLng, Layer, Map}; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(js_namespace = L, js_name = DivOverlay, extends = Layer)] - #[derive(Debug, Clone)] - pub type DivOverlay; - - #[wasm_bindgen(constructor)] - pub fn new(options: &JsValue) -> DivOverlay; - - #[wasm_bindgen(method)] - pub fn setContent(this: &DivOverlay, content: &JsValue) -> DivOverlay; - - #[wasm_bindgen(method)] - pub fn getContent(this: &DivOverlay) -> JsValue; - - #[wasm_bindgen(method)] - pub fn setLatLng(this: &DivOverlay, latlng: &JsValue) -> DivOverlay; - - #[wasm_bindgen(method)] - pub fn getLatLng(this: &DivOverlay) -> LatLng; - - #[wasm_bindgen(method)] - pub fn toggle(this: &DivOverlay) -> DivOverlay; - - #[wasm_bindgen(method)] - pub fn close(this: &DivOverlay) -> DivOverlay; - - #[wasm_bindgen(method)] - pub fn isOpen(this: &DivOverlay) -> bool; - - #[wasm_bindgen(method)] - pub fn getElement(this: &DivOverlay) -> HtmlElement; - - #[wasm_bindgen(method)] - pub fn update(this: &DivOverlay); - - #[wasm_bindgen(method)] - pub fn bringToFront(this: &DivOverlay) -> DivOverlay; - - #[wasm_bindgen(method)] - pub fn bringToBack(this: &DivOverlay) -> DivOverlay; - - #[wasm_bindgen(method)] - pub fn openOn(this: &DivOverlay, map: &Map); -} diff --git a/leaflet/src/event.rs b/leaflet/src/event.rs deleted file mode 100644 index 5499576..0000000 --- a/leaflet/src/event.rs +++ /dev/null @@ -1,42 +0,0 @@ -use js_sys::Object; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = Object, js_name = Event)] - #[derive(Debug, Clone, Eq, PartialEq)] - pub type Event; - - #[wasm_bindgen(constructor)] - pub fn new() -> Event; - - #[wasm_bindgen(method, getter, js_name = "type")] - pub fn eventType(this: &Event) -> String; - - #[wasm_bindgen(method, setter, js_name = "type")] - pub fn setEventType(this: &Event, value: &str); - - #[wasm_bindgen(method, getter, js_name = target)] - pub fn target(this: &Event) -> Object; - - #[wasm_bindgen(method, setter, js_name = target)] - pub fn setTarget(this: &Event, value: &Object); - - #[wasm_bindgen(method, getter, js_name = sourceTarget)] - pub fn sourceTarget(this: &Event) -> Object; - - #[wasm_bindgen(method, setter, js_name = sourceTarget)] - pub fn setsourceTarget(this: &Event, value: &Object); - - #[wasm_bindgen(method, getter, js_name = propagatedFrom)] - pub fn propagatedFrom(this: &Event) -> Object; - - #[wasm_bindgen(method, setter, js_name = propagatedFrom)] - pub fn setPropagatedFrom(this: &Event, value: &Object); - - #[wasm_bindgen(method, getter, js_name = layer)] - pub fn layer(this: &Event) -> Object; - - #[wasm_bindgen(method, setter, js_name = layer)] - pub fn setLayer(this: &Event, value: &Object); -} diff --git a/leaflet/src/evented.rs b/leaflet/src/evented.rs deleted file mode 100644 index 3e6ebdd..0000000 --- a/leaflet/src/evented.rs +++ /dev/null @@ -1,387 +0,0 @@ -use std::borrow::Cow; - -use crate::map::{DragEndEvent, TooltipEvent}; -use crate::{ - Circle, CircleMarker, Event, Layer, Map, Marker, MouseEvent, Path, Polygon, Polyline, - PopupEvent, -}; -use js_sys::Object; -use wasm_bindgen::convert::FromWasmAbi; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[derive(Debug, Clone, PartialEq)] - pub type Evented; - - /// Creates a new Evented object. - /// - /// [`on`](https://leafletjs.com/reference.html#evented-on) - #[wasm_bindgen(method, js_name = on)] - pub fn on(this: &Evented, kind: &str, handler: &JsValue) -> Evented; - - /// Removes an event listener. - /// - /// [`off`](https://leafletjs.com/reference.html#evented-off) - #[wasm_bindgen(method)] - pub fn off(this: &Evented, kind: &str, handler: &JsValue) -> Evented; - - #[wasm_bindgen(method, js_name = off)] - pub fn offByName(this: &Evented, kind: &str) -> Evented; - - /// Removes all event listeners. - /// - /// [`off`](https://leafletjs.com/reference.html#evented-off) - #[wasm_bindgen(method, js_name = off)] - pub fn offAll(this: &Evented) -> Evented; - - /// Emits an event. - /// - /// [`fire`](https://leafletjs.com/reference.html#evented-fire) - #[wasm_bindgen(method)] - pub fn fire(this: &Evented, kind: &str, data: &Object, propagate: Option) -> Evented; - - /// Returns true if the event has listeners. - /// - /// [`listens`](https://leafletjs.com/reference.html#evented-listens) - #[wasm_bindgen(method)] - pub fn listens(this: &Evented, kind: &str, propagate: Option) -> bool; - - /// Returns true if the event has listeners. - /// - /// [`once`](https://leafletjs.com/reference.html#evented-once) - #[wasm_bindgen(method)] - pub fn once(this: &Evented, kind: &str, handler: &JsValue) -> Evented; - - /// Returns true if the event has listeners. - /// - /// [`addEventParent`](https://leafletjs.com/reference.html#evented-addeventparent) - #[wasm_bindgen(method)] - pub fn addEventParent(this: &Evented, other: &Evented) -> Evented; - - /// Returns true if the event has listeners. - /// - /// ['removeEventParent'](https://leafletjs.com/reference.html#evented-removeeventparent) - #[wasm_bindgen(method)] - pub fn removeEventParent(this: &Evented, other: &Evented) -> Evented; - - /// Returns true if the event has listeners. - /// - /// [`addEventListener`](https://leafletjs.com/reference.html#evented-addeventlistener) - #[wasm_bindgen(method)] - pub fn addEventListener( - this: &Evented, - kind: &str, - handler: &Closure, - ) -> Evented; - - /// Returns true if the event has listeners. - /// - /// [`removeEventListener`](https://leafletjs.com/reference.html#evented-removeeventlistener) - #[wasm_bindgen(method)] - pub fn removeEventListener( - this: &Evented, - kind: &str, - handler: &Closure, - ) -> Evented; - - /// Clears all event listeners. - /// - /// [`clearAllEventListeners`](https://leafletjs.com/reference.html#evented-cleareventlisteners) - #[wasm_bindgen(method)] - pub fn clearAllEventListeners(this: &Evented) -> Evented; - - /// Adds a one time event listener. - /// - /// [`addOneTimeEventListener`](https://leafletjs.com/reference.html#evented-addonetimeeventlistener) - #[wasm_bindgen(method)] - pub fn addOneTimeEventListener( - this: &Evented, - kind: &str, - handler: &Closure, - ) -> Evented; - - /// Fires an event. - /// - /// [`fireEvent`](https://leafletjs.com/reference.html#evented-fireevent) - #[wasm_bindgen(method)] - pub fn fireEvent(this: &Evented, kind: &str, data: &Object, propagate: Option) - -> Evented; - - /// Returns true if the event has listeners. - /// - /// [`hasEventListeners`](https://leafletjs.com/reference.html#evented-haseventlisteners) - #[wasm_bindgen(method)] - pub fn hasEventListeners(this: &Evented, kind: &str, propagate: Option) -> bool; -} - -pub trait FromLeafletEvent: FromWasmAbi { - type EventType; - fn from_leaflet_event(event: Self::EventType) -> Self; -} - -impl FromLeafletEvent for Event { - type EventType = Event; - fn from_leaflet_event(event: Self::EventType) -> Self { - event - } -} - -impl FromLeafletEvent for MouseEvent { - type EventType = Event; - fn from_leaflet_event(event: Self::EventType) -> Self { - event.unchecked_into() - } -} - -impl FromLeafletEvent for DragEndEvent { - type EventType = Event; - fn from_leaflet_event(event: Self::EventType) -> Self { - event.unchecked_into() - } -} - -impl FromLeafletEvent for TooltipEvent { - type EventType = Event; - fn from_leaflet_event(event: Self::EventType) -> Self { - event.unchecked_into() - } -} - -pub struct EventedHandle { - target: Evented, - event_type: Cow<'static, str>, - callback: Closure, -} - -impl EventedHandle { - pub fn callback(&self) -> &Closure { - &self.callback - } -} - -impl Drop for EventedHandle { - fn drop(&mut self) { - self.target - .off(&self.event_type, self.callback.as_ref().unchecked_ref()); - } -} - -impl Evented { - pub fn on_leaflet_event(target: &T, event: S, callback: F) -> EventedHandle - where - T: EventedTarget, - E: FromLeafletEvent + 'static, - F: FnMut(E) + 'static, - S: Into>, - { - let callback = Closure::wrap(Box::new(callback) as Box); - let event_type = event.into(); - let target = target.as_evented(); - target.on(&event_type, callback.as_ref().unchecked_ref()); - EventedHandle { - target, - event_type, - callback, - } - } -} - -pub trait EventedTarget { - fn as_evented(&self) -> Evented; -} - -impl EventedTarget for Layer { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for &Layer { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for &Evented { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for &Map { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for Marker { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for &Marker { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for &Path { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for &Polygon { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for &Polyline { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for &Circle { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -impl EventedTarget for &CircleMarker { - fn as_evented(&self) -> Evented { - self.unchecked_ref::().clone() - } -} - -pub trait LeafletEventHandler { - fn on(&self, event: &str, callback: &JsValue); -} - -pub trait MoveEvents -where - Self: LeafletEventHandler, -{ - fn on_move(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("move", &closure.into_js_value()); - } -} - -pub trait MouseEvents -where - Self: LeafletEventHandler, -{ - fn on_click(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("click", &closure.into_js_value()); - } - - fn on_double_click(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("dblclick", &closure.into_js_value()); - } - - fn on_mouse_down(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("mousedown", &closure.into_js_value()); - } - - fn on_mouse_up(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("mouseup", &closure.into_js_value()); - } - - fn on_mouse_over(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("mouseover", &closure.into_js_value()); - } - - fn on_mouse_out(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("mouseout", &closure.into_js_value()); - } - - fn on_context_menu(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("contextmenu", &closure.into_js_value()); - } -} - -pub trait DragEvents -where - Self: LeafletEventHandler, -{ - fn on_drag_start(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("dragstart", &closure.into_js_value()); - } - - fn on_move_start(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("movestart", &closure.into_js_value()); - } - - fn on_drag(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("drag", &closure.into_js_value()); - } - - fn on_drag_end(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("dragend", &closure.into_js_value()); - } - - fn on_move_end(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("moveend", &closure.into_js_value()); - } -} - -pub trait LayerEvents -where - Self: LeafletEventHandler, -{ - fn on_add(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("add", &closure.into_js_value()); - } - - fn on_remove(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("remove", &closure.into_js_value()); - } -} - -pub trait PopupEvents -where - Self: LeafletEventHandler, -{ - fn on_popup_open(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("popupopen", &closure.into_js_value()); - } - - fn on_popup_close(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("popupclose", &closure.into_js_value()); - } -} - -pub trait TooltipEvents -where - Self: LeafletEventHandler, -{ - fn on_tooltip_open(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("tooltipopen", &closure.into_js_value()); - } - - fn on_tooltip_close(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("tooltipclose", &closure.into_js_value()); - } -} diff --git a/leaflet/src/feature_group.rs b/leaflet/src/feature_group.rs deleted file mode 100644 index 946f170..0000000 --- a/leaflet/src/feature_group.rs +++ /dev/null @@ -1,27 +0,0 @@ -use wasm_bindgen::prelude::*; - -use crate::{LatLngBounds, LayerGroup}; - -#[wasm_bindgen] -extern "C" { - /// [`FeatureGroup`](https://leafletjs.com/reference-1.7.1.html#featuregroup) - #[derive(Clone, Debug)] - #[wasm_bindgen(extends = LayerGroup)] - pub type FeatureGroup; - - /// [`setStyle`](https://leafletjs.com/reference-1.7.1.html#featuregroup-setstyle) - #[wasm_bindgen(method)] - pub fn setStyle(this: &FeatureGroup, style: &JsValue); - - /// [`bringToFront`](https://leafletjs.com/reference-1.7.1.html#featuregroup-bringtofront) - #[wasm_bindgen(method)] - pub fn bringToFront(this: &FeatureGroup); - - /// [`bringToBack`](https://leafletjs.com/reference-1.7.1.html#featuregroup-bringtoback) - #[wasm_bindgen(method)] - pub fn bringToBack(this: &FeatureGroup); - - /// [`getBounds`](https://leafletjs.com/reference-1.7.1.html#featuregroup-getbounds) - #[wasm_bindgen(method)] - pub fn getBounds(this: &FeatureGroup) -> LatLngBounds; -} diff --git a/leaflet/src/geo_json.rs b/leaflet/src/geo_json.rs deleted file mode 100644 index d5a2d9d..0000000 --- a/leaflet/src/geo_json.rs +++ /dev/null @@ -1,27 +0,0 @@ -use wasm_bindgen::prelude::*; - -use crate::Layer; - -#[wasm_bindgen] -extern "C" { - /// [`GeoJSON`](https://leafletjs.com/reference-1.7.1.html#geojson) - #[derive(Clone, Debug)] - #[wasm_bindgen(extends = Layer)] - pub type GeoJSON; - - /// [`L.geoJSON`](https://leafletjs.com/reference-1.7.1.html#geojson-l-geojson) - #[wasm_bindgen(js_namespace = L)] - pub fn geoJSON(geojson: &JsValue, options: &JsValue) -> GeoJSON; - - /// [`addData`](https://leafletjs.com/reference-1.7.1.html#geojson-adddata) - #[wasm_bindgen(method)] - pub fn addData(this: &GeoJSON, data: &JsValue); - - /// [`resetStyle`](https://leafletjs.com/reference-1.7.1.html#geojson-resetstyle) - #[wasm_bindgen(method)] - pub fn resetStyle(this: &GeoJSON, layer: Option<&Layer>); - - /// [`setStyle`](https://leafletjs.com/reference-1.7.1.html#geojson-setstyle) - #[wasm_bindgen(method)] - pub fn setStyle(this: &GeoJSON, style: &JsValue); -} diff --git a/leaflet/src/grid_layer.rs b/leaflet/src/grid_layer.rs deleted file mode 100644 index 8139fa7..0000000 --- a/leaflet/src/grid_layer.rs +++ /dev/null @@ -1,70 +0,0 @@ -use js_sys::Object; -use wasm_bindgen::prelude::*; -use web_sys::HtmlElement; - -use crate::{object_constructor, object_property_set, LatLngBounds, Layer, Point}; - -#[wasm_bindgen] -extern "C" { - - # [wasm_bindgen (extends = Object, js_name = GridLayerOptions)] - #[derive(Debug, Clone, PartialEq)] - pub type GridLayerOptions; - - #[wasm_bindgen(extends = Layer)] - #[derive(Debug, Clone, PartialEq)] - pub type GridLayer; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new() -> GridLayer; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn newWithOptions(options: &GridLayerOptions) -> GridLayer; - - #[wasm_bindgen(method, js_name = bringToFront)] - pub fn bringToFront(this: &GridLayer) -> GridLayer; - - #[wasm_bindgen(method, js_name = bringToBack)] - pub fn bringToBack(this: &GridLayer) -> GridLayer; - - #[wasm_bindgen(method, js_name = getContainer)] - pub fn getContainer(this: &GridLayer) -> HtmlElement; - - #[wasm_bindgen(method, js_name = setOpacity)] - pub fn setOpacity(this: &GridLayer, opacity: f64) -> GridLayer; - - #[wasm_bindgen(method, js_name = setZIndex)] - pub fn setZIndex(this: &GridLayer, opacity: f64) -> GridLayer; - - #[wasm_bindgen(method, js_name = isLoading)] - pub fn isLoading(this: &GridLayer) -> bool; - - #[wasm_bindgen(method, js_name = redraw)] - pub fn redraw(this: &GridLayer) -> GridLayer; -} - -impl GridLayerOptions { - object_constructor!(); - object_property_set!(tile_size, tileSize, f64); - object_property_set!(tile_size_point, tileSize, &Point); - object_property_set!(opacity, f64); - object_property_set!(update_when_idle, updateWhenIdle, bool); - object_property_set!(update_when_zooming, updateWhenZooming, bool); - object_property_set!(update_interval, updateInterval, f64); - object_property_set!(z_index, zIndex, f64); - object_property_set!(bounds, &LatLngBounds); - object_property_set!(min_zoom, minZoom, f64); - object_property_set!(max_zoom, maxZoom, f64); - object_property_set!(min_native_zoom, minNativeZoom, f64); - object_property_set!(max_native_zoom, maxNativeZoom, f64); - object_property_set!(no_wrap, noWrap, bool); - object_property_set!(pane, &str); - object_property_set!(class_name, className, &str); - object_property_set!(keep_buffer, keepBuffer, f64); -} - -impl Default for GridLayerOptions { - fn default() -> Self { - GridLayerOptions::new() - } -} diff --git a/leaflet/src/handler.rs b/leaflet/src/handler.rs deleted file mode 100644 index 7fe0f82..0000000 --- a/leaflet/src/handler.rs +++ /dev/null @@ -1,21 +0,0 @@ -use js_sys::Object; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = Object, js_name = DivOverlay)] - #[derive(Debug, Clone)] - pub type Handler; - - /// Create a new handler - #[wasm_bindgen(method)] - pub fn enable(this: &Handler) -> Handler; - - /// Remove the handler - #[wasm_bindgen(method)] - pub fn disable(this: &Handler) -> Handler; - - /// Check if the handler is enabled - #[wasm_bindgen(method)] - pub fn enabled(this: &Handler) -> bool; -} diff --git a/leaflet/src/icon.rs b/leaflet/src/icon.rs deleted file mode 100644 index 2a92d1c..0000000 --- a/leaflet/src/icon.rs +++ /dev/null @@ -1,38 +0,0 @@ -use crate::{object_constructor, object_property_set, Point}; -use js_sys::Object; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = Object, js_name = IconOptions)] - #[derive(Debug, Clone)] - pub type IconOptions; - - #[derive(Debug, Clone)] - #[wasm_bindgen(js_namespace = L, js_name = Icon)] - pub type Icon; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(options: &IconOptions) -> Icon; -} - -impl IconOptions { - object_constructor!(); - object_property_set!(icon_url, iconUrl, &str); - object_property_set!(icon_size, iconSize, Point); - object_property_set!(icon_anchor, iconAnchor, Point); - object_property_set!(popup_anchor, popupAnchor, Point); - object_property_set!(shadow_anchor, shadowAnchor, Point); - object_property_set!(tooltip_anchor, tooltipAnchor, Point); - object_property_set!(shadow_url, shadowUrl, &str); - object_property_set!(shadow_retina_url, shadowRetinaUrl, &str); - object_property_set!(shadow_size, shadowSize, Point); - object_property_set!(class_name, className, &str); - object_property_set!(cross_origin, crossOrigin, &str); -} - -impl Default for IconOptions { - fn default() -> Self { - Self::new() - } -} diff --git a/leaflet/src/lat_lng.rs b/leaflet/src/lat_lng.rs deleted file mode 100644 index f888380..0000000 --- a/leaflet/src/lat_lng.rs +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) HeadlessStudio 2023. - */ - -use std::ops::{Add, AddAssign, Div, Sub}; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[derive(Debug, Default, Clone)] - pub type LatLng; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(lat: f64, lng: f64) -> LatLng; - - #[wasm_bindgen(method, getter)] - pub fn lat(this: &LatLng) -> f64; - - #[wasm_bindgen(method, getter)] - pub fn lng(this: &LatLng) -> f64; - - #[wasm_bindgen(method, setter)] - pub fn set_lat(this: &LatLng, value: f64) -> f64; - - #[wasm_bindgen(method, setter)] - pub fn set_lng(this: &LatLng, value: f64) -> f64; - - #[wasm_bindgen(method)] - pub fn distanceTo(this: &LatLng, otherLatLng: &LatLng) -> f64; - -} - -#[allow(clippy::from_over_into)] -impl Into for (f64, f64) { - fn into(self) -> LatLng { - LatLng::new(self.0, self.1) - } -} - -#[allow(clippy::from_over_into)] -impl Into for [f64; 2] { - fn into(self) -> LatLng { - LatLng::new(self[0], self[1]) - } -} - -impl Add for LatLng { - type Output = LatLng; - - fn add(self, rhs: LatLng) -> Self::Output { - LatLng::new(self.lat() + rhs.lat(), self.lng() + rhs.lng()) - } -} - -impl Add for &LatLng { - type Output = LatLng; - - fn add(self, rhs: LatLng) -> Self::Output { - LatLng::new(self.lat() + rhs.lat(), self.lng() + rhs.lng()) - } -} - -impl Sub for LatLng { - type Output = LatLng; - - fn sub(self, rhs: LatLng) -> Self::Output { - LatLng::new(self.lat() - rhs.lat(), self.lng() - rhs.lng()) - } -} - -impl Sub<&LatLng> for LatLng { - type Output = LatLng; - - fn sub(self, rhs: &LatLng) -> Self::Output { - LatLng::new(self.lat() - rhs.lat(), self.lng() - rhs.lng()) - } -} - -impl Sub for &LatLng { - type Output = LatLng; - - fn sub(self, rhs: LatLng) -> Self::Output { - LatLng::new(self.lat() - rhs.lat(), self.lng() - rhs.lng()) - } -} - -impl AddAssign for LatLng { - fn add_assign(&mut self, rhs: LatLng) { - self.set_lat(self.lat() + rhs.lat()); - self.set_lng(self.lng() + rhs.lng()); - } -} - -impl Div for LatLng { - type Output = LatLng; - - fn div(self, rhs: f64) -> Self::Output { - LatLng::new(self.lat() / rhs, self.lng() / rhs) - } -} - -impl Div for &LatLng { - type Output = LatLng; - - fn div(self, rhs: f64) -> Self::Output { - LatLng::new(self.lat() / rhs, self.lng() / rhs) - } -} diff --git a/leaflet/src/latlng_bounds.rs b/leaflet/src/latlng_bounds.rs deleted file mode 100644 index 7ea975f..0000000 --- a/leaflet/src/latlng_bounds.rs +++ /dev/null @@ -1,21 +0,0 @@ -use wasm_bindgen::prelude::*; - -use crate::LatLng; - -#[wasm_bindgen] -extern "C" { - #[derive(Debug)] - pub type LatLngBounds; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(corner1: &LatLng, corner2: &LatLng) -> LatLngBounds; - - #[wasm_bindgen(method)] - pub fn getNorthEast(this: &LatLngBounds) -> LatLng; - - #[wasm_bindgen(method)] - pub fn getSouthWest(this: &LatLngBounds) -> LatLng; - - #[wasm_bindgen(method)] - pub fn contains(this: &LatLngBounds, latlng: &LatLng) -> bool; -} diff --git a/leaflet/src/layer.rs b/leaflet/src/layer.rs deleted file mode 100644 index e2def83..0000000 --- a/leaflet/src/layer.rs +++ /dev/null @@ -1,137 +0,0 @@ -use js_sys::Object; -use wasm_bindgen::prelude::*; -use web_sys::HtmlElement; - -use crate::evented::{LayerEvents, LeafletEventHandler, PopupEvents, TooltipEvents}; -use crate::{ - object_constructor, object_property_set, Evented, LatLng, LayerGroup, Map, Popup, Tooltip, -}; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = Object, js_name = LayerOptions)] - #[derive(Debug, Clone, PartialEq)] - pub type LayerOptions; - - #[wasm_bindgen(extends = Evented)] - #[derive(Debug, Clone, PartialEq)] - pub type Layer; - - /// [`addTo`](https://leafletjs.com/reference.html#layer-addto) - #[wasm_bindgen(method, js_name = addTo)] - pub fn addTo(this: &Layer, map: &Map) -> Layer; - - /// [`addTo`](https://leafletjs.com/reference.html#layer-addto) - #[wasm_bindgen(method, js_name = addTo)] - pub fn addToLayerGroup(this: &Layer, layerGroup: &LayerGroup) -> Layer; - - #[wasm_bindgen(method, js_name = remove)] - pub fn remove(this: &Layer) -> Layer; - - #[wasm_bindgen(method, js_name = removeFrom)] - pub fn removeFrom(this: &Layer, map: &Map) -> Layer; - - #[wasm_bindgen(method, js_name = removeFrom)] - pub fn removeFromLayerGroup(this: &Layer, map: &LayerGroup) -> Layer; - - #[wasm_bindgen(method, js_name = getPane)] - pub fn getPane(this: &Layer) -> HtmlElement; - - #[wasm_bindgen(method, js_name = getAttribution)] - pub fn getAttribution(this: &Layer) -> String; - - // Layer Popup Methods - - /// [`bindPopup`](https://leafletjs.com/reference.html#layer-bindpopup) - #[wasm_bindgen(method)] - pub fn bindPopup(this: &Layer, content: &Popup) -> Layer; - - /// [`bindPopup`](https://leafletjs.com/reference.html#layer-bindpopup) - #[wasm_bindgen(method)] - pub fn bindPopupWithOptions(this: &Layer, content: &JsValue, options: &JsValue) -> Layer; - - /// [`unbindPopup`](https://leafletjs.com/reference.html#layer-unbindpopup) - #[wasm_bindgen(method)] - pub fn unbindPopup(this: &Layer) -> Layer; - - /// [`openPopup`](https://leafletjs.com/reference.html#layer-openpopup) - #[wasm_bindgen(method)] - pub fn openPopup(this: &Layer) -> Layer; - - /// [`openPopup`](https://leafletjs.com/reference.html#layer-openpopup) - #[wasm_bindgen(method, js_name = openPopup)] - pub fn openPopupWithLatLng(this: &Layer, lat_lng: &LatLng) -> Layer; - - /// [`closePopup`](https://leafletjs.com/reference.html#layer-closepopup) - #[wasm_bindgen(method)] - pub fn closePopup(this: &Layer) -> Layer; - - /// [`togglePopup`](https://leafletjs.com/reference.html#layer-togglepopup) - #[wasm_bindgen(method)] - pub fn togglePopup(this: &Layer) -> Layer; - - /// [`isPopupOpen`](https://leafletjs.com/reference.html#layer-ispopupopen) - #[wasm_bindgen(method)] - pub fn isPopupOpen(this: &Layer) -> bool; - - /// [`setPopupContent`](https://leafletjs.com/reference.html#layer-setpopupcontent) - #[wasm_bindgen(method)] - pub fn setPopupContent(this: &Layer, content: &JsValue) -> Layer; - - /// [`getPopup`](https://leafletjs.com/reference.html#layer-getpopup) - #[wasm_bindgen(method)] - pub fn getPopup(this: &Layer) -> Popup; - - // Layer Tooltip Methods - - /// [`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; - - /// [`unbindTooltip`](https://leafletjs.com/reference.html#layer-unbindtooltip) - #[wasm_bindgen(method)] - pub fn unbindTooltip(this: &Layer) -> Layer; - - /// [`openTooltip`](https://leafletjs.com/reference.html#layer-opentooltip) - #[wasm_bindgen(method)] - pub fn openTooltip(this: &Layer, lat_lng: &LatLng) -> Layer; - - /// [`closeTooltip`](https://leafletjs.com/reference.html#layer-closetooltip) - #[wasm_bindgen(method)] - pub fn closeTooltip(this: &Layer) -> Layer; - - /// [`toggleTooltip`](https://leafletjs.com/reference.html#layer-toggletooltip) - #[wasm_bindgen(method)] - pub fn toggleTooltip(this: &Layer) -> Layer; - - /// [`isTooltipOpen`](https://leafletjs.com/reference.html#layer-istooltipopen) - #[wasm_bindgen(method)] - pub fn isTooltipOpen(this: &Layer) -> bool; - - /// [`setTooltipContent`](https://leafletjs.com/reference.html#layer-settooltipcontent) - #[wasm_bindgen(method)] - pub fn setTooltipContent(this: &Layer, content: &JsValue) -> Layer; - - /// [`getTooltip`](https://leafletjs.com/reference.html#layer-gettooltip) - #[wasm_bindgen(method)] - pub fn getTooltip(this: &Layer) -> Tooltip; -} - -impl LayerOptions { - object_constructor!(); - object_property_set!(pane, &str); - object_property_set!(attribution, &str); -} - -impl LeafletEventHandler for Layer { - fn on(&self, event: &str, callback: &JsValue) { - self.unchecked_ref::().on(event, callback); - } -} - -impl LayerEvents for Layer {} -impl PopupEvents for Layer {} -impl TooltipEvents for Layer {} diff --git a/leaflet/src/layer_control.rs b/leaflet/src/layer_control.rs deleted file mode 100644 index ec5afc1..0000000 --- a/leaflet/src/layer_control.rs +++ /dev/null @@ -1,12 +0,0 @@ -use super::Control; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[derive(Debug, Clone)] - #[wasm_bindgen(js_namespace = ["L", "control"], js_name = Layers, extends = Control)] - pub type LayerControl; - - #[wasm_bindgen(constructor)] - pub fn new(base_layers: &JsValue) -> LayerControl; -} diff --git a/leaflet/src/layer_group.rs b/leaflet/src/layer_group.rs deleted file mode 100644 index 1a1dc58..0000000 --- a/leaflet/src/layer_group.rs +++ /dev/null @@ -1,60 +0,0 @@ -use js_sys::{Array, Object}; -use wasm_bindgen::prelude::*; - -use crate::Layer; - -#[wasm_bindgen] -extern "C" { - /// [`LayerGroup`](https://leafletjs.com/reference.html#layergroup) - #[derive(Clone, Debug)] - #[wasm_bindgen(extends = Layer)] - pub type LayerGroup; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new() -> LayerGroup; - - /// [`toGeoJSON`](https://leafletjs.com/reference.html#layergroup-togeojson) - #[wasm_bindgen(method)] - pub fn toGeoJSON(this: &LayerGroup) -> JsValue; - - /// [`addLayer`](https://leafletjs.com/reference.html#layergroup-addlayer) - #[wasm_bindgen(method)] - pub fn addLayer(this: &LayerGroup, layer: &Layer) -> LayerGroup; - - /// [`removeLayer`](https://leafletjs.com/reference.html#layergroup-removelayer) - #[wasm_bindgen(method)] - pub fn removeLayer(this: &LayerGroup, layer: &Layer) -> LayerGroup; - - /// [`hasLayer`](https://leafletjs.com/reference.html#layergroup-haslayer) - #[wasm_bindgen(method)] - pub fn hasLayer(this: &LayerGroup, layer: &Layer) -> bool; - - /// [`clearLayers`](https://leafletjs.com/reference.html#layergroup-clearlayers) - #[wasm_bindgen(method)] - pub fn clearLayers(this: &LayerGroup) -> LayerGroup; - - #[wasm_bindgen(method)] - pub fn invoke(this: &LayerGroup, method_name: &str) -> LayerGroup; - - #[wasm_bindgen(method)] - pub fn eachLayer(this: &LayerGroup, callback: &Closure) -> LayerGroup; - - #[wasm_bindgen(method, js_name = eachLayer)] - pub fn eachLayerWithContext( - this: &LayerGroup, - callback: &Closure, - context: &Object, - ) -> LayerGroup; - - #[wasm_bindgen(method)] - pub fn getLayer(this: &LayerGroup, id: i32) -> Layer; - - #[wasm_bindgen(method)] - pub fn getLayers(this: &LayerGroup) -> Array; - - #[wasm_bindgen(method)] - pub fn setZIndex(this: &LayerGroup, index: f64) -> LayerGroup; - - #[wasm_bindgen(method)] - pub fn getLayerId(this: &LayerGroup, layer: &Layer) -> i32; -} diff --git a/leaflet/src/lib.rs b/leaflet/src/lib.rs deleted file mode 100644 index aaa2bef..0000000 --- a/leaflet/src/lib.rs +++ /dev/null @@ -1,140 +0,0 @@ -mod control; -mod crs; -mod div_icon; -mod div_overlay; -mod event; -mod evented; -mod feature_group; -mod geo_json; -mod grid_layer; -mod handler; -mod icon; -mod lat_lng; -mod latlng_bounds; -mod layer; -mod layer_control; -mod layer_group; -mod map; -mod marker; -mod point; -mod popup; -mod raster; -mod shapes; -mod tooltip; - -use js_sys::Array; - -pub use control::Control; -pub use crs::Crs; -pub use div_icon::{DivIcon, DivIconOptions}; -pub use div_overlay::DivOverlay; -pub use event::Event; -pub use evented::{ - DragEvents, Evented, EventedHandle, LayerEvents, MouseEvents, MoveEvents, PopupEvents, - TooltipEvents, -}; -pub use feature_group::FeatureGroup; -pub use geo_json::GeoJSON; -pub use grid_layer::{GridLayer, GridLayerOptions}; -pub use handler::Handler; -pub use icon::{Icon, IconOptions}; -pub use lat_lng::LatLng; -pub use latlng_bounds::LatLngBounds; -pub use layer::Layer; -pub use layer_group::LayerGroup; -pub use map::{ - DragEndEvent, ErrorEvent, LocateOptions, LocationEvent, Map, MapOptions, MouseEvent, - PopupEvent, TooltipEvent, -}; -pub use marker::{Marker, MarkerOptions}; -pub use point::Point; -pub use popup::{Popup, PopupOptions}; -pub use raster::{ - ImageOverlay, ImageOverlayOptions, TileLayer, TileLayerOptions, TileLayerWms, - TileLayerWmsOptions, VideoOverlay, VideoOverlayOptions, -}; -pub use shapes::{ - Circle, CircleMarker, CircleOptions, Path, PathOptions, Polygon, Polyline, PolylineOptions, - Rectangle, -}; -pub use tooltip::{Tooltip, TooltipOptions}; - -#[macro_export] -macro_rules! object_property_set { - ($a:ident, $b:ty) => { - pub fn $a(&mut self, val: $b) -> &mut Self { - let r = js_sys::Reflect::set( - self.as_ref(), - &wasm_bindgen::JsValue::from(stringify!($a)), - &wasm_bindgen::JsValue::from(val), - ); - let _ = r; - self - } - }; - ($a:ident, $b:ident, $c:ty) => { - pub fn $a(&mut self, val: $c) -> &mut Self { - let r = js_sys::Reflect::set( - self.as_ref(), - &wasm_bindgen::JsValue::from(stringify!($b)), - &wasm_bindgen::JsValue::from(val), - ); - let _ = r; - self - } - }; -} - -#[macro_export] -macro_rules! object_property_set_with { - ($a:ident, $b:ident, $c:expr) => { - pub fn $a(&mut self) -> &mut Self { - let r = js_sys::Reflect::set( - self.as_ref(), - &wasm_bindgen::JsValue::from(stringify!($b)), - &wasm_bindgen::JsValue::from($c), - ); - let _ = r; - self - } - }; -} - -#[macro_export] -macro_rules! object_constructor { - () => { - #[allow(clippy::new_without_default)] - pub fn new() -> Self { - #[allow(unused_mut)] - let mut r = JsCast::unchecked_into(Object::new()); - r - } - }; -} - -#[allow(clippy::from_over_into)] -impl Into for (LatLng, LatLng) { - fn into(self) -> LatLngBounds { - LatLngBounds::new(&self.0, &self.1) - } -} - -pub fn to_lat_lng_array + Clone>(lat_lngs: &[T]) -> Array { - let array = Array::new(); - for lat_lng in lat_lngs.iter().cloned() { - array.push(&lat_lng.into()); - } - array -} - -impl From<(u32, u32)> for Point { - fn from((x, y): (u32, u32)) -> Point { - Point::new(x as f64, y as f64) - } -} - -impl From<(f64, f64)> for Point { - fn from((x, y): (f64, f64)) -> Point { - Point::new(x, y) - } -} diff --git a/leaflet/src/map/events.rs b/leaflet/src/map/events.rs deleted file mode 100644 index f2e7557..0000000 --- a/leaflet/src/map/events.rs +++ /dev/null @@ -1,252 +0,0 @@ -use crate::evented::LeafletEventHandler; -use crate::{Event, LatLng, LocationEvent, Point, Popup, PopupEvents, Tooltip, TooltipEvents}; -use wasm_bindgen::prelude::*; - -use super::Map; - -#[wasm_bindgen] -extern "C" { - /// Mouse Event - #[wasm_bindgen (extends = Event, js_name = MouseEvent)] - #[derive(Debug, Clone, Eq, PartialEq)] - pub type MouseEvent; - - #[wasm_bindgen(constructor)] - pub fn new() -> MouseEvent; - - #[wasm_bindgen(method, getter, js_name = latlng)] - pub fn latlng(this: &MouseEvent) -> LatLng; - - #[wasm_bindgen(method, setter, js_name = latlng)] - pub fn setLatlng(this: &MouseEvent, value: &LatLng) -> MouseEvent; - - #[wasm_bindgen(method, getter, js_name = layerPoint)] - pub fn layerPoint(this: &MouseEvent) -> Point; - - #[wasm_bindgen(method, setter, js_name = layerPoint)] - pub fn setLayerPoint(this: &MouseEvent, value: &Point) -> MouseEvent; - - #[wasm_bindgen(method, getter, js_name = containerPoint)] - pub fn containerPoint(this: &crate::map::events::MouseEvent) -> Point; - - #[wasm_bindgen(method, setter, js_name = containerPoint)] - pub fn setContainerPoint(this: &MouseEvent, value: &Point) -> MouseEvent; - - #[wasm_bindgen(method, getter, js_name = originalEvent)] - pub fn originalEvent(this: &MouseEvent) -> web_sys::MouseEvent; - - #[wasm_bindgen(method, setter, js_name = originalEvent)] - pub fn setOriginalEvent( - this: &MouseEvent, - value: &web_sys::MouseEvent, - ) -> crate::map::events::MouseEvent; - - /// Error Event - #[wasm_bindgen (extends = Event, js_name = ErrorEvent)] - #[derive(Debug, Clone, Eq, PartialEq)] - pub type ErrorEvent; - - #[wasm_bindgen(constructor)] - pub fn new() -> ErrorEvent; - - #[wasm_bindgen(method, getter, js_name = message)] - pub fn message(this: &ErrorEvent) -> String; - - #[wasm_bindgen(method, setter, js_name = message)] - pub fn setMessage(this: &ErrorEvent, value: &str); - - #[wasm_bindgen(method, getter, js_name = code)] - pub fn code(this: &ErrorEvent) -> i32; - - #[wasm_bindgen(method, setter, js_name = code)] - pub fn setCode(this: &ErrorEvent, value: i32); - - /// Drag End Event - #[wasm_bindgen (extends = Event, js_name = DragEndEvent)] - #[derive(Debug, Clone, Eq, PartialEq)] - pub type DragEndEvent; - - #[wasm_bindgen(constructor)] - pub fn new() -> DragEndEvent; - - /// The distance in pixels the draggable element was moved by. - #[wasm_bindgen(method, getter, js_name = distance)] - pub fn distance(this: &DragEndEvent) -> f64; - - #[wasm_bindgen(method, setter, js_name = distance)] - pub fn setDistance(this: &DragEndEvent, value: f64); - - /// Reset Event - #[wasm_bindgen (extends = Event, js_name = ResetEvent)] - #[derive(Debug, Clone, Eq, PartialEq)] - pub type ResetEvent; - - #[wasm_bindgen(constructor)] - pub fn new() -> ResetEvent; - - #[wasm_bindgen(method, getter, js_name = oldSize)] - pub fn oldSize(this: &ResetEvent) -> Point; - - #[wasm_bindgen(method, setter, js_name = oldSize)] - pub fn setOldSize(this: &ResetEvent, value: &Point); - - #[wasm_bindgen(method, getter, js_name = newSize)] - pub fn newSize(this: &ResetEvent) -> Point; - - #[wasm_bindgen(method, setter, js_name = newSize)] - pub fn setNewSize(this: &ResetEvent, value: &Point); - - /// Popup Event - #[wasm_bindgen(extends = Event, js_name = PopupEvent)] - #[derive(Debug, Clone, Eq, PartialEq)] - pub type PopupEvent; - - #[wasm_bindgen(constructor)] - pub fn new() -> PopupEvent; - - #[wasm_bindgen(method, getter, js_name = popup)] - pub fn popup(this: &PopupEvent) -> Popup; - - #[wasm_bindgen(method, setter, js_name = popup)] - pub fn setPopup(this: &PopupEvent, value: &Popup); - - /// Tooltip Event - #[wasm_bindgen(extends = Event, js_name = TooltipEvent)] - #[derive(Debug, Clone, Eq, PartialEq)] - pub type TooltipEvent; - - #[wasm_bindgen(constructor)] - pub fn new() -> TooltipEvent; - - #[wasm_bindgen(method, getter, js_name = tooltip)] - pub fn tooltip(this: &TooltipEvent) -> Popup; - - #[wasm_bindgen(method, setter, js_name = tooltip)] - pub fn setTooltip(this: &TooltipEvent, value: &Tooltip); -} - -impl Map { - pub fn on_zoom_levels_change(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("zoomlevelschange", &closure.into_js_value()); - } - - pub fn on_resize(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("resize", &closure.into_js_value()); - } - - pub fn on_view_reset(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("viewreset", &closure.into_js_value()); - } - - pub fn on_load(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("load", &closure.into_js_value()); - } - - pub fn on_unload(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("unload", &closure.into_js_value()); - } - - pub fn on_zoom(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("zoom", &closure.into_js_value()); - } - - pub fn on_zoom_start(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("zoomstart", &closure.into_js_value()); - } - - pub fn on_zoom_end(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("zoomend", &closure.into_js_value()); - } - - pub fn on_move(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("move", &closure.into_js_value()); - } - - pub fn on_move_start(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("movestart", &closure.into_js_value()); - } - - pub fn on_move_end(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("moveend", &closure.into_js_value()); - } - - pub fn on_location_found(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("locationfound", &closure.into_js_value()); - } - - pub fn on_location_error(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("locationerror", &closure.into_js_value()); - } - - pub fn on_popup_open(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("popupopen", &closure.into_js_value()); - } - - pub fn on_popup_close(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("popupclose", &closure.into_js_value()); - } - - pub fn on_mouse_click(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("click", &closure.into_js_value()); - } - - pub fn on_mouse_double_click(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("dblclick", &closure.into_js_value()); - } - - pub fn on_mouse_context_menu(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("contextmenu", &closure.into_js_value()); - } - - pub fn on_mouse_move(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("mousemove", &closure.into_js_value()); - } - - pub fn on_mouse_over(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("mouseover", &closure.into_js_value()); - } - - pub fn on_mouse_out(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("mouseout", &closure.into_js_value()); - } - - pub fn on_mouse_down(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("mousedown", &closure.into_js_value()); - } - - pub fn on_mouse_up(&self, callback: Box) { - let closure = Closure::wrap(callback); - self.on("mouseup", &closure.into_js_value()); - } -} - -impl LeafletEventHandler for Map { - fn on(&self, event: &str, callback: &JsValue) { - self.obj.on(event, callback); - } -} - -impl TooltipEvents for Map {} -impl PopupEvents for Map {} diff --git a/leaflet/src/map/geolocation.rs b/leaflet/src/map/geolocation.rs deleted file mode 100644 index c3fbec5..0000000 --- a/leaflet/src/map/geolocation.rs +++ /dev/null @@ -1,117 +0,0 @@ -use js_sys::{Object, Reflect}; -use wasm_bindgen::prelude::*; - -use crate::{object_constructor, Map}; - -#[wasm_bindgen] -extern "C" { - - #[wasm_bindgen (extends = Object , js_name = LocateOptions)] - #[derive(Debug, Clone, Eq, PartialEq)] - pub type LocateOptions; - - #[wasm_bindgen(method, js_name = locate)] - pub fn locate(this: &Map) -> Map; - - /// Tries to locate the user using the Geolocation API, firing a - /// locationfound event with location data on success or a `locationerror` - /// event on failure, and optionally sets the map view to the user's - /// location with respect to detection accuracy (or to the world view if - /// geolocation failed). Note that, if your page doesn't use HTTPS, this - /// method will fail in modern browsers (Chrome 50 and newer) - /// See `LocateOptions` for more details. - #[wasm_bindgen(method, js_name = locate)] - pub fn locateWithOptions(this: &Map, options: &LocateOptions) -> Map; - - /// Stops watching location previously initiated by map.locate({watch: true}) - /// and aborts resetting the map view if map.locate was called with {setView: true}. - #[wasm_bindgen(method, js_name = stopLocate)] - pub fn stopLocate(this: &Map) -> Map; -} - -impl LocateOptions { - object_constructor!(); - - /// If true, starts continuous watching of location changes (instead of detecting it once) - /// using W3C watchPosition method. You can later stop watching using map.stopLocate() method. - /// - /// [Leaflet Documentation](https://leafletjs.com/reference.html#locate-options-watch) - pub fn watch(&mut self, val: bool) -> &mut Self { - let r = Reflect::set(self.as_ref(), &JsValue::from("watch"), &JsValue::from(val)); - let _ = r; - self - } - - /// If true, automatically sets the map view to the user location with respect to - /// detection accuracy, or to world view if geolocation failed. - /// - /// [Leaflet Documentation](https://leafletjs.com/reference.html#locate-options-setView) - pub fn set_view(&mut self, val: bool) -> &mut Self { - let r = Reflect::set( - self.as_ref(), - &JsValue::from("setView"), - &JsValue::from(val), - ); - let _ = r; - self - } - - /// The maximum zoom for automatic view setting when using setView option. - /// - /// [Leaflet Documentation](https://leafletjs.com/reference.html#locate-options-maxZoom) - pub fn max_zoom(&mut self, val: f64) -> &mut Self { - let r = Reflect::set( - self.as_ref(), - &JsValue::from("maxZoom"), - &JsValue::from(val), - ); - let _ = r; - self - } - - /// Number of milliseconds to wait for a response from geolocation before firing a `locationerror` event. - /// - /// [Leaflet Documentation](https://leafletjs.com/reference.html#locate-options-timeout) - pub fn timeout(&mut self, val: f64) -> &mut Self { - let r = Reflect::set( - self.as_ref(), - &JsValue::from("timeout"), - &JsValue::from(val), - ); - let _ = r; - self - } - - /// Maximum age of detected location. If less than this amount of milliseconds passed since - /// last geolocation response, locate will return a cached location. - /// - /// [Leaflet Documentation](https://leafletjs.com/reference.html#locate-options-maximumAge) - pub fn maximum_age(&mut self, val: f64) -> &mut Self { - let r = Reflect::set( - self.as_ref(), - &JsValue::from("maximumAge"), - &JsValue::from(val), - ); - let _ = r; - self - } - - /// Enables high accuracy, see (description in the W3C spec)[https://w3c.github.io/geolocation-api/#enablehighaccuracy-member]. - /// - /// [Leaflet Documentation](https://leafletjs.com/reference.html#locate-options-enableHighAccuracy) - pub fn enable_high_accuracy(&mut self, val: bool) -> &mut Self { - let r = Reflect::set( - self.as_ref(), - &JsValue::from("enableHighAccuracy"), - &JsValue::from(val), - ); - let _ = r; - self - } -} - -impl Default for LocateOptions { - fn default() -> Self { - LocateOptions::new() - } -} diff --git a/leaflet/src/map/location_event.rs b/leaflet/src/map/location_event.rs deleted file mode 100644 index 2092441..0000000 --- a/leaflet/src/map/location_event.rs +++ /dev/null @@ -1,60 +0,0 @@ -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; - - #[wasm_bindgen(method, getter, js_name = latlng)] - pub fn latlng(this: &LocationEvent) -> LatLng; - - #[wasm_bindgen(method, setter,js_name = latlng)] - pub fn setLatlng(this: &LocationEvent, lat_lng: &LatLng); - - #[wasm_bindgen(method, getter, js_name = bounds)] - pub fn bounds(this: &LocationEvent) -> LatLngBounds; - - #[wasm_bindgen(method, setter,js_name = bounds)] - pub fn setBounds(this: &LocationEvent, value: &LatLngBounds); - - #[wasm_bindgen(method, getter, js_name = accuracy)] - pub fn accuracy(this: &LocationEvent) -> f64; - - #[wasm_bindgen(method, setter,js_name = accuracy)] - pub fn setAccuracy(this: &LocationEvent, value: f64); - - #[wasm_bindgen(method, getter, js_name = altitude)] - pub fn altitude(this: &LocationEvent) -> f64; - - #[wasm_bindgen(method, setter,js_name = altitude)] - pub fn setAltitude(this: &LocationEvent, value: f64); - - #[wasm_bindgen(method, getter, js_name = altitudeAccuracy)] - pub fn altitudeAccuracy(this: &LocationEvent) -> f64; - - #[wasm_bindgen(method, setter,js_name = altitudeAccuracy)] - pub fn setAltitudeAccuracy(this: &LocationEvent, value: f64); - - #[wasm_bindgen(method, getter, js_name = heading)] - pub fn heading(this: &LocationEvent) -> f64; - - #[wasm_bindgen(method, setter,js_name = heading)] - pub fn setHeading(this: &LocationEvent, value: f64); - - #[wasm_bindgen(method, getter, js_name = speed)] - pub fn speed(this: &LocationEvent) -> f64; - - #[wasm_bindgen(method, setter,js_name = speed)] - pub fn setSpeed(this: &LocationEvent, value: f64); - - #[wasm_bindgen(method, getter, js_name = timestamp)] - pub fn timestamp(this: &LocationEvent) -> f64; - - #[wasm_bindgen(method, setter,js_name = timestamp)] - pub fn setTimestamp(this: &LocationEvent, value: f64); -} diff --git a/leaflet/src/map/mod.rs b/leaflet/src/map/mod.rs deleted file mode 100644 index d583b95..0000000 --- a/leaflet/src/map/mod.rs +++ /dev/null @@ -1,306 +0,0 @@ -mod events; -mod geolocation; -mod location_event; -mod other; - -use js_sys::{Array, Object}; -use wasm_bindgen::prelude::*; -use web_sys::HtmlElement; - -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 other::*; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = Object , js_name = MapOptions)] - #[derive(Debug, Clone, Eq, PartialEq)] - pub type MapOptions; - - #[wasm_bindgen(extends=Evented)] - #[derive(Debug, Clone)] - pub type Map; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(id: &str, options: &MapOptions) -> Map; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn newWithElement(el: &HtmlElement, options: &MapOptions) -> Map; - - // Methods for Layers and Controls - #[wasm_bindgen(method, js_name = addControl)] - pub fn addControl(this: &Map, control: &Control) -> Map; - - #[wasm_bindgen(method, js_name = removeControl)] - pub fn removeControl(this: &Map, control: &Control) -> Map; - - #[wasm_bindgen(method, js_name = addLayer)] - pub fn addLayer(this: &Map, layer: &Layer) -> Map; - - #[wasm_bindgen(method, js_name = removeLayer)] - pub fn removeLayer(this: &Map, layer: &Layer) -> Map; - - #[wasm_bindgen(method, js_name = hasLayer)] - pub fn hasLayer(this: &Map, layer: &Layer) -> bool; - - #[wasm_bindgen(method, js_name = eachLayer)] - pub fn eachLayer(this: &Map, for_each: &dyn Fn(Layer)) -> Map; - - #[wasm_bindgen(method, js_name = eachLayer)] - pub fn eachLayerWithContext(this: &Map, for_each: &dyn Fn(Layer), context: &JsValue) -> Map; - - #[wasm_bindgen(method, js_name = openPopup)] - pub fn openPopup(this: &Map, popup: &Popup) -> Map; - - #[wasm_bindgen(method, js_name = openPopup)] - pub fn openPopupWithContent(this: &Map, content: &JsValue, lat_lng: &LatLng) -> Map; - - #[wasm_bindgen(method, js_name = openPopup)] - pub fn openPopupWithContentAndOptions( - this: &Map, - content: &JsValue, - lat_lng: &LatLng, - options: &JsValue, - ) -> Map; - - #[wasm_bindgen(method, js_name = closePopup)] - pub fn closePopup(this: &Map, popup: &Popup) -> Map; - - #[wasm_bindgen(method, js_name = openTooltip)] - pub fn openTooltip(this: &Map, tooltip: &Tooltip) -> Map; - - #[wasm_bindgen(method, js_name = openTooltip)] - pub fn openTooltipWithContent(this: &Map, content: &JsValue, lat_lng: &LatLng) -> Map; - - #[wasm_bindgen(method, js_name = openTooltip)] - pub fn openTooltipWithContentAndOptions( - this: &Map, - content: &JsValue, - lat_lng: &LatLng, - options: &JsValue, - ) -> Map; - - #[wasm_bindgen(method, js_name = closeTooltip)] - pub fn closeTooltip(this: &Map, tooltip: &Tooltip) -> Map; - - // Methods for modifying map state - - #[wasm_bindgen(method)] - pub fn setView(this: &Map, center: &LatLng, zoom: f64) -> Map; - - #[wasm_bindgen(method, js_name = setView)] - pub fn setViewWithOptions(this: &Map, center: &LatLng, zoom: f64, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn getBounds(this: &Map) -> LatLngBounds; - - #[wasm_bindgen(method)] - pub fn getCenter(this: &Map) -> LatLng; - - #[wasm_bindgen(method)] - pub fn getZoom(this: &Map) -> f64; - - #[wasm_bindgen(method)] - pub fn getZoomScale(this: &Map, toZoom: f64, fromZoom: f64) -> f64; - - #[wasm_bindgen(method)] - pub fn setZoom(this: &Map, zoom: f64) -> Map; - - #[wasm_bindgen(method, js_name = setZoom)] - pub fn setZoomWithOptions(this: &Map, zoom: f64, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn zoomIn(this: &Map, delta: f64) -> Map; - - #[wasm_bindgen(method, js_name = zoomIn)] - pub fn zoomInWithOptions(this: &Map, delta: f64, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn zoomOut(this: &Map, delta: f64); - - #[wasm_bindgen(method, js_name = zoomOut)] - pub fn zoomOutWithOptions(this: &Map, delta: f64, options: &JsValue) -> Map; - - #[wasm_bindgen(method, js_name = setZoomAround)] - pub fn setZoomAroundLatLng(this: &Map, latlng: &LatLng, zoom: f64) -> Map; - - #[wasm_bindgen(method, js_name = setZoomAround)] - pub fn setZoomAroundLatLngWithOptions( - this: &Map, - latlng: &LatLng, - zoom: f64, - options: &JsValue, - ) -> Map; - - #[wasm_bindgen(method, js_name = setZoomAround)] - pub fn setZoomAroundPoint(this: &Map, offset: &Point, zoom: f64) -> Map; - - #[wasm_bindgen(method, js_name = setZoomAround)] - pub fn setZoomAroundPointWithOptions( - this: &Map, - offset: &Point, - zoom: f64, - options: &JsValue, - ) -> Map; - - #[wasm_bindgen(method)] - pub fn fitBounds(this: &Map, bounds: &LatLngBounds) -> Map; - - #[wasm_bindgen(method, js_name = fitBounds)] - pub fn fitBoundsWithOptions(this: &Map, bounds: &LatLngBounds, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn fitWorld(this: &Map) -> Map; - - #[wasm_bindgen(method, js_name = fitWorld)] - pub fn fitWorldWithOptions(this: &Map, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn panTo(this: &Map, lat_lng: &LatLng) -> Map; - - #[wasm_bindgen(method, js_name = panTo)] - pub fn panToWithOptions(this: &Map, lat_lng: &LatLng, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn panBy(this: &Map, point: &Point) -> Map; - - #[wasm_bindgen(method, js_name = panBy)] - pub fn panByWithOptions(this: &Map, point: &Point, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn flyTo(this: &Map, lat_lng: &LatLng, zoom: f64) -> Map; - - #[wasm_bindgen(method, js_name = flyTo)] - pub fn flyToWithOptions(this: &Map, latlng: &LatLng, zoom: f64, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn flyToBounds(this: &Map, bounds: &LatLngBounds) -> Map; - - #[wasm_bindgen(method, js_name = flyToBounds)] - pub fn flyToBoundsWithOptions(this: &Map, bounds: &LatLngBounds, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn setMaxBounds(this: &Map, bounds: &LatLngBounds) -> Map; - - #[wasm_bindgen(method)] - pub fn setMinZoom(this: &Map, zoom: f64) -> Map; - - #[wasm_bindgen(method)] - pub fn setMaxZoom(this: &Map, zoom: f64) -> Map; - - /// [`getMaxZoom`](https://leafletjs.com/reference-1.7.1.html#map-getmaxzoom) - #[wasm_bindgen(method)] - pub fn getMaxZoom(this: &Map) -> f64; - - #[wasm_bindgen(method)] - pub fn panInsideBounds(this: &Map, bounds: &LatLngBounds) -> Map; - - #[wasm_bindgen(method, js_name = panInsideBounds)] - pub fn panInsideBoundsWithOptions(this: &Map, bounds: &LatLngBounds, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn panInside(this: &Map, latlng: &LatLng) -> Map; - - #[wasm_bindgen(method, js_name = panInside)] - pub fn panInsideWithOptions(this: &Map, latlng: &LatLng, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn invalidateSize(this: &Map, animate: bool) -> Map; - - #[wasm_bindgen(method, js_name = invalidateSize)] - pub fn invalidateSizeWithOptions(this: &Map, options: &JsValue) -> Map; - - #[wasm_bindgen(method)] - pub fn stop(this: &Map) -> Map; - - #[wasm_bindgen(method)] - pub fn project(this: &Map, point: &LatLng) -> Point; - - #[wasm_bindgen(method)] - pub fn unproject(this: &Map, point: &Point) -> LatLng; - - #[wasm_bindgen(method, js_name = project)] - pub fn project_with_zoom(this: &Map, point: &LatLng, zoom: f64) -> Point; - - #[wasm_bindgen(method, js_name = unproject)] - pub fn unproject_with_zoom(this: &Map, point: &Point, zoom: f64) -> LatLng; - - #[wasm_bindgen(method)] - pub fn distance(this: &Map, latlng1: &LatLng, latlng2: &LatLng) -> f64; - - #[wasm_bindgen(method)] - pub fn latLngToContainerPoint(this: &Map, latlng: &LatLng) -> Point; - - #[wasm_bindgen(method)] - pub fn containerPointToLatLng(this: &Map, point: &Point) -> LatLng; - - #[wasm_bindgen(method)] - pub fn layerPointToLatLng(this: &Map, point: &Point) -> LatLng; - - #[wasm_bindgen(method)] - pub fn latLngToLayerPoint(this: &Map, latlng: &LatLng) -> Point; -} - -impl MapOptions { - object_constructor!(); - // Options - object_property_set!(prefer_canvas, preferCanvas, bool); - // Control options - object_property_set!(attribution_control, attributionControl, bool); - object_property_set!(zoom_control, zoomControl, bool); - // Interaction Options - object_property_set!(close_popup_on_click, closePopupOnClick, bool); - object_property_set!(box_zoom, boxZoom, bool); - object_property_set!(double_click_zoom, doubleClickZoom, JsValue); - object_property_set!(dragging, bool); - object_property_set!(zoom_snap, zoomSnap, f64); - object_property_set!(zoom_delta, zoomDelta, f64); - object_property_set!(track_resize, trackResize, bool); - // Panning Inertia Options - object_property_set!(inertia, bool); - object_property_set!(inertia_deceleration, inertiaDeceleration, f64); - object_property_set!(inertia_max_speed, inertiaMaxSpeed, f64); - object_property_set!(ease_linearity, easeLinearity, f64); - object_property_set!(world_copy_jump, worldCopyJump, bool); - object_property_set!(max_bounds_viscosity, maxBoundsViscosity, f64); - // Keyboard Navigation Options - object_property_set!(keyboard, bool); - object_property_set!(keyboard_pan_delta, keyboardPanDelta, f64); - // Mouse wheel options - object_property_set!(scroll_wheel_zoom, scrollWheelZoom, bool); - object_property_set_with!(scroll_wheel_zoom_center, scrollWheelZoom, "center"); - object_property_set!(wheel_debounce_time, wheelDebounceTime, f64); - object_property_set!(wheel_px_per_zoom_level, wheelPxPerZoomLevel, f64); - // Touch interaction options - object_property_set!(tap_hold, tapHold, bool); - object_property_set!(tap_tolerance, tapTolerance, f64); - object_property_set!(touch_zoom, touchZoom, bool); - object_property_set_with!(touch_zoom_center, touchZoom, "center"); - object_property_set!(bounce_at_zoom_limits, bounceAtZoomLimits, bool); - // Map State Options - object_property_set!(crs, &JsValue); - object_property_set!(center, &LatLng); - object_property_set!(zoom, f64); - object_property_set!(min_zoom, minZoom, f64); - object_property_set!(max_zoom, maxZoom, f64); - object_property_set!(layers, &Array); - object_property_set!(max_bounds, maxBounds, &LatLngBounds); - object_property_set!(renderer, &JsValue); - // Animation Options - object_property_set!(zoom_animation, zoomAnimation, bool); - object_property_set!(zoom_animation_threshold, zoomAnimationThreshold, f64); - object_property_set!(fade_animation, fadeAnimation, bool); - object_property_set!(marker_zoom_animation, markerZoomAnimation, bool); - object_property_set!(transform3d_limit, transform3DLimit, f64); -} - -impl Default for MapOptions { - fn default() -> Self { - MapOptions::new() - } -} diff --git a/leaflet/src/map/other.rs b/leaflet/src/map/other.rs deleted file mode 100644 index 4111314..0000000 --- a/leaflet/src/map/other.rs +++ /dev/null @@ -1,40 +0,0 @@ -use js_sys::Object; -use wasm_bindgen::prelude::*; -use web_sys::HtmlElement; - -use crate::Map; - -#[wasm_bindgen] -extern "C" { - - #[wasm_bindgen(method, js_name = addHandler)] - pub fn add_handler(this: &Map, name: &str, handler_class: &Closure) -> Map; - - #[wasm_bindgen(method, js_name = remove)] - pub fn remove(this: &Map) -> Map; - - #[wasm_bindgen(method, js_name = createPane)] - pub fn create_pane(this: &Map, name: &str, container: &HtmlElement) -> HtmlElement; - - #[wasm_bindgen(method, js_name = getPane)] - pub fn get_pane(this: &Map, pane: &HtmlElement) -> HtmlElement; - - #[wasm_bindgen(method, js_name = getPane)] - pub fn get_pane_by_name(this: &Map, name: &str) -> HtmlElement; - - #[wasm_bindgen(method, js_name = getPanes)] - pub fn get_panes(this: &Map) -> Object; - - #[wasm_bindgen(method, js_name = getContainer)] - pub fn get_container(this: &Map) -> HtmlElement; - - #[wasm_bindgen(method, js_name = whenReady)] - pub fn when_ready(this: &Map, callback: &Closure) -> Map; - - #[wasm_bindgen(method, js_name = whenReady)] - pub fn when_ready_with_context( - this: &Map, - callback: &Closure, - context: &JsValue, - ) -> Map; -} diff --git a/leaflet/src/marker.rs b/leaflet/src/marker.rs deleted file mode 100644 index d48669e..0000000 --- a/leaflet/src/marker.rs +++ /dev/null @@ -1,115 +0,0 @@ -use crate::evented::{ - DragEvents, LeafletEventHandler, MouseEvents, MoveEvents, PopupEvents, TooltipEvents, -}; -use crate::{ - object_constructor, object_property_set, Evented, Handler, Icon, LatLng, Layer, LayerEvents, - Point, -}; -use js_sys::Object; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = Object, js_name = MarkerOptions)] - #[derive(Debug, Clone)] - pub type MarkerOptions; - - // Marker - #[derive(Debug, Clone, PartialEq)] - #[wasm_bindgen(extends = Layer)] - pub type Marker; - - // [`Marker`](https://leafletjs.com/reference.html#marker-l-marker) - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(lat_lng: &LatLng) -> Marker; - - // [`Marker`](https://leafletjs.com/reference.html#marker-l-marker) - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn newWithOptions(lat_lng: &LatLng, options: &MarkerOptions) -> Marker; - - /// ['setIcon'](https://leafletjs.com/reference.html#marker-seticon) - #[wasm_bindgen(method)] - pub fn setIcon(this: &Marker, icon: &Icon); - - /// ['setIcon'](https://leafletjs.com/reference.html#marker-setopacity) - #[wasm_bindgen(method)] - pub fn setOpacity(this: &Marker, value: f64); - - /// ['getLatLng'](https://leafletjs.com/reference.html#marker-getlatlng) - #[wasm_bindgen(method)] - pub fn getLatLng(this: &Marker) -> LatLng; - - /// ['setLatLng'](https://leafletjs.com/reference.html#marker-setlatlng) - #[wasm_bindgen(method)] - pub fn setLatLng(this: &Marker, latlng: &LatLng); - - /// ['dragging'](https://leafletjs.com/reference.html#marker-dragging) - #[wasm_bindgen(method, getter)] - pub fn dragging(this: &Marker) -> Handler; - - #[wasm_bindgen(method)] - pub fn update(this: &Marker) -> Marker; - - #[wasm_bindgen(method)] - pub fn setZIndexOffset(this: &Marker, offset: f64) -> Marker; -} - -impl MarkerOptions { - object_constructor!(); - // [`icon`](https://leafletjs.com/reference.html#marker-icon) - object_property_set!(icon, Icon); - // ['keyboard'](https://leafletjs.com/reference.html#marker-keyboard) - object_property_set!(keyboard, bool); - // ['title'](https://leafletjs.com/reference.html#marker-title) - object_property_set!(title, &str); - // ['alt'](https://leafletjs.com/reference.html#marker-alt) - object_property_set!(alt, &str); - // ['zIndexOffset'](https://leafletjs.com/reference.html#marker-zindexoffset) - object_property_set!(z_index_offset, zIndexOffset, f64); - // ['opacity'](https://leafletjs.com/reference.html#marker-opacity) - object_property_set!(opacity, f64); - // ['riseOnHover'](https://leafletjs.com/reference.html#marker-riseonhover) - object_property_set!(rise_on_hover, riseOnHover, bool); - // ['riseOffset'](https://leafletjs.com/reference.html#marker-riseoffset) - object_property_set!(rise_offset, riseOffset, f64); - // ['pane'](https://leafletjs.com/reference.html#marker-pane) - object_property_set!(pane, &str); - // ['shadowPane'](https://leafletjs.com/reference.html#marker-shadowpane) - object_property_set!(shadow_pane, shadowPane, &str); - // ['bubblingMouseEvents'](https://leafletjs.com/reference.html#marker-bubblingmouseevents) - object_property_set!(bubbling_mouse_events, bubblingMouseEvents, bool); - // Draggable marker options - // ['draggable'](https://leafletjs.com/reference.html#marker-draggable) - object_property_set!(draggable, bool); - // ['autoPan'](https://leafletjs.com/reference.html#marker-autopan) - object_property_set!(auto_pan, autoPan, bool); - // ['autoPanPadding'](https://leafletjs.com/reference.html#marker-autopanpadding) - object_property_set!(auto_pan_padding, autoPanPadding, Point); - // ['autoPanSpeed'](https://leafletjs.com/reference.html#marker-autopanspeed) - object_property_set!(auto_pan_speed, autoPanSpeed, f64); - // Interactive layer - // ['interactive'](https://leafletjs.com/reference.html#marker-interactive) - object_property_set!(interactive, bool); - // Layer - // ['attribution'](https://leafletjs.com/reference.html#marker-attribution) - object_property_set!(attribution, &str); -} - -impl Default for MarkerOptions { - fn default() -> Self { - Self::new() - } -} - -impl LeafletEventHandler for Marker { - fn on(&self, event: &str, callback: &JsValue) { - self.unchecked_ref::().on(event, callback); - } -} - -impl MoveEvents for Marker {} -impl MouseEvents for Marker {} -impl DragEvents for Marker {} -impl LayerEvents for Marker {} -impl PopupEvents for Marker {} -impl TooltipEvents for Marker {} diff --git a/leaflet/src/point.rs b/leaflet/src/point.rs deleted file mode 100644 index 7d5cb6a..0000000 --- a/leaflet/src/point.rs +++ /dev/null @@ -1,55 +0,0 @@ -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[derive(Debug)] - pub type Point; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(x: f64, y: f64) -> Point; - - #[wasm_bindgen(method, getter)] - pub fn x(this: &Point) -> f64; - - #[wasm_bindgen(method, getter)] - pub fn y(this: &Point) -> f64; - - #[wasm_bindgen(method)] - pub fn add(this: &Point, other: &Point) -> Point; - - #[wasm_bindgen(method)] - pub fn subtract(this: &Point, other: &Point) -> Point; - - #[wasm_bindgen(method)] - pub fn multiplyBy(this: &Point, scalar: f64) -> Point; - - #[wasm_bindgen(method)] - pub fn divideBy(this: &Point, scalar: f64) -> Point; - - #[wasm_bindgen(method)] - pub fn scaleBy(this: &Point, other: &Point) -> Point; - - #[wasm_bindgen(method)] - pub fn unscaleByTo(this: &Point, other: &Point) -> Point; - - #[wasm_bindgen(method)] - pub fn round(this: &Point) -> Point; - - #[wasm_bindgen(method)] - pub fn floor(this: &Point) -> Point; - - #[wasm_bindgen(method)] - pub fn ceil(this: &Point) -> Point; - - #[wasm_bindgen(method)] - pub fn trunc(this: &Point) -> bool; - - #[wasm_bindgen(method)] - pub fn equals(this: &Point, other: &Point) -> bool; - - #[wasm_bindgen(method)] - pub fn contains(this: &Point, other: &Point) -> f64; - - #[wasm_bindgen(method)] - pub fn distanceTo(this: &Point, other: &Point) -> f64; -} \ No newline at end of file diff --git a/leaflet/src/popup.rs b/leaflet/src/popup.rs deleted file mode 100644 index d438b4c..0000000 --- a/leaflet/src/popup.rs +++ /dev/null @@ -1,55 +0,0 @@ -use js_sys::Object; -use wasm_bindgen::prelude::*; - -use crate::{object_constructor, object_property_set, DivOverlay, LatLng, Layer, Point}; - -#[wasm_bindgen] -extern "C" { - // Popup - - # [wasm_bindgen (extends = Object , js_name = PopupOptions)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type PopupOptions; - - /// [`Popup`](https://leafletjs.com/reference.html#popup) - #[derive(Debug, Clone)] - #[wasm_bindgen(extends = DivOverlay)] - pub type Popup; - - /// [`L.popup`](https://leafletjs.com/reference.html#popup-l-popup) - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(options: &PopupOptions, layer: Option<&Layer>) -> Popup; - - /// [`L.popup`](/// [`L.popup`](https://leafletjs.com/reference.html#popup-l-popup)) - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn newWithLatLng(lat_lng: &LatLng, options: &PopupOptions) -> Popup; -} - -impl PopupOptions { - object_constructor!(); - object_property_set!(pane, &str); - object_property_set!(offset, Point); - object_property_set!(min_width, minWidth, f64); - object_property_set!(max_width, maxWidth, f64); - 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, autoPanPadding, Point); - object_property_set!(keep_in_view, keepInView, bool); - object_property_set!(close_button, closeButton, bool); - object_property_set!(auto_close, autoClose, bool); - object_property_set!(close_on_escape_key, closeOnEscapeKey, bool); - object_property_set!(close_on_click, closeOnClick, bool); - object_property_set!(class_name, className, &str); -} - -impl Default for PopupOptions { - fn default() -> Self { - Self::new() - } -} diff --git a/leaflet/src/raster/image_overlay.rs b/leaflet/src/raster/image_overlay.rs deleted file mode 100644 index d57fb39..0000000 --- a/leaflet/src/raster/image_overlay.rs +++ /dev/null @@ -1,47 +0,0 @@ -use crate::{object_constructor, object_property_set, LatLngBounds, Layer}; -use js_sys::Object; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[derive(Debug, Clone)] - #[wasm_bindgen(extends = Object, js_name = ImageOverlayOptions)] - pub type ImageOverlayOptions; - - #[wasm_bindgen(extends = Layer, js_name = ImageOverlay, js_namespace = L)] - #[derive(Debug, Clone)] - pub type ImageOverlay; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(image_url: &str, bounds: &LatLngBounds) -> ImageOverlay; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new_with_options( - image_url: &str, - bounds: &LatLngBounds, - options: &ImageOverlayOptions, - ) -> ImageOverlay; -} - -impl ImageOverlayOptions { - object_constructor!(); - object_property_set!(opacity, f64); - object_property_set!(alt, &str); - object_property_set!(interactive, bool); - object_property_set!(cross_origin, crossOrigin, &str); - object_property_set!(cross_origin_toggle, crossOrigin, bool); - object_property_set!(error_overlay_url, errorOverlayUrl, &str); - object_property_set!(z_index, zIndex, f64); - object_property_set!(class_name, className, &str); - // Interactive layer - object_property_set!(bubbling_mouse_events, bubblingMouseEvents, bool); - // Layer options - object_property_set!(pane, &str); - object_property_set!(attribution, &str); -} - -impl Default for ImageOverlayOptions { - fn default() -> Self { - ImageOverlayOptions::new() - } -} diff --git a/leaflet/src/raster/mod.rs b/leaflet/src/raster/mod.rs deleted file mode 100644 index 1f79e05..0000000 --- a/leaflet/src/raster/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -mod image_overlay; -mod tile_layer; -mod tile_layer_wms; -mod video_overlay; - -pub use image_overlay::{ImageOverlay, ImageOverlayOptions}; -pub use tile_layer::{TileLayer, TileLayerOptions}; -pub use tile_layer_wms::{TileLayerWms, TileLayerWmsOptions}; -pub use video_overlay::{VideoOverlay, VideoOverlayOptions}; diff --git a/leaflet/src/raster/tile_layer.rs b/leaflet/src/raster/tile_layer.rs deleted file mode 100644 index 257c300..0000000 --- a/leaflet/src/raster/tile_layer.rs +++ /dev/null @@ -1,74 +0,0 @@ -use js_sys::{Function, Object}; -use wasm_bindgen::prelude::*; -use web_sys::HtmlElement; - -use crate::{object_constructor, object_property_set, GridLayer, LatLng, LatLngBounds, Point}; - -#[wasm_bindgen] -extern "C" { - - # [wasm_bindgen (extends = Object , js_name = TileLayerOptions)] - #[derive(Debug, Clone, PartialEq, Eq)] - #[wasm_bindgen(extends = GridLayer)] - pub type TileLayerOptions; - - #[derive(Debug, Clone, PartialEq)] - #[wasm_bindgen(extends = GridLayer)] - pub type TileLayer; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(url_template: &str) -> TileLayer; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new_options(url_template: &str, options: &TileLayerOptions) -> TileLayer; - - #[wasm_bindgen(method, js_name = setUrl)] - pub fn setUrl(this: &TileLayer, url: &str, no_redraw: Option) -> TileLayer; - - #[wasm_bindgen(method, js_name = getTileUrl)] - pub fn getTileUrl(this: &TileLayer, coords: &LatLng) -> String; - - #[wasm_bindgen(method, js_name = createTile)] - pub fn createTile(this: &TileLayer, lat_long: &LatLng) -> HtmlElement; - - #[wasm_bindgen(method, js_name = createTile)] - pub fn createTileWithDone(this: &TileLayer, lat_long: &LatLng, done: &Function) -> HtmlElement; -} - -impl TileLayerOptions { - object_constructor!(); - // TileLayerOptions - object_property_set!(min_zoom, minZoom, f64); - object_property_set!(max_zoom, maxZoom, f64); - object_property_set!(subdomains, bool); - object_property_set!(error_tile_url, errorTileUrl, &str); - object_property_set!(zoom_offset, zoomOffset, f64); - object_property_set!(tms, bool); - object_property_set!(zoom_reverse, zoomReverse, bool); - object_property_set!(detect_retina, detectRetina, bool); - object_property_set!(cross_origin, crossOrigin, &str); - object_property_set!(referrer_policy, referrerPolicy, &str); - // GridLayerOptions - object_property_set!(tile_size, tileSize, u32); - object_property_set!(tile_size_with_point, tileSize, Point); - object_property_set!(opacity, opacity, f64); - object_property_set!(update_when_idle, updateWhenIdle, bool); - object_property_set!(update_when_zooming, updateWhenZooming, bool); - object_property_set!(update_interval, updateInterval, f64); - object_property_set!(z_index, zIndex, f64); - object_property_set!(bounds, bounds, LatLngBounds); - object_property_set!(max_native_zoom, maxNativeZoom, f64); - object_property_set!(min_native_zoom, minNativeZoom, f64); - object_property_set!(no_wrap, noWrap, bool); - object_property_set!(pane, &str); - object_property_set!(class_name, className, &str); - object_property_set!(keep_buffer, keepBuffer, u32); - // LayerOptions - object_property_set!(attribution, &str); -} - -impl Default for TileLayerOptions { - fn default() -> Self { - TileLayerOptions::new() - } -} diff --git a/leaflet/src/raster/tile_layer_wms.rs b/leaflet/src/raster/tile_layer_wms.rs deleted file mode 100644 index 20b2b0e..0000000 --- a/leaflet/src/raster/tile_layer_wms.rs +++ /dev/null @@ -1,89 +0,0 @@ -use js_sys::{Function, Object}; -use wasm_bindgen::prelude::*; -use web_sys::HtmlElement; - -use crate::{ - object_constructor, object_property_set, Crs, GridLayer, LatLng, LatLngBounds, Point, TileLayer, -}; - -#[wasm_bindgen] -extern "C" { - - #[wasm_bindgen (extends = Object , js_name = TileLayerWmsOptions)] - #[derive(Debug, Clone, PartialEq, Eq)] - #[wasm_bindgen(extends = TileLayer)] - pub type TileLayerWmsOptions; - - #[derive(Debug, Clone, PartialEq)] - #[wasm_bindgen(extends = TileLayer,js_namespace = ["L", "tileLayer"], js_name = "TileLayerWMS")] - pub type TileLayerWms; - - #[wasm_bindgen(js_namespace = ["L", "tileLayer"], js_name = "wms")] - fn new_wms(url_template: &str) -> TileLayerWms; - - #[wasm_bindgen(js_namespace = ["L", "tileLayer"], js_name = "wms")] - fn new_wms_options(url_template: &str, options: &TileLayerWmsOptions) -> TileLayerWms; - - #[wasm_bindgen(method, js_name = setParams)] - pub fn setParams( - this: &TileLayer, - params: &TileLayerWmsOptions, - no_redraw: Option, - ) -> TileLayerWms; -} - -impl TileLayerWmsOptions { - object_constructor!(); - // TileLayerWmsOptions - object_property_set!(layers, layers, &str); - object_property_set!(styles, styles, &str); - object_property_set!(format, format, &str); - object_property_set!(transparent, transparent, bool); - object_property_set!(version, version, &str); - object_property_set!(crs, crs, Crs); - object_property_set!(uppercase, uppercase, Crs); - // TileLayerOptions - object_property_set!(min_zoom, minZoom, f64); - object_property_set!(max_zoom, maxZoom, f64); - object_property_set!(subdomains, bool); - object_property_set!(error_tile_url, errorTileUrl, &str); - object_property_set!(zoom_offset, zoomOffset, f64); - object_property_set!(tms, bool); - object_property_set!(zoom_reverse, zoomReverse, bool); - object_property_set!(detect_retina, detectRetina, bool); - object_property_set!(cross_origin, crossOrigin, &str); - object_property_set!(referrer_policy, referrerPolicy, &str); - // GridLayerOptions - object_property_set!(tile_size, tileSize, u32); - object_property_set!(tile_size_with_point, tileSize, Point); - object_property_set!(opacity, opacity, f64); - object_property_set!(update_when_idle, updateWhenIdle, bool); - object_property_set!(update_when_zooming, updateWhenZooming, bool); - object_property_set!(update_interval, updateInterval, f64); - object_property_set!(z_index, zIndex, f64); - object_property_set!(bounds, bounds, LatLngBounds); - object_property_set!(max_native_zoom, maxNativeZoom, f64); - object_property_set!(min_native_zoom, minNativeZoom, f64); - object_property_set!(no_wrap, noWrap, bool); - object_property_set!(pane, &str); - object_property_set!(class_name, className, &str); - object_property_set!(keep_buffer, keepBuffer, u32); - // LayerOptions - object_property_set!(attribution, &str); -} - -impl TileLayerWms { - pub fn new(url_template: &str) -> TileLayerWms { - new_wms(url_template) - } - - pub fn new_options(url_template: &str, options: &TileLayerWmsOptions) -> TileLayerWms { - new_wms_options(url_template, options) - } -} - -impl Default for TileLayerWmsOptions { - fn default() -> Self { - TileLayerWmsOptions::new() - } -} diff --git a/leaflet/src/raster/video_overlay.rs b/leaflet/src/raster/video_overlay.rs deleted file mode 100644 index 8cd0f12..0000000 --- a/leaflet/src/raster/video_overlay.rs +++ /dev/null @@ -1,58 +0,0 @@ -use crate::{object_constructor, object_property_set, ImageOverlay, LatLngBounds, Layer}; -use js_sys::Object; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - #[derive(Debug, Clone)] - #[wasm_bindgen(extends = Object, js_name = ImageOverlayOptions)] - pub type VideoOverlayOptions; - - #[wasm_bindgen(extends = ImageOverlay, js_name = ImageOverlay, js_namespace = L)] - #[derive(Debug, Clone)] - pub type VideoOverlay; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(image_url: &str, bounds: &LatLngBounds) -> VideoOverlay; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new_with_options( - image_url: &str, - bounds: &LatLngBounds, - options: &VideoOverlayOptions, - ) -> VideoOverlay; -} - -impl VideoOverlayOptions { - object_constructor!(); - object_property_set!(opacity, f64); - object_property_set!(alt, &str); - object_property_set!(interactive, bool); - object_property_set!(cross_origin, crossOrigin, &str); - object_property_set!(cross_origin_toggle, crossOrigin, bool); - object_property_set!(error_overlay_url, errorOverlayUrl, &str); - object_property_set!(z_index, zIndex, f64); - object_property_set!(class_name, className, &str); - // Interactive layer - object_property_set!(bubbling_mouse_events, bubblingMouseEvents, bool); - // Layer options - object_property_set!(pane, &str); - object_property_set!(attribution, &str); - object_property_set!(autoplay, bool); - object_property_set!(looped, loop, bool); - object_property_set!(keep_aspect_ratio, keepAspectRatio, bool); - object_property_set!(muted, bool); - object_property_set!(plays_inline, playsInline, bool); -} - -impl Default for VideoOverlayOptions { - fn default() -> Self { - VideoOverlayOptions::new() - } -} - -impl From for Layer { - fn from(value: VideoOverlay) -> Self { - value.unchecked_into() - } -} diff --git a/leaflet/src/shapes/circle.rs b/leaflet/src/shapes/circle.rs deleted file mode 100644 index dbeddd2..0000000 --- a/leaflet/src/shapes/circle.rs +++ /dev/null @@ -1,78 +0,0 @@ -use js_sys::Object; -use std::ops::DerefMut; -use wasm_bindgen::prelude::*; - -use crate::evented::{LeafletEventHandler, MouseEvents, MoveEvents, PopupEvents, TooltipEvents}; -use crate::{ - object_constructor, object_property_set, CircleMarker, Evented, LatLng, LatLngBounds, Layer, - LayerEvents, PathOptions, -}; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = PathOptions, js_name = CircleOptions)] - #[derive(Debug, Clone, PartialEq)] - pub type CircleOptions; - - #[derive(Debug, Clone)] - #[wasm_bindgen(extends = CircleMarker)] - pub type Circle; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(latlng: &LatLng) -> Circle; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new_with_radius(latlng: &LatLng, radius: f64) -> Circle; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new_with_options(latlng: &LatLng, options: &CircleOptions) -> Circle; - - #[wasm_bindgen(method)] - pub fn setStyle(this: &Circle, options: &CircleOptions) -> Circle; - /// [`setRadius`](https://leafletjs.com/reference-1.7.1.html#circle-setradius) - #[wasm_bindgen(method)] - pub fn setRadius(this: &Circle, radius: f64); - - /// [`getRadius`](https://leafletjs.com/reference-1.7.1.html#circle-getradius) - #[wasm_bindgen(method)] - pub fn getRadius(this: &Circle) -> f64; - - /// [`getBounds`](https://leafletjs.com/reference.html#circle-getbounds) - #[wasm_bindgen(method)] - pub fn getBounds(this: &Circle) -> LatLngBounds; -} - -impl CircleOptions { - object_constructor!(); - object_property_set!(radius, f64); -} - -impl Default for CircleOptions { - fn default() -> Self { - Self::new() - } -} - -impl DerefMut for CircleOptions { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.obj - } -} - -impl From for Layer { - fn from(circle: Circle) -> Self { - circle.unchecked_into() - } -} - -impl LeafletEventHandler for Circle { - fn on(&self, event: &str, callback: &JsValue) { - self.unchecked_ref::().on(event, callback); - } -} - -impl MoveEvents for Circle {} -impl MouseEvents for Circle {} -impl LayerEvents for Circle {} -impl PopupEvents for Circle {} -impl TooltipEvents for Circle {} diff --git a/leaflet/src/shapes/circle_marker.rs b/leaflet/src/shapes/circle_marker.rs deleted file mode 100644 index 544e228..0000000 --- a/leaflet/src/shapes/circle_marker.rs +++ /dev/null @@ -1,55 +0,0 @@ -use wasm_bindgen::prelude::*; - -use crate::evented::{LeafletEventHandler, MouseEvents, MoveEvents, PopupEvents, TooltipEvents}; -use crate::{Evented, LatLng, LayerEvents, Path}; - -#[wasm_bindgen] -extern "C" { - // CircleMarker - - /// [`CirleMarker`](https://leafletjs.com/reference-1.7.1.html#circlemarker) - #[derive(Debug, Clone)] - #[wasm_bindgen(extends = Path)] - pub type CircleMarker; - - /// [`Constructor`](https://leafletjs.com/reference-1.7.1.html#circlemarker-l-circlemarker) - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(latlng: &LatLng) -> CircleMarker; - - /// [`Constructor`](https://leafletjs.com/reference-1.7.1.html#circlemarker-l-circlemarker) - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new_with_options(latlng: &LatLng, options: &JsValue) -> CircleMarker; - - /// [`toGeoJSON`](https://leafletjs.com/reference-1.7.1.html#circlemarker-togeojson) - #[wasm_bindgen(method)] - pub fn toGeoJSON(this: &CircleMarker) -> JsValue; - - /// [`setLatLng`](https://leafletjs.com/reference-1.7.1.html#circlemarker-setlanglng) - #[wasm_bindgen(method)] - pub fn setLatLng(this: &CircleMarker, latlng: &LatLng); - - /// [`getLatLng`](https://leafletjs.com/reference-1.7.1.html#circlemarker-getlatlng) - #[wasm_bindgen(method)] - pub fn getLatLng(this: &CircleMarker) -> LatLng; - - /// [`setRadius`](https://leafletjs.com/reference-1.7.1.html#circlemarker-setradius) - #[wasm_bindgen(method)] - pub fn setRadius(this: &CircleMarker, radius: f64); - - /// [`getRadius`](https://leafletjs.com/reference-1.7.1.html#circlemarker-getradius) - #[wasm_bindgen(method)] - pub fn getRadius(this: &CircleMarker) -> f64; - -} - -impl LeafletEventHandler for CircleMarker { - fn on(&self, event: &str, callback: &JsValue) { - self.unchecked_ref::().on(event, callback); - } -} - -impl MoveEvents for CircleMarker {} -impl MouseEvents for CircleMarker {} -impl LayerEvents for CircleMarker {} -impl PopupEvents for CircleMarker {} -impl TooltipEvents for CircleMarker {} diff --git a/leaflet/src/shapes/mod.rs b/leaflet/src/shapes/mod.rs deleted file mode 100644 index d73e1c6..0000000 --- a/leaflet/src/shapes/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -mod circle; -mod circle_marker; -mod path; -mod polygon; -mod polyline; -mod rectangle; - -pub use circle::{Circle, CircleOptions}; -pub use circle_marker::CircleMarker; -pub use path::{Path, PathOptions}; -pub use polygon::Polygon; -pub use polyline::{Polyline, PolylineOptions}; -pub use rectangle::Rectangle; diff --git a/leaflet/src/shapes/path.rs b/leaflet/src/shapes/path.rs deleted file mode 100644 index 40ad28e..0000000 --- a/leaflet/src/shapes/path.rs +++ /dev/null @@ -1,59 +0,0 @@ -use js_sys::Object; -use wasm_bindgen::prelude::*; - -use crate::{object_constructor, object_property_set, Layer}; - -#[wasm_bindgen] -extern "C" { - - #[wasm_bindgen(extends = Object, js_name = PathOptions)] - #[derive(Debug, Clone, PartialEq)] - pub type PathOptions; - - /// [`Path`](https://leafletjs.com/reference.html#path) - #[wasm_bindgen(extends = Layer)] - #[derive(Debug, Clone)] - pub type Path; - - /// [`redraw`](https://leafletjs.com/reference.html#path-redraw) - #[wasm_bindgen(method)] - pub fn redraw(this: &Path); - - /// [`setStyle`](https://leafletjs.com/reference.html#path-setstyle) - #[wasm_bindgen(method)] - pub fn setStyle(this: &Path, path_options: &PathOptions); - - /// [`bringToFront`](https://leafletjs.com/reference.html#path-bringtofront) - #[wasm_bindgen(method)] - pub fn bringToFront(this: &Path); - - /// [`bringToBack`](https://leafletjs.com/reference.html#path-bringtoback) - #[wasm_bindgen(method)] - pub fn bringToBack(this: &Path); -} - -impl PathOptions { - object_constructor!(); - object_property_set!(stroke, bool); - object_property_set!(color, &str); - object_property_set!(weight, f64); - object_property_set!(interactive, bool); - object_property_set!(opacity, f64); - object_property_set!(line_cap, lineCap, &str); - object_property_set!(line_join, lineJoin, &str); - object_property_set!(dash_array, dashArray, &str); - object_property_set!(dash_offset, dashOffset, &str); - object_property_set!(fill, bool); - object_property_set!(fill_color, fillColor, &str); - object_property_set!(fill_opacity, fillOpacity, f64); - object_property_set!(fill_rule, fillRule, &str); - object_property_set!(bubbling_mouse_events, bubblingMouseEvents, bool); - object_property_set!(renderer, &JsValue); - object_property_set!(class_name, className, &str); -} - -impl Default for PathOptions { - fn default() -> Self { - PathOptions::new() - } -} diff --git a/leaflet/src/shapes/polygon.rs b/leaflet/src/shapes/polygon.rs deleted file mode 100644 index c6d9f48..0000000 --- a/leaflet/src/shapes/polygon.rs +++ /dev/null @@ -1,39 +0,0 @@ -use js_sys::Array; -use wasm_bindgen::prelude::*; - -use crate::evented::{LeafletEventHandler, MouseEvents, PopupEvents, TooltipEvents}; -use crate::{Evented, LatLng, Layer, LayerEvents, Polyline, PolylineOptions}; - -#[wasm_bindgen] -extern "C" { - #[derive(Debug, Clone)] - #[wasm_bindgen(extends = Polyline)] - pub type Polygon; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(latlngs: &Array) -> Polygon; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new_with_options(latlngs: &Array, options: &PolylineOptions) -> Polygon; - - #[wasm_bindgen(method, js_name = getCenter)] - pub fn get_center(this: &Polygon) -> LatLng; -} - -/// Seems that wasmbindgen doesn't implement From for Layer -impl From for Layer { - fn from(value: Polygon) -> Self { - value.unchecked_into() - } -} - -impl LeafletEventHandler for Polygon { - fn on(&self, event: &str, callback: &JsValue) { - self.unchecked_ref::().on(event, callback); - } -} - -impl MouseEvents for Polygon {} -impl LayerEvents for Polygon {} -impl PopupEvents for Polygon {} -impl TooltipEvents for Polygon {} diff --git a/leaflet/src/shapes/polyline.rs b/leaflet/src/shapes/polyline.rs deleted file mode 100644 index 665ef28..0000000 --- a/leaflet/src/shapes/polyline.rs +++ /dev/null @@ -1,88 +0,0 @@ -use std::ops::DerefMut; - -use js_sys::{Array, Object}; -use wasm_bindgen::prelude::*; - -use crate::evented::{LeafletEventHandler, MouseEvents, PopupEvents, TooltipEvents}; -use crate::{ - object_constructor, object_property_set, Evented, LatLng, LatLngBounds, Layer, LayerEvents, - Path, PathOptions, Point, -}; - -#[wasm_bindgen] -extern "C" { - - #[wasm_bindgen(extends = PathOptions, js_name = PolylineOptions)] - #[derive(Debug, Clone, PartialEq)] - pub type PolylineOptions; - - #[wasm_bindgen(extends = Path)] - #[derive(Debug, Clone)] - pub type Polyline; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(latlngs: &Array) -> Polyline; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new_with_options(latlngs: &Array, options: &PolylineOptions) -> Polyline; - - #[wasm_bindgen(method, js_name = toGeoJSON)] - pub fn toGeoJSON(this: &Polyline, precision: f64) -> Object; - - #[wasm_bindgen(method, js_name = getLatLngs)] - pub fn getLatLngs(this: &Polyline) -> Array; - - #[wasm_bindgen(method, js_name = setLatLngs)] - pub fn setLatLngs(this: &Polyline, lat_lngs: &Array) -> Polyline; - - #[wasm_bindgen(method, js_name = isEmpty)] - pub fn isEmpty(this: &Polyline) -> bool; - - #[wasm_bindgen(method, js_name = closestLayerPoint)] - pub fn closestLayerPoint(this: &Polyline, point: &Point) -> Point; - - #[wasm_bindgen(method, js_name = getCenter)] - pub fn getCenter(this: &Polyline) -> LatLng; - - #[wasm_bindgen(method, js_name = getBounds)] - pub fn getBounds(this: &Polyline) -> LatLngBounds; - - #[wasm_bindgen(method,js_name = addLatLng)] - pub fn addLatLng(this: &Polyline, lat_lng: &LatLng) -> Polyline; -} - -impl PolylineOptions { - object_constructor!(); - object_property_set!(smooth_factor, smoothFactor, f64); - object_property_set!(no_clip, noClip, bool); -} - -impl Default for PolylineOptions { - fn default() -> Self { - Self::new() - } -} - -/// Seems that wasmbindgen doesn't implement From for Layer -impl From for Layer { - fn from(value: Polyline) -> Self { - value.unchecked_into() - } -} - -impl DerefMut for PolylineOptions { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.obj - } -} - -impl LeafletEventHandler for Polyline { - fn on(&self, event: &str, callback: &JsValue) { - self.unchecked_ref::().on(event, callback); - } -} - -impl MouseEvents for Polyline {} -impl LayerEvents for Polyline {} -impl PopupEvents for Polyline {} -impl TooltipEvents for Polyline {} diff --git a/leaflet/src/shapes/rectangle.rs b/leaflet/src/shapes/rectangle.rs deleted file mode 100644 index bfca428..0000000 --- a/leaflet/src/shapes/rectangle.rs +++ /dev/null @@ -1,33 +0,0 @@ -use wasm_bindgen::prelude::*; - -use crate::evented::{LeafletEventHandler, MouseEvents, PopupEvents, TooltipEvents}; -use crate::{Evented, LatLngBounds, LayerEvents, Polygon, PolylineOptions}; - -#[wasm_bindgen] -extern "C" { - // Rectangle - - #[derive(Debug)] - #[wasm_bindgen(extends = Polygon)] - pub type Rectangle; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new(bounds: &LatLngBounds) -> Rectangle; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn new_with_options(bounds: &LatLngBounds, options: &PolylineOptions) -> Rectangle; - - #[wasm_bindgen(method)] - pub fn setBounds(this: &Rectangle, bounds: &LatLngBounds) -> Rectangle; -} - -impl LeafletEventHandler for Rectangle { - fn on(&self, event: &str, callback: &JsValue) { - self.unchecked_ref::().on(event, callback); - } -} - -impl MouseEvents for Rectangle {} -impl LayerEvents for Rectangle {} -impl PopupEvents for Rectangle {} -impl TooltipEvents for Rectangle {} diff --git a/leaflet/src/tooltip.rs b/leaflet/src/tooltip.rs deleted file mode 100644 index 5bb9eec..0000000 --- a/leaflet/src/tooltip.rs +++ /dev/null @@ -1,51 +0,0 @@ -use js_sys::Object; -use wasm_bindgen::prelude::*; - -use crate::{object_constructor, object_property_set, DivOverlay, LatLng, Layer, Point}; - -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = Object, js_name = PopupOptions)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type TooltipOptions; - - /// [`Tooltip`](https://leafletjs.com/reference-1.7.1.html#tooltip) - #[derive(Debug, Clone)] - #[wasm_bindgen(extends = DivOverlay)] - pub type Tooltip; - - /// [`L.tooltip`](https://leafletjs.com/reference-1.7.1.html#tooltip-l-tooltip) - #[wasm_bindgen(js_namespace = L, constructor, js_name = Tooltip)] - pub fn new(options: &TooltipOptions, layer: Option<&Layer>) -> Tooltip; - - #[wasm_bindgen(constructor, js_namespace = L)] - pub fn newWithLatLng(lat_lng: &LatLng, options: &TooltipOptions) -> Tooltip; - - #[wasm_bindgen(method)] - pub fn setContent(this: &Tooltip, content: &JsValue) -> Tooltip; - - #[wasm_bindgen(method)] - pub fn getContent(this: &Tooltip) -> JsValue; - - #[wasm_bindgen(method)] - pub fn setLatLng(this: &Tooltip, latlng: &JsValue) -> Tooltip; - - #[wasm_bindgen(method)] - pub fn getLatLng(this: &Tooltip) -> LatLng; -} - -impl TooltipOptions { - object_constructor!(); - object_property_set!(pane, &str); - object_property_set!(direction, &str); - object_property_set!(offset, &Point); - object_property_set!(permanent, bool); - object_property_set!(sticky, bool); - object_property_set!(opacity, f64); -} - -impl Default for TooltipOptions { - fn default() -> Self { - Self::new() - } -} diff --git a/leptos-leaflet/src/components/circle.rs b/leptos-leaflet/src/components/circle.rs index a93c325..474fb9a 100644 --- a/leptos-leaflet/src/components/circle.rs +++ b/leptos-leaflet/src/components/circle.rs @@ -69,7 +69,7 @@ pub fn Circle( tooltip_events.setup(&circle); layer_events.setup(&circle); - circle.addTo(&map); + circle.add_to(&map); overlay_context.set_container(&circle); overlay.set_value(Some(circle)); }; @@ -79,7 +79,7 @@ pub fn Circle( move || radius.get(), move |radius, _, _| { if let Some(polygon) = overlay.get_value() { - polygon.setRadius(*radius); + polygon.set_radius(*radius); } }, false, @@ -90,8 +90,8 @@ pub fn Circle( move |stroke, _, _| { if let (Some(stroke), Some(overlay)) = (stroke, overlay.get_value()) { let mut options = CircleOptions::new(); - options.stroke(*stroke); - overlay.setStyle(&options); + options.set_stroke(*stroke); + overlay.set_style(&options); } }, false, @@ -102,8 +102,8 @@ pub fn Circle( move |color, _, _| { if let (Some(color), Some(overlay)) = (color, overlay.get_value()) { let mut options = CircleOptions::new(); - options.color(color); - overlay.setStyle(&options); + options.set_color(color); + overlay.set_style(&options); } }, false, @@ -114,8 +114,8 @@ pub fn Circle( move |color, _, _| { if let (Some(color), Some(overlay)) = (color, overlay.get_value()) { let mut options = CircleOptions::new(); - options.fill_color(color); - overlay.setStyle(&options); + options.set_fill_color(color); + overlay.set_style(&options); } }, false, @@ -126,8 +126,8 @@ pub fn Circle( move |opacity, _, _| { if let (Some(opacity), Some(overlay)) = (opacity, overlay.get_value()) { let mut options = CircleOptions::new(); - options.opacity(*opacity); - overlay.setStyle(&options); + options.set_opacity(*opacity); + overlay.set_style(&options); } }, false, @@ -138,8 +138,8 @@ pub fn Circle( move |opacity, _, _| { if let (Some(opacity), Some(overlay)) = (opacity, overlay.get_value()) { let mut options = CircleOptions::new(); - options.fill_opacity(*opacity); - overlay.setStyle(&options); + options.set_fill_opacity(*opacity); + overlay.set_style(&options); } }, false, @@ -150,8 +150,8 @@ pub fn Circle( move |weight, _, _| { if let (Some(weight), Some(overlay)) = (weight, overlay.get_value()) { let mut options = CircleOptions::new(); - options.weight(*weight); - overlay.setStyle(&options); + options.set_weight(*weight); + overlay.set_style(&options); } }, false, diff --git a/leptos-leaflet/src/components/context.rs b/leptos-leaflet/src/components/context.rs index 7b42528..39c1f5c 100644 --- a/leptos-leaflet/src/components/context.rs +++ b/leptos-leaflet/src/components/context.rs @@ -28,13 +28,19 @@ impl LeafletMapContext { pub fn add_layer + Clone>(&self, layer: &L) { let map = self.map.get_untracked().expect("Map to be available"); let layer: leaflet::Layer = layer.to_owned().into(); - layer.addTo(&map); + layer.add_to(&map); } pub fn remove_layer + Clone>(&self, layer: &L) { let map = self.map.get_untracked().expect("Map to be available"); let layer: leaflet::Layer = layer.to_owned().into(); - layer.removeFrom(&map); + layer.remove_from(&map); + } +} + +impl Default for LeafletMapContext { + fn default() -> Self { + Self::new() } } @@ -99,3 +105,9 @@ impl LeafletOverlayContainerContext { .map(|layer| layer.unchecked_into()) } } + +impl Default for LeafletOverlayContainerContext { + fn default() -> Self { + Self::new() + } +} \ No newline at end of file diff --git a/leptos-leaflet/src/components/image_overlay.rs b/leptos-leaflet/src/components/image_overlay.rs index ca04e04..b86f890 100644 --- a/leptos-leaflet/src/components/image_overlay.rs +++ b/leptos-leaflet/src/components/image_overlay.rs @@ -24,41 +24,41 @@ pub fn ImageOverlay( log!("Adding image layer: {}", url); let mut options = leaflet::ImageOverlayOptions::new(); if let Some(opacity) = opacity { - options.opacity(opacity.get_untracked()); + options.set_opacity(opacity.get_untracked()); } if let Some(alt) = &alt { - options.alt(&alt.get_untracked()); + options.set_alt(&alt.get_untracked()); } if let Some(interactive) = interactive { - options.interactive(interactive.get_untracked()); + options.set_interactive(interactive.get_untracked()); } if let Some(cross_origin) = &cross_origin { - options.cross_origin(&cross_origin.get_untracked()); + options.set_cross_origin(&cross_origin.get_untracked()); } if let Some(cross_origin_toggle) = cross_origin_toggle { - options.cross_origin_toggle(cross_origin_toggle.get_untracked()); + options.set_cross_origin_toggle(cross_origin_toggle.get_untracked()); } if let Some(error_overlay_url) = &error_overlay_url { - options.error_overlay_url(&error_overlay_url.get_untracked()); + options.set_error_overlay_url(&error_overlay_url.get_untracked()); } if let Some(z_index) = z_index { - options.z_index(z_index.get_untracked()); + options.set_z_index(z_index.get_untracked()); } if let Some(class_name) = &class_name { - options.class_name(&class_name.get_untracked()); + options.set_class_name(&class_name.get_untracked()); } if let Some(bubbling_mouse_events) = bubbling_mouse_events { - options.bubbling_mouse_events(bubbling_mouse_events.get_untracked()); + options.set_bubbling_mouse_events(bubbling_mouse_events.get_untracked()); } if let Some(pane) = &pane { - options.pane(&pane.get_untracked()); + options.set_pane(&pane.get_untracked()); } if let Some(attribution) = &attribution { - options.attribution(&attribution.get_untracked()); + options.set_attribution(&attribution.get_untracked()); } let map_layer = leaflet::ImageOverlay::new_with_options(&url, &bounds, &options); - map_layer.addTo(&map); + map_layer.add_to(&map); on_cleanup(move || { map_layer.remove(); }); diff --git a/leptos-leaflet/src/components/map_container.rs b/leptos-leaflet/src/components/map_container.rs index cafc542..1a6326a 100644 --- a/leptos-leaflet/src/components/map_container.rs +++ b/leptos-leaflet/src/components/map_container.rs @@ -56,9 +56,9 @@ pub fn MapContainer( _ = map_div.on_mount(move |map_div| { let map_div = map_div.unchecked_ref::(); let mut options = leaflet::MapOptions::new(); - options.zoom(zoom); + options.set_zoom(zoom); if let Some(center) = center { - options.center(¢er.into()); + options.set_center(¢er.into()); } let leaflet_map = Map::new(&map_div.id(), &options); @@ -72,7 +72,7 @@ pub fn MapContainer( locate_options.enable_high_accuracy(enable_high_accuracy); locate_options.set_view(set_view); locate_options.watch(watch); - leaflet_map.locateWithOptions(&locate_options); + leaflet_map.locate_with_options(&locate_options); } map_context.set_map(&leaflet_map); diff --git a/leptos-leaflet/src/components/marker.rs b/leptos-leaflet/src/components/marker.rs index b760e56..332fd37 100644 --- a/leptos-leaflet/src/components/marker.rs +++ b/leptos-leaflet/src/components/marker.rs @@ -54,7 +54,7 @@ pub fn Marker( let mut options = leaflet::MarkerOptions::new(); let drag = draggable.get_untracked(); if drag { - options.draggable(drag); + options.set_draggable(drag); } setup_layer_leaflet_option!(keyboard, options); setup_layer_leaflet_option_ref!(title, options); @@ -72,27 +72,27 @@ pub fn Marker( setup_layer_leaflet_option_ref!(attribution, options); if let Some((x, y)) = auto_pan_padding.get_untracked() { - options.auto_pan_padding(leaflet::Point::new(x, y)); + options.set_auto_pan_padding(leaflet::Point::new(x, y)); } if let Some(icon_url) = icon_url.get_untracked() { let mut icon_options = leaflet::IconOptions::new(); - icon_options.icon_url(&icon_url); + icon_options.set_icon_url(&icon_url); if let Some((x, y)) = icon_size.get_untracked() { - icon_options.icon_size(leaflet::Point::new(x, y)); + icon_options.set_icon_size(leaflet::Point::new(x, y)); } let icon = leaflet::Icon::new(&icon_options); - options.icon(icon); + options.set_icon(icon); } else if let Some(icon_class) = icon_class.get_untracked() { let mut icon_options = leaflet::DivIconOptions::new(); - icon_options.class_name(&icon_class); + icon_options.set_class_name(&icon_class); if let Some((x, y)) = icon_size.get_untracked() { - icon_options.icon_size(leaflet::Point::new(x, y)); + icon_options.set_icon_size(leaflet::Point::new(x, y)); } let icon = leaflet::DivIcon::new(&icon_options); - options.icon(icon.into()); + options.set_icon(icon.into()); } let marker = - leaflet::Marker::newWithOptions(&position.get_untracked().into(), &options); + leaflet::Marker::new_with_options(&position.get_untracked().into(), &options); mouse_events.setup(&marker); move_events.setup(&marker); @@ -101,7 +101,7 @@ pub fn Marker( tooltip_events.setup(&marker); layer_events.setup(&marker); - marker.addTo(&map); + marker.add_to(&map); overlay_context.set_container(&marker); overlay.set_value(Some(marker)); }; @@ -111,7 +111,7 @@ pub fn Marker( move || position_tracking.get(), move |position_tracking, _, _| { if let Some(marker) = overlay.get_value() { - marker.setLatLng(&position_tracking.into()); + marker.set_lat_lng(&position_tracking.into()); } }, false, @@ -122,7 +122,7 @@ pub fn Marker( move |opacity, _, _| { overlay.get_value().and_then(|marker| { opacity.map(|opacity| { - marker.setOpacity(opacity); + marker.set_opacity(opacity); }) }); }, diff --git a/leptos-leaflet/src/components/mod.rs b/leptos-leaflet/src/components/mod.rs index bf26b0b..a856269 100644 --- a/leptos-leaflet/src/components/mod.rs +++ b/leptos-leaflet/src/components/mod.rs @@ -10,6 +10,7 @@ mod polyline; mod popup; mod position; mod tile_layer; +mod tile_layer_wms; mod tooltip; mod video_overlay; @@ -27,6 +28,7 @@ pub use polyline::Polyline; pub use popup::Popup; pub use position::Position; pub use tile_layer::TileLayer; +pub use tile_layer_wms::TileLayerWms; pub use tooltip::Tooltip; #[macro_export] @@ -48,24 +50,28 @@ macro_rules! effect_update_on_change { #[macro_export] macro_rules! effect_update_on_change_ref { ($class:ty, $option_class:ty, $name:ident, $value:expr) => { - create_effect(move |_| { - use leaflet; - let overlay_context = - leptos::use_context::().expect("overlay context"); - if let (Some(layer), Some(setting)) = (overlay_context.container::<$class>(), &$value) { - let mut options = <$option_class>::new(); - options.$name(&setting.get()); - layer.setStyle(&options); - } - }); + $crate::paste! { + create_effect(move |_| { + use leaflet; + let overlay_context = + leptos::use_context::().expect("overlay context"); + if let (Some(layer), Some(setting)) = (overlay_context.container::<$class>(), &$value) { + let mut options = <$option_class>::new(); + options.[](&setting.get()); + layer.set_style(&options); + } + }); + } }; } #[macro_export] macro_rules! setup_layer_option { ($name:ident, $options:ident) => { - if let Some($name) = $name { - $options.$name($name.get_untracked()); + $crate::paste! { + if let Some($name) = $name { + $options.[]($name.get_untracked()); + } } }; } @@ -73,8 +79,10 @@ macro_rules! setup_layer_option { #[macro_export] macro_rules! setup_layer_option_ref { ($name:ident, $options:ident) => { - if let Some($name) = &$name { - $options.$name(&$name.get_untracked()); + $crate::paste! { + if let Some($name) = &$name { + $options.[](&$name.get_untracked()); + } } }; } @@ -82,8 +90,10 @@ macro_rules! setup_layer_option_ref { #[macro_export] macro_rules! setup_layer_option_str { ($name:ident, $options:ident) => { - if let Some($name) = &$name { - $options.$name(&format!("{}", &$name.get_untracked())); + $crate::paste! { + if let Some($name) = &$name { + $options.[](&format!("{}", &$name.get_untracked())); + } } }; } @@ -91,8 +101,10 @@ macro_rules! setup_layer_option_str { #[macro_export] macro_rules! setup_layer_leaflet_option { ($name:ident, $options:ident) => { - if let Some($name) = $name.get_untracked() { - $options.$name($name); + $crate::paste! { + if let Some($name) = $name.get_untracked() { + $options.[]($name); + } } }; } @@ -100,8 +112,10 @@ macro_rules! setup_layer_leaflet_option { #[macro_export] macro_rules! setup_layer_leaflet_option_ref { ($name:ident, $options:ident) => { - if let Some($name) = $name.get_untracked() { - $options.$name($name.as_ref()); + $crate::paste! { + if let Some($name) = $name.get_untracked() { + $options.[]($name.as_ref()); + } } }; } diff --git a/leptos-leaflet/src/components/polygon.rs b/leptos-leaflet/src/components/polygon.rs index 43ce440..b7abf37 100644 --- a/leptos-leaflet/src/components/polygon.rs +++ b/leptos-leaflet/src/components/polygon.rs @@ -78,7 +78,7 @@ pub fn Polygon( popup_events.setup(&polygon); tooltip_events.setup(&polygon); - polygon.addTo(&map); + polygon.add_to(&map); update_overlay_context(&polygon); overlay.set_value(Some(polygon)); } @@ -89,7 +89,7 @@ pub fn Polygon( move |pos, _, _| { if let Some(polygon) = overlay.get_value() { let lat_lngs = to_lat_lng_array(pos); - polygon.setLatLngs(&lat_lngs); + polygon.set_lat_lngs(&lat_lngs); } }, false, @@ -100,8 +100,8 @@ pub fn Polygon( move |stroke, _, _| { if let (Some(stroke), Some(overlay)) = (stroke, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.stroke(*stroke); - overlay.setStyle(&options.into()) + options.set_stroke(*stroke); + overlay.set_style(&options.into()) } }, false, @@ -112,8 +112,8 @@ pub fn Polygon( move |color, _, _| { if let (Some(color), Some(overlay)) = (color, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.color(color); - overlay.setStyle(&options.into()) + options.set_color(color); + overlay.set_style(&options.into()) } }, false, @@ -124,8 +124,8 @@ pub fn Polygon( move |color, _, _| { if let (Some(color), Some(overlay)) = (color, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.fill_color(color); - overlay.setStyle(&options.into()) + options.set_fill_color(color); + overlay.set_style(&options.into()) } }, false, @@ -136,8 +136,8 @@ pub fn Polygon( move |opacity, _, _| { if let (Some(opacity), Some(overlay)) = (opacity, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.opacity(*opacity); - overlay.setStyle(&options.into()) + options.set_opacity(*opacity); + overlay.set_style(&options.into()) } }, false, @@ -148,8 +148,8 @@ pub fn Polygon( move |opacity, _, _| { if let (Some(opacity), Some(overlay)) = (opacity, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.fill_opacity(*opacity); - overlay.setStyle(&options.into()) + options.set_fill_opacity(*opacity); + overlay.set_style(&options.into()) } }, false, @@ -160,8 +160,8 @@ pub fn Polygon( move |weight, _, _| { if let (Some(weight), Some(overlay)) = (weight, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.weight(*weight); - overlay.setStyle(&options.into()) + options.set_weight(*weight); + overlay.set_style(&options.into()) } }, false, @@ -172,8 +172,8 @@ pub fn Polygon( move |smooth_factor, _, _| { if let (Some(smooth_factor), Some(overlay)) = (smooth_factor, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.smooth_factor(*smooth_factor); - overlay.setStyle(&options.into()) + options.set_smooth_factor(*smooth_factor); + overlay.set_style(&options.into()) } }, false, diff --git a/leptos-leaflet/src/components/polyline.rs b/leptos-leaflet/src/components/polyline.rs index b74acdd..793468c 100644 --- a/leptos-leaflet/src/components/polyline.rs +++ b/leptos-leaflet/src/components/polyline.rs @@ -75,7 +75,7 @@ pub fn Polyline( popup_events.setup(&polyline); tooltip_events.setup(&polyline); - polyline.addTo(&map); + polyline.add_to(&map); update_overlay_context(&polyline); overlay.set_value(Some(polyline)); } @@ -86,7 +86,7 @@ pub fn Polyline( move |pos, _, _| { if let Some(polygon) = overlay.get_value() { let lat_lngs = to_lat_lng_array(pos); - polygon.setLatLngs(&lat_lngs); + polygon.set_lat_lngs(&lat_lngs); } }, false, @@ -97,8 +97,8 @@ pub fn Polyline( move |stroke, _, _| { if let (Some(stroke), Some(overlay)) = (stroke, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.stroke(*stroke); - overlay.setStyle(&options.into()) + options.set_stroke(*stroke); + overlay.set_style(&options.into()) } }, false, @@ -109,8 +109,8 @@ pub fn Polyline( move |color, _, _| { if let (Some(color), Some(overlay)) = (color, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.color(color); - overlay.setStyle(&options.into()) + options.set_color(color); + overlay.set_style(&options.into()) } }, false, @@ -121,8 +121,8 @@ pub fn Polyline( move |color, _, _| { if let (Some(color), Some(overlay)) = (color, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.fill_color(color); - overlay.setStyle(&options.into()) + options.set_fill_color(color); + overlay.set_style(&options.into()) } }, false, @@ -133,8 +133,8 @@ pub fn Polyline( move |opacity, _, _| { if let (Some(opacity), Some(overlay)) = (opacity, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.opacity(*opacity); - overlay.setStyle(&options.into()) + options.set_opacity(*opacity); + overlay.set_style(&options.into()) } }, false, @@ -145,8 +145,8 @@ pub fn Polyline( move |opacity, _, _| { if let (Some(opacity), Some(overlay)) = (opacity, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.fill_opacity(*opacity); - overlay.setStyle(&options.into()) + options.set_fill_opacity(*opacity); + overlay.set_style(&options.into()) } }, false, @@ -157,8 +157,8 @@ pub fn Polyline( move |weight, _, _| { if let (Some(weight), Some(overlay)) = (weight, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.weight(*weight); - overlay.setStyle(&options.into()) + options.set_weight(*weight); + overlay.set_style(&options.into()) } }, false, @@ -169,8 +169,8 @@ pub fn Polyline( move |smooth_factor, _, _| { if let (Some(smooth_factor), Some(overlay)) = (smooth_factor, overlay.get_value()) { let mut options = PolylineOptions::new(); - options.smooth_factor(*smooth_factor); - overlay.setStyle(&options.into()) + options.set_smooth_factor(*smooth_factor); + overlay.set_style(&options.into()) } }, false, diff --git a/leptos-leaflet/src/components/popup.rs b/leptos-leaflet/src/components/popup.rs index f410458..4d0bc6f 100644 --- a/leptos-leaflet/src/components/popup.rs +++ b/leptos-leaflet/src/components/popup.rs @@ -34,50 +34,50 @@ pub fn Popup( let inner_content = content; let mut options = leaflet::PopupOptions::default(); if let Some(pane) = &pane { - options.pane(&pane.get_untracked()); + options.set_pane(&pane.get_untracked()); } if let Some(offset) = offset { - options.offset(leaflet::Point::from(offset.get_untracked())); + options.set_offset(leaflet::Point::from(offset.get_untracked())); } if let Some(min_width) = min_width { - options.min_width(min_width.get_untracked()); + options.set_min_width(min_width.get_untracked()); } if let Some(max_width) = max_width { - options.max_width(max_width.get_untracked()); + options.set_max_width(max_width.get_untracked()); } if let Some(auto_pan) = auto_pan { - options.auto_pan(auto_pan.get_untracked()); + options.set_auto_pan(auto_pan.get_untracked()); } if let Some(auto_pan_padding_top_left) = auto_pan_padding_top_left { - options.auto_pan_padding_top_left(leaflet::Point::from( + options.set_auto_pan_padding_top_left(leaflet::Point::from( auto_pan_padding_top_left.get_untracked(), )); } if let Some(auto_pan_padding_bottom_right) = auto_pan_padding_bottom_right { - options.auto_pan_padding_bottom_right(leaflet::Point::from( + options.set_auto_pan_padding_bottom_right(leaflet::Point::from( auto_pan_padding_bottom_right.get_untracked(), )); } if let Some(auto_pan_padding) = auto_pan_padding { - options.auto_pan_padding(leaflet::Point::from(auto_pan_padding.get_untracked())); + options.set_auto_pan_padding(leaflet::Point::from(auto_pan_padding.get_untracked())); } if let Some(keep_in_view) = keep_in_view { - options.keep_in_view(keep_in_view.get_untracked()); + options.set_keep_in_view(keep_in_view.get_untracked()); } if let Some(close_button) = close_button { - options.close_button(close_button.get_untracked()); + options.set_close_button(close_button.get_untracked()); } if let Some(auto_close) = auto_close { - options.auto_close(auto_close.get_untracked()); + options.set_auto_close(auto_close.get_untracked()); } if let Some(close_on_escape_key) = close_on_escape_key { - options.close_on_escape_key(close_on_escape_key.get_untracked()); + options.set_close_on_escape_key(close_on_escape_key.get_untracked()); } if let Some(close_on_click) = close_on_click { - options.close_on_click(close_on_click.get_untracked()); + options.set_close_on_click(close_on_click.get_untracked()); } if let Some(class_name) = &class_name { - options.class_name(&class_name.get_untracked()); + options.set_class_name(&class_name.get_untracked()); } if let Some(overlay_context) = overlay_context { if let (Some(marker), Some(_map)) = ( @@ -87,18 +87,19 @@ pub fn Popup( let popup = leaflet::Popup::new(&options, Some(marker.unchecked_ref())); let content = inner_content.get_untracked().expect("content ref"); let html_view: &JsValue = content.unchecked_ref(); - popup.setContent(html_view); - marker.bindPopup(&popup); + popup.set_content(html_view); + marker.bind_popup(&popup); on_cleanup(move || { popup.remove(); }); } } else if let Some(map) = map_context.map() { - let popup = leaflet::Popup::newWithLatLng(&position.get_untracked().into(), &options); + let popup = + leaflet::Popup::new_with_lat_lng(&position.get_untracked().into(), &options); let content = inner_content.get_untracked().expect("content ref"); let html_view: &JsValue = content.unchecked_ref(); - popup.setContent(html_view); - popup.openOn(&map); + popup.set_content(html_view); + popup.open_on(&map); on_cleanup(move || { popup.remove(); }); diff --git a/leptos-leaflet/src/components/tile_layer.rs b/leptos-leaflet/src/components/tile_layer.rs index 492221b..ad33ffd 100644 --- a/leptos-leaflet/src/components/tile_layer.rs +++ b/leptos-leaflet/src/components/tile_layer.rs @@ -13,10 +13,10 @@ pub fn TileLayer( if let Some(map) = map_context.map() { let mut options = leaflet::TileLayerOptions::default(); if attribution.is_empty() { - options.attribution(&attribution); + options.set_attribution(&attribution); } let map_layer = leaflet::TileLayer::new_options(&url, &options); - map_layer.addTo(&map); + map_layer.add_to(&map); on_cleanup(move || { map_layer.remove(); }); diff --git a/leptos-leaflet/src/components/tile_layer_wms.rs b/leptos-leaflet/src/components/tile_layer_wms.rs new file mode 100644 index 0000000..1323c13 --- /dev/null +++ b/leptos-leaflet/src/components/tile_layer_wms.rs @@ -0,0 +1,19 @@ +use leptos::*; + +use crate::components::context::LeafletMapContext; +use leaflet::TileLayerWmsOptions; + +#[component(transparent)] +pub fn TileLayerWms(#[prop(into)] url: String, options: TileLayerWmsOptions) -> impl IntoView { + let map_context = use_context::().expect("map context not found"); + + create_effect(move |_| { + if let Some(map) = map_context.map() { + let map_layer = leaflet::TileLayerWms::new_options(&url, &options); + map_layer.add_to(&map); + on_cleanup(move || { + map_layer.remove(); + }); + } + }); +} diff --git a/leptos-leaflet/src/components/tooltip.rs b/leptos-leaflet/src/components/tooltip.rs index 507c6ae..ab1dd72 100644 --- a/leptos-leaflet/src/components/tooltip.rs +++ b/leptos-leaflet/src/components/tooltip.rs @@ -20,9 +20,9 @@ pub fn Tooltip( // let content = view! {
{children()}
}; create_effect(move |_| { let mut options = leaflet::TooltipOptions::default(); - options.permanent(permanent.get_untracked()); - options.direction(&direction.get_untracked()); - options.sticky(sticky.get_untracked()); + options.set_permanent(permanent.get_untracked()); + options.set_direction(&direction.get_untracked()); + options.set_sticky(sticky.get_untracked()); if let Some(overlay_context) = overlay_context { if let (Some(layer), Some(_map)) = ( @@ -31,19 +31,19 @@ pub fn Tooltip( ) { let tooltip = leaflet::Tooltip::new(&options, Some(layer.unchecked_ref())); let content = content.get_untracked().expect("content ref"); - tooltip.setContent(content.unchecked_ref()); - layer.bindTooltip(&tooltip); + tooltip.set_content(content.unchecked_ref()); + layer.bind_tooltip(&tooltip); on_cleanup(move || { tooltip.remove(); }); } } else if let Some(map) = map_context.map() { let tooltip = - leaflet::Tooltip::newWithLatLng(&position.get_untracked().into(), &options); + leaflet::Tooltip::new_with_lat_lng(&position.get_untracked().into(), &options); let content = content.get_untracked().expect("content ref"); let html_view: &JsValue = content.unchecked_ref(); - tooltip.setContent(html_view); - tooltip.openOn(&map); + tooltip.set_content(html_view); + tooltip.open_on(&map); on_cleanup(move || { tooltip.remove(); }); diff --git a/leptos-leaflet/src/components/video_overlay.rs b/leptos-leaflet/src/components/video_overlay.rs index 13e381a..930c5a1 100644 --- a/leptos-leaflet/src/components/video_overlay.rs +++ b/leptos-leaflet/src/components/video_overlay.rs @@ -29,56 +29,56 @@ pub fn VideoOverlay( log!("Adding image layer: {}", url); let mut options = leaflet::VideoOverlayOptions::new(); if let Some(opacity) = opacity { - options.opacity(opacity.get_untracked()); + options.set_opacity(opacity.get_untracked()); } if let Some(alt) = &alt { - options.alt(&alt.get_untracked()); + options.set_alt(&alt.get_untracked()); } if let Some(interactive) = interactive { - options.interactive(interactive.get_untracked()); + options.set_interactive(interactive.get_untracked()); } if let Some(cross_origin) = &cross_origin { - options.cross_origin(&cross_origin.get_untracked()); + options.set_cross_origin(&cross_origin.get_untracked()); } if let Some(cross_origin_toggle) = cross_origin_toggle { - options.cross_origin_toggle(cross_origin_toggle.get_untracked()); + options.set_cross_origin_toggle(cross_origin_toggle.get_untracked()); } if let Some(error_overlay_url) = &error_overlay_url { - options.error_overlay_url(&error_overlay_url.get_untracked()); + options.set_error_overlay_url(&error_overlay_url.get_untracked()); } if let Some(z_index) = z_index { - options.z_index(z_index.get_untracked()); + options.set_z_index(z_index.get_untracked()); } if let Some(class_name) = &class_name { - options.class_name(&class_name.get_untracked()); + options.set_class_name(&class_name.get_untracked()); } if let Some(bubbling_mouse_events) = bubbling_mouse_events { - options.bubbling_mouse_events(bubbling_mouse_events.get_untracked()); + options.set_bubbling_mouse_events(bubbling_mouse_events.get_untracked()); } if let Some(pane) = &pane { - options.pane(&pane.get_untracked()); + options.set_pane(&pane.get_untracked()); } if let Some(attribution) = &attribution { - options.attribution(&attribution.get_untracked()); + options.set_attribution(&attribution.get_untracked()); } if let Some(autoplay) = autoplay { - options.autoplay(autoplay.get_untracked()); + options.set_autoplay(autoplay.get_untracked()); } if let Some(looped) = looped { - options.looped(looped.get_untracked()); + options.set_looped(looped.get_untracked()); } if let Some(keep_aspect_ratio) = keep_aspect_ratio { - options.keep_aspect_ratio(keep_aspect_ratio.get_untracked()); + options.set_keep_aspect_ratio(keep_aspect_ratio.get_untracked()); } if let Some(muted) = muted { - options.muted(muted.get_untracked()); + options.set_muted(muted.get_untracked()); } if let Some(plays_inline) = plays_inline { - options.plays_inline(plays_inline.get_untracked()); + options.set_plays_inline(plays_inline.get_untracked()); } let map_layer = leaflet::VideoOverlay::new_with_options(&url, &bounds, &options); - map_layer.addTo(&map); + map_layer.add_to(&map); on_cleanup(move || { map_layer.remove(); }); diff --git a/leptos-leaflet/src/lib.rs b/leptos-leaflet/src/lib.rs index d3177fd..97f0a54 100644 --- a/leptos-leaflet/src/lib.rs +++ b/leptos-leaflet/src/lib.rs @@ -4,9 +4,9 @@ pub(crate) mod core; pub use components::*; /// Leaflet re-exports -pub mod leaflet { - pub use leaflet::*; -} +pub use leaflet; + +use paste::paste; #[macro_export] macro_rules! position {