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
use js_sys::Array;
use wasm_bindgen::prelude::*;

use crate::evented::{LeafletEventHandler, MouseEvents, PopupEvents, TooltipEvents};
use crate::{Evented, LatLng, Layer, LayerEvents, Polyline, PolylineOptions};

#[wasm_bindgen]
extern "C" {
    #[derive(Debug, Clone)]
    #[wasm_bindgen(extends = Polyline)]
    pub type Polygon;

    #[wasm_bindgen(constructor, js_namespace = L)]
    pub fn new(latlngs: &Array) -> Polygon;

    #[wasm_bindgen(constructor, js_namespace = L)]
    pub fn new_with_options(latlngs: &Array, options: &PolylineOptions) -> Polygon;

    #[wasm_bindgen(method, js_name = getCenter)]
    pub fn get_center(this: &Polygon) -> LatLng;
}

/// Seems that wasmbindgen doesn't implement From<Polyline> for Layer
impl From<Polygon> for Layer {
    fn from(value: Polygon) -> Self {
        value.unchecked_into()
    }
}

impl LeafletEventHandler for Polygon {
    fn on(&self, event: &str, callback: &JsValue) {
        self.unchecked_ref::<Evented>().on(event, callback);
    }
}

impl MouseEvents for Polygon {}
impl LayerEvents for Polygon {}
impl PopupEvents for Polygon {}
impl TooltipEvents for Polygon {}