1mod events;
2mod geolocation;
3mod location_event;
4mod other;
5
6use js_sys::{Array, Object};
7use wasm_bindgen::prelude::*;
8use web_sys::HtmlElement;
9
10use crate::{
11 Control, Evented, LatLng, LatLngBounds, Layer, Point, Popup, Tooltip,
12 create_object_with_properties, object_property_set_with,
13};
14pub use events::*;
15pub use geolocation::*;
16pub use location_event::*;
17
18#[wasm_bindgen]
19extern "C" {
20 #[wasm_bindgen(extends=Evented)]
21 #[derive(Debug, Clone)]
22 pub type Map;
23
24 #[wasm_bindgen(constructor, js_namespace = L, catch)]
25 pub fn new(id: &str, options: &MapOptions) -> Result<Map, JsValue>;
26
27 #[wasm_bindgen(constructor, js_namespace = L, catch)]
28 pub fn new_with_element(el: &HtmlElement, options: &MapOptions) -> Result<Map, JsValue>;
29
30 #[wasm_bindgen(method, js_name = addControl)]
32 pub fn add_control(this: &Map, control: &Control) -> Map;
33
34 #[wasm_bindgen(method, js_name = removeControl)]
35 pub fn remove_control(this: &Map, control: &Control) -> Map;
36
37 #[wasm_bindgen(method, js_name = addLayer)]
38 pub fn add_layer(this: &Map, layer: &Layer) -> Map;
39
40 #[wasm_bindgen(method, js_name = removeLayer)]
41 pub fn remove_layer(this: &Map, layer: &Layer) -> Map;
42
43 #[wasm_bindgen(method, js_name = hasLayer)]
44 pub fn has_layer(this: &Map, layer: &Layer) -> bool;
45
46 #[wasm_bindgen(method, js_name = eachLayer)]
47 pub fn each_layer(this: &Map, for_each: &dyn Fn(Layer)) -> Map;
48
49 #[wasm_bindgen(method, js_name = eachLayer)]
50 pub fn each_layer_with_context(this: &Map, for_each: &dyn Fn(Layer), context: &JsValue) -> Map;
51
52 #[wasm_bindgen(method, js_name = openPopup)]
53 pub fn open_popup(this: &Map, popup: &Popup) -> Map;
54
55 #[wasm_bindgen(method, js_name = openPopup)]
56 pub fn open_popup_with_content(this: &Map, content: &JsValue, lat_lng: &LatLng) -> Map;
57
58 #[wasm_bindgen(method, js_name = openPopup)]
59 pub fn open_popup_with_content_and_options(
60 this: &Map,
61 content: &JsValue,
62 lat_lng: &LatLng,
63 options: &JsValue,
64 ) -> Map;
65
66 #[wasm_bindgen(method, js_name = closePopup)]
67 pub fn close_popup(this: &Map, popup: &Popup) -> Map;
68
69 #[wasm_bindgen(method, js_name = openTooltip)]
70 pub fn open_tooltip(this: &Map, tooltip: &Tooltip) -> Map;
71
72 #[wasm_bindgen(method, js_name = openTooltip)]
73 pub fn open_tooltip_with_content(this: &Map, content: &JsValue, lat_lng: &LatLng) -> Map;
74
75 #[wasm_bindgen(method, js_name = openTooltip)]
76 pub fn open_tooltip_with_content_and_options(
77 this: &Map,
78 content: &JsValue,
79 lat_lng: &LatLng,
80 options: &JsValue,
81 ) -> Map;
82
83 #[wasm_bindgen(method, js_name = closeTooltip)]
84 pub fn close_tooltip(this: &Map, tooltip: &Tooltip) -> Map;
85
86 #[wasm_bindgen(method, js_name = setView)]
89 pub fn set_view(this: &Map, center: &LatLng, zoom: f64) -> Map;
90
91 #[wasm_bindgen(method, js_name = setView)]
92 pub fn set_view_with_options(this: &Map, center: &LatLng, zoom: f64, options: &JsValue) -> Map;
93
94 #[wasm_bindgen(method, js_name = getBounds)]
95 pub fn get_bounds(this: &Map) -> LatLngBounds;
96
97 #[wasm_bindgen(method, js_name = getCenter)]
98 pub fn get_center(this: &Map) -> LatLng;
99
100 #[wasm_bindgen(method, js_name = getZoom)]
101 pub fn get_zoom(this: &Map) -> f64;
102
103 #[wasm_bindgen(method, js_name = getZoomScale)]
104 pub fn get_zoom_scale(this: &Map, toZoom: f64, fromZoom: f64) -> f64;
105
106 #[wasm_bindgen(method, js_name = setZoom)]
107 pub fn set_zoom(this: &Map, zoom: f64) -> Map;
108
109 #[wasm_bindgen(method, js_name = setZoom)]
110 pub fn set_zoom_with_options(this: &Map, zoom: f64, options: &JsValue) -> Map;
111
112 #[wasm_bindgen(method, js_name = zoomIn)]
113 pub fn zoom_in(this: &Map, delta: f64) -> Map;
114
115 #[wasm_bindgen(method, js_name = zoomIn)]
116 pub fn zoom_in_with_options(this: &Map, delta: f64, options: &JsValue) -> Map;
117
118 #[wasm_bindgen(method, js_name = zoomOut)]
119 pub fn zoom_out(this: &Map, delta: f64);
120
121 #[wasm_bindgen(method, js_name = zoomOut)]
122 pub fn zoom_out_with_options(this: &Map, delta: f64, options: &JsValue) -> Map;
123
124 #[wasm_bindgen(method, js_name = setZoomAround)]
125 pub fn set_zoom_around_lat_lng(this: &Map, latlng: &LatLng, zoom: f64) -> Map;
126
127 #[wasm_bindgen(method, js_name = setZoomAround)]
128 pub fn set_zoom_around_lat_lng_with_options(
129 this: &Map,
130 latlng: &LatLng,
131 zoom: f64,
132 options: &JsValue,
133 ) -> Map;
134
135 #[wasm_bindgen(method, js_name = setZoomAround)]
136 pub fn set_zoom_around_point(this: &Map, offset: &Point, zoom: f64) -> Map;
137
138 #[wasm_bindgen(method, js_name = setZoomAround)]
139 pub fn set_zoom_around_point_with_options(
140 this: &Map,
141 offset: &Point,
142 zoom: f64,
143 options: &JsValue,
144 ) -> Map;
145
146 #[wasm_bindgen(method, js_name = "fitBounds")]
147 pub fn fit_bounds(this: &Map, bounds: &LatLngBounds) -> Map;
148
149 #[wasm_bindgen(method, js_name = fitBounds)]
150 pub fn fit_bounds_with_options(this: &Map, bounds: &LatLngBounds, options: &JsValue) -> Map;
151
152 #[wasm_bindgen(method, js_name = fitWorld)]
153 pub fn fit_world(this: &Map) -> Map;
154
155 #[wasm_bindgen(method, js_name = fitWorld)]
156 pub fn fit_world_with_options(this: &Map, options: &JsValue) -> Map;
157
158 #[wasm_bindgen(method, js_name = panTo)]
159 pub fn pan_to(this: &Map, lat_lng: &LatLng) -> Map;
160
161 #[wasm_bindgen(method, js_name = panTo)]
162 pub fn pan_to_with_options(this: &Map, lat_lng: &LatLng, options: &JsValue) -> Map;
163
164 #[wasm_bindgen(method, js_name = panBy)]
165 pub fn pan_by(this: &Map, point: &Point) -> Map;
166
167 #[wasm_bindgen(method, js_name = panBy)]
168 pub fn pan_by_with_options(this: &Map, point: &Point, options: &JsValue) -> Map;
169
170 #[wasm_bindgen(method, js_name = flyTo)]
171 pub fn fly_to(this: &Map, lat_lng: &LatLng) -> Map;
172
173 #[wasm_bindgen(method, js_name = flyTo)]
174 pub fn fly_to_with_zoom(this: &Map, lat_lng: &LatLng, zoom: f64) -> Map;
175
176 #[wasm_bindgen(method, js_name = flyTo)]
177 pub fn fly_to_with_zoom_and_options(
178 this: &Map,
179 latlng: &LatLng,
180 zoom: f64,
181 options: &JsValue,
182 ) -> Map;
183
184 #[wasm_bindgen(method, js_name = flyToBounds)]
185 pub fn fly_to_bounds(this: &Map, bounds: &LatLngBounds) -> Map;
186
187 #[wasm_bindgen(method, js_name = flyToBounds)]
188 pub fn fly_to_bounds_with_options(this: &Map, bounds: &LatLngBounds, options: &JsValue) -> Map;
189
190 #[wasm_bindgen(method, js_name = setMaxBounds)]
191 pub fn set_max_bounds(this: &Map, bounds: &LatLngBounds) -> Map;
192
193 #[wasm_bindgen(method, js_name = setMinZoom)]
194 pub fn set_min_zoom(this: &Map, zoom: f64) -> Map;
195
196 #[wasm_bindgen(method, js_name = setMaxZoom)]
197 pub fn set_max_zoom(this: &Map, zoom: f64) -> Map;
198
199 #[wasm_bindgen(method, js_name = getMaxZoom)]
201 pub fn get_max_zoom(this: &Map) -> f64;
202
203 #[wasm_bindgen(method, js_name = panInsideBounds)]
204 pub fn pan_inside_bounds(this: &Map, bounds: &LatLngBounds) -> Map;
205
206 #[wasm_bindgen(method, js_name = panInsideBounds)]
207 pub fn pan_inside_bounds_with_options(
208 this: &Map,
209 bounds: &LatLngBounds,
210 options: &JsValue,
211 ) -> Map;
212
213 #[wasm_bindgen(method, js_name = panInside)]
214 pub fn pan_inside(this: &Map, latlng: &LatLng) -> Map;
215
216 #[wasm_bindgen(method, js_name = panInside)]
217 pub fn pan_inside_with_options(this: &Map, latlng: &LatLng, options: &JsValue) -> Map;
218
219 #[wasm_bindgen(method, js_name = invalidateSize)]
220 pub fn invalidate_size(this: &Map, animate: bool) -> Map;
221
222 #[wasm_bindgen(method, js_name = invalidateSize)]
223 pub fn invalidate_size_with_options(this: &Map, options: &JsValue) -> Map;
224
225 #[wasm_bindgen(method)]
226 pub fn stop(this: &Map) -> Map;
227
228 #[wasm_bindgen(method)]
229 pub fn project(this: &Map, point: &LatLng) -> Point;
230
231 #[wasm_bindgen(method)]
232 pub fn unproject(this: &Map, point: &Point) -> LatLng;
233
234 #[wasm_bindgen(method, js_name = project)]
235 pub fn project_with_zoom(this: &Map, point: &LatLng, zoom: f64) -> Point;
236
237 #[wasm_bindgen(method, js_name = unproject)]
238 pub fn unproject_with_zoom(this: &Map, point: &Point, zoom: f64) -> LatLng;
239
240 #[wasm_bindgen(method)]
241 pub fn distance(this: &Map, latlng1: &LatLng, latlng2: &LatLng) -> f64;
242
243 #[wasm_bindgen(method, js_name = latLngToContainerPoint)]
244 pub fn lat_lng_to_container_point(this: &Map, latlng: &LatLng) -> Point;
245
246 #[wasm_bindgen(method, js_name = containerPointToLatLng)]
247 pub fn container_point_to_lat_lng(this: &Map, point: &Point) -> LatLng;
248
249 #[wasm_bindgen(method, js_name = layerPointToLatLng)]
250 pub fn layer_point_to_lat_lng(this: &Map, point: &Point) -> LatLng;
251
252 #[wasm_bindgen(method, js_name = latLngToLayerPoint)]
253 pub fn lat_lng_to_layer_point(this: &Map, latlng: &LatLng) -> Point;
254
255 #[wasm_bindgen(method, js_name = getSize)]
256 pub fn get_size(this: &Map) -> Point;
257}
258
259create_object_with_properties!(
260 (MapOptions, MapOptions),
261 (prefer_canvas, preferCanvas, bool),
263 (attribution_control, attributionControl, bool),
265 (zoom_control, zoomControl, bool),
266 (close_popup_on_click, closePopupOnClick, bool),
268 (box_zoom, boxZoom, bool),
269 (double_click_zoom, doubleClickZoom, JsValue),
270 (dragging, dragging, bool),
271 (zoom_snap, zoomSnap, f64),
272 (zoom_delta, zoomDelta, f64),
273 (track_resize, trackResize, bool),
274 (inertia, inertia, bool),
276 (inertia_deceleration, inertiaDeceleration, f64),
277 (inertia_max_speed, inertiaMaxSpeed, f64),
278 (ease_linearity, easeLinearity, f64),
279 (world_copy_jump, worldCopyJump, bool),
280 (max_bounds_viscosity, maxBoundsViscosity, f64),
281 (keyboard, keyboard, bool),
283 (keyboard_pan_delta, keyboardPanDelta, f64),
284 (scroll_wheel_zoom, scrollWheelZoom, bool),
286 (wheel_debounce_time, wheelDebounceTime, f64),
287 (wheel_px_per_zoom_level, wheelPxPerZoomLevel, f64),
288 (tap_hold, tapHold, bool),
290 (tap_tolerance, tapTolerance, f64),
291 (touch_zoom, touchZoom, bool),
292 (bounce_at_zoom_limits, bounceAtZoomLimits, bool),
293 (crs, crs, JsValue),
295 (center, center, LatLng),
296 (zoom, zoom, f64),
297 (min_zoom, minZoom, f64),
298 (max_zoom, maxZoom, f64),
299 (layers, layers, Array),
300 (max_bounds, maxBounds, LatLngBounds),
301 (renderer, renderer, JsValue),
302 (zoom_animation, zoomAnimation, bool),
304 (zoom_animation_threshold, zoomAnimationThreshold, f64),
305 (fade_animation, fadeAnimation, bool),
306 (marker_zoom_animation, markerZoomAnimation, bool),
307 (transform3d_limit, transform3DLimit, f64)
308);
309
310impl MapOptions {
311 object_property_set_with!(scroll_wheel_zoom_center, scrollWheelZoom, "center");
312 object_property_set_with!(touch_zoom_center, touchZoom, "center");
313}
314
315impl Default for MapOptions {
316 fn default() -> Self {
317 MapOptions::new()
318 }
319}