1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use js_sys::{Object, Reflect};
use wasm_bindgen::prelude::*;
use crate::{Map, object_constructor};
#[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 locate_with_options(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 stop_locate(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()
}
}