import config from "@/api/config.js";
import * as KMap from "@/utils/ol-map/KMap";
import { newAreaFeature } from "@/utils/util";

/**
 * @description 地图层对象
 */
class BoundaryLayer {
    constructor(map) {
        let that = this;
        this.vectorStyle = new KMap.VectorStyle();

        // this.boundaryLayer = new KMap.VectorLayer("boundaryLayer", 99, {
        //     minZoom: 15,
        // });

        this.boundaryLayer = new KMap.VectorLayer("areaLayer", 999, {
            style: (f) => {
                const style = that.vectorStyle.getPolygonStyle("#00000010", "#ffffffcc", 3)
                const style2 = that.vectorStyle.getPointTextStyle(f.get('name'), "#000000", "#ffffff", 0, 22)
                return [style, style2]
            }
        });

        map.addLayer(this.boundaryLayer.layer);
        this.kmap = map
    }

    initData(arr,opacity='') {
        if (this.boundaryLayer) {
            this.boundaryLayer.source.clear();
        }
        if(arr.length>0){
            for (let item of arr) {
                let feature = newAreaFeature(item);
                this.boundaryLayer.addFeature(feature);
            }
            // setTimeout(()=>{
            //     this.kmap.fit(this.boundaryLayer.source.getExtent(), {padding:[100,100,100,100]});
            // })
        }
    }

    toggleLayer(val) {
        this.boundaryLayer.layer.setVisible(val)
    }
}

export default BoundaryLayer;
