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 #[wasm_bindgen(method, js_name = addTo)]
16 pub fn add_to(this: &Layer, map: &Map) -> Layer;
17
18 #[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 #[wasm_bindgen(method, js_name = bindPopup)]
41 pub fn bind_popup(this: &Layer, content: &Popup) -> Layer;
42
43 #[wasm_bindgen(method, js_name = bindPopup)]
45 pub fn bind_popup_with_options(this: &Layer, content: &JsValue, options: &JsValue) -> Layer;
46
47 #[wasm_bindgen(method, js_name = unbindPopup)]
49 pub fn unbind_popup(this: &Layer) -> Layer;
50
51 #[wasm_bindgen(method, js_name = openPopup)]
53 pub fn open_popup(this: &Layer) -> Layer;
54
55 #[wasm_bindgen(method, js_name = openPopup)]
57 pub fn open_popup_with_lat_lng(this: &Layer, lat_lng: &LatLng) -> Layer;
58
59 #[wasm_bindgen(method, js_name = closePopup)]
61 pub fn close_popup(this: &Layer) -> Layer;
62
63 #[wasm_bindgen(method, js_name = togglePopup)]
65 pub fn toggle_popup(this: &Layer) -> Layer;
66
67 #[wasm_bindgen(method, js_name = isPopupOpen)]
69 pub fn is_popup_open(this: &Layer) -> bool;
70
71 #[wasm_bindgen(method, js_name = setPopupContent)]
73 pub fn set_popup_content(this: &Layer, content: &JsValue) -> Layer;
74
75 #[wasm_bindgen(method, js_name = getPopup)]
77 pub fn get_popup(this: &Layer) -> Popup;
78
79 #[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 #[wasm_bindgen(method, js_name = unbindTooltip)]
90 pub fn unbind_tooltip(this: &Layer) -> Layer;
91
92 #[wasm_bindgen(method, js_name = openTooltip)]
94 pub fn open_tooltip(this: &Layer, lat_lng: &LatLng) -> Layer;
95
96 #[wasm_bindgen(method, js_name = closeTooltip)]
98 pub fn close_tooltip(this: &Layer) -> Layer;
99
100 #[wasm_bindgen(method, js_name = toggleTooltip)]
102 pub fn toggle_tooltip(this: &Layer) -> Layer;
103
104 #[wasm_bindgen(method, js_name = isTooltipOpen)]
106 pub fn is_tooltip_open(this: &Layer) -> bool;
107
108 #[wasm_bindgen(method, js_name = setTooltipContent)]
110 pub fn set_tooltip_content(this: &Layer, content: &JsValue) -> Layer;
111
112 #[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 {}