leaflet/shapes/
polyline.rs1use std::ops::DerefMut;
2
3use js_sys::{Array, Object};
4use wasm_bindgen::prelude::*;
5
6use crate::evented::{LeafletEventHandler, MouseEvents, PopupEvents, TooltipEvents};
7use crate::{
8 Evented, LatLng, LatLngBounds, Layer, LayerEvents, Path, PathOptions, Point,
9 create_object_with_properties,
10};
11
12#[wasm_bindgen]
13extern "C" {
14 #[wasm_bindgen(extends = Path)]
15 #[derive(Debug, Clone)]
16 pub type Polyline;
17
18 #[wasm_bindgen(constructor, js_namespace = L)]
19 pub fn new(latlngs: &Array) -> Polyline;
20
21 #[wasm_bindgen(constructor, js_namespace = L)]
22 pub fn new_with_options(latlngs: &Array, options: &PolylineOptions) -> Polyline;
23
24 #[wasm_bindgen(method, js_name = toGeoJSON)]
25 pub fn to_geo_json(this: &Polyline, precision: f64) -> Object;
26
27 #[wasm_bindgen(method, js_name = getLatLngs)]
28 pub fn get_lat_lngs(this: &Polyline) -> Array;
29
30 #[wasm_bindgen(method, js_name = setLatLngs)]
31 pub fn set_lat_lngs(this: &Polyline, lat_lngs: &Array) -> Polyline;
32
33 #[wasm_bindgen(method, js_name = isEmpty)]
34 pub fn is_empty(this: &Polyline) -> bool;
35
36 #[wasm_bindgen(method, js_name = closestLayerPoint)]
37 pub fn closest_layer_point(this: &Polyline, point: &Point) -> Point;
38
39 #[wasm_bindgen(method, js_name = getCenter)]
40 pub fn get_center(this: &Polyline) -> LatLng;
41
42 #[wasm_bindgen(method, js_name = getBounds)]
43 pub fn get_bounds(this: &Polyline) -> LatLngBounds;
44
45 #[wasm_bindgen(method,js_name = addLatLng)]
46 pub fn add_lat_lng(this: &Polyline, lat_lng: &LatLng) -> Polyline;
47}
48
49create_object_with_properties!(
50 (PolylineOptions, PolylineOptions, PathOptions),
51 (smooth_factor, smoothFactor, f64),
52 (no_clip, noClip, bool)
53);
54
55impl Default for PolylineOptions {
56 fn default() -> Self {
57 Self::new()
58 }
59}
60
61impl From<Polyline> for Layer {
63 fn from(value: Polyline) -> Self {
64 value.unchecked_into()
65 }
66}
67
68impl DerefMut for PolylineOptions {
69 fn deref_mut(&mut self) -> &mut Self::Target {
70 &mut self.obj
71 }
72}
73
74impl LeafletEventHandler for Polyline {
75 fn on(&self, event: &str, callback: &JsValue) {
76 self.unchecked_ref::<Evented>().on(event, callback);
77 }
78}
79
80impl MouseEvents for Polyline {}
81impl LayerEvents for Polyline {}
82impl PopupEvents for Polyline {}
83impl TooltipEvents for Polyline {}