leaflet/
layer.rs

1use js_sys::Object;
2use wasm_bindgen::prelude::*;
3use web_sys::HtmlElement;
4
5use crate::evented::{LayerEvents, LeafletEventHandler, PopupEvents, TooltipEvents};
6use crate::{Evented, LatLng, LayerGroup, Map, Popup, Tooltip, create_object_with_properties};
7
8#[wasm_bindgen]
9extern "C" {
10    #[wasm_bindgen(extends = Evented)]
11    #[derive(Debug, Clone, PartialEq)]
12    pub type Layer;
13
14    /// [`addTo`](https://leafletjs.com/reference.html#layer-addto)
15    #[wasm_bindgen(method, js_name = addTo)]
16    pub fn add_to(this: &Layer, map: &Map) -> Layer;
17
18    /// [`addTo`](https://leafletjs.com/reference.html#layer-addto)
19    #[wasm_bindgen(method, js_name = addTo)]
20    pub fn add_to_layer_group(this: &Layer, layerGroup: &LayerGroup) -> Layer;
21
22    #[wasm_bindgen(method, js_name = remove)]
23    pub fn remove(this: &Layer) -> Layer;
24
25    #[wasm_bindgen(method, js_name = removeFrom)]
26    pub fn remove_from(this: &Layer, map: &Map) -> Layer;
27
28    #[wasm_bindgen(method, js_name = removeFrom)]
29    pub fn remove_from_layer_group(this: &Layer, map: &LayerGroup) -> Layer;
30
31    #[wasm_bindgen(method, js_name = getPane)]
32    pub fn get_pane(this: &Layer) -> HtmlElement;
33
34    #[wasm_bindgen(method, js_name = getAttribution)]
35    pub fn get_attribution(this: &Layer) -> String;
36
37    // Layer Popup Methods
38
39    /// [`bindPopup`](https://leafletjs.com/reference.html#layer-bindpopup)
40    #[wasm_bindgen(method, js_name = bindPopup)]
41    pub fn bind_popup(this: &Layer, content: &Popup) -> Layer;
42
43    /// [`bindPopup`](https://leafletjs.com/reference.html#layer-bindpopup)
44    #[wasm_bindgen(method, js_name = bindPopup)]
45    pub fn bind_popup_with_options(this: &Layer, content: &JsValue, options: &JsValue) -> Layer;
46
47    /// [`unbindPopup`](https://leafletjs.com/reference.html#layer-unbindpopup)
48    #[wasm_bindgen(method, js_name = unbindPopup)]
49    pub fn unbind_popup(this: &Layer) -> Layer;
50
51    /// [`openPopup`](https://leafletjs.com/reference.html#layer-openpopup)
52    #[wasm_bindgen(method, js_name = openPopup)]
53    pub fn open_popup(this: &Layer) -> Layer;
54
55    /// [`openPopup`](https://leafletjs.com/reference.html#layer-openpopup)
56    #[wasm_bindgen(method, js_name = openPopup)]
57    pub fn open_popup_with_lat_lng(this: &Layer, lat_lng: &LatLng) -> Layer;
58
59    /// [`closePopup`](https://leafletjs.com/reference.html#layer-closepopup)
60    #[wasm_bindgen(method, js_name = closePopup)]
61    pub fn close_popup(this: &Layer) -> Layer;
62
63    /// [`togglePopup`](https://leafletjs.com/reference.html#layer-togglepopup)
64    #[wasm_bindgen(method, js_name = togglePopup)]
65    pub fn toggle_popup(this: &Layer) -> Layer;
66
67    /// [`isPopupOpen`](https://leafletjs.com/reference.html#layer-ispopupopen)
68    #[wasm_bindgen(method, js_name = isPopupOpen)]
69    pub fn is_popup_open(this: &Layer) -> bool;
70
71    /// [`setPopupContent`](https://leafletjs.com/reference.html#layer-setpopupcontent)
72    #[wasm_bindgen(method, js_name = setPopupContent)]
73    pub fn set_popup_content(this: &Layer, content: &JsValue) -> Layer;
74
75    /// [`getPopup`](https://leafletjs.com/reference.html#layer-getpopup)
76    #[wasm_bindgen(method, js_name = getPopup)]
77    pub fn get_popup(this: &Layer) -> Popup;
78
79    // Layer Tooltip Methods
80
81    /// [`bindTooltip`](https://leafletjs.com/reference.html#layer-bindtooltip)
82    #[wasm_bindgen(method, js_name = bindTooltip)]
83    pub fn bind_tooltip(this: &Layer, tooltip: &Tooltip) -> Layer;
84
85    #[wasm_bindgen(method, js_name = bindTooltipWithContent)]
86    pub fn bind_tooltip_with_content(this: &Layer, content: &JsValue, options: &JsValue) -> Layer;
87
88    /// [`unbindTooltip`](https://leafletjs.com/reference.html#layer-unbindtooltip)
89    #[wasm_bindgen(method, js_name = unbindTooltip)]
90    pub fn unbind_tooltip(this: &Layer) -> Layer;
91
92    /// [`openTooltip`](https://leafletjs.com/reference.html#layer-opentooltip)
93    #[wasm_bindgen(method, js_name = openTooltip)]
94    pub fn open_tooltip(this: &Layer, lat_lng: &LatLng) -> Layer;
95
96    /// [`closeTooltip`](https://leafletjs.com/reference.html#layer-closetooltip)
97    #[wasm_bindgen(method, js_name = closeTooltip)]
98    pub fn close_tooltip(this: &Layer) -> Layer;
99
100    /// [`toggleTooltip`](https://leafletjs.com/reference.html#layer-toggletooltip)
101    #[wasm_bindgen(method, js_name = toggleTooltip)]
102    pub fn toggle_tooltip(this: &Layer) -> Layer;
103
104    /// [`isTooltipOpen`](https://leafletjs.com/reference.html#layer-istooltipopen)
105    #[wasm_bindgen(method, js_name = isTooltipOpen)]
106    pub fn is_tooltip_open(this: &Layer) -> bool;
107
108    /// [`setTooltipContent`](https://leafletjs.com/reference.html#layer-settooltipcontent)
109    #[wasm_bindgen(method, js_name = setTooltipContent)]
110    pub fn set_tooltip_content(this: &Layer, content: &JsValue) -> Layer;
111
112    /// [`getTooltip`](https://leafletjs.com/reference.html#layer-gettooltip)
113    #[wasm_bindgen(method, js_name = getTooltip)]
114    pub fn get_tooltip(this: &Layer) -> Tooltip;
115}
116
117create_object_with_properties!(
118    (LayerOptions, LayerOptions),
119    (pane, pane, String),
120    (attribution, attribution, String)
121);
122
123impl LeafletEventHandler for Layer {
124    fn on(&self, event: &str, callback: &JsValue) {
125        self.unchecked_ref::<Evented>().on(event, callback);
126    }
127}
128
129impl LayerEvents for Layer {}
130impl PopupEvents for Layer {}
131impl TooltipEvents for Layer {}