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

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

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

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

    initData(arr,opacity='') {
        if (this.blueRegionLayer) {
            this.blueRegionLayer.source.clear();
        }
        if(arr.length>0){
            for (let item of arr) {
                let feature = newAreaFeature(item);
                let strokeColor = "#FFFFFF";
                // feature.setStyle(this.vectorStyle.getPolygonStyle("transparent", item.color, 2));
                feature.setStyle(this.vectorStyle.getPolygonStyle("transparent", "rgba(255, 255, 255, 0.6)", 2));
                // feature.setStyle(this.vectorStyle.getPolygonStyle(item.color+opacity, strokeColor, 1));
                this.blueRegionLayer.addFeature(feature);
            }
            // setTimeout(()=>{
            //     this.kmap.fit(this.blueRegionLayer.source.getExtent(), {padding:[100,100,100,100]});
            // })
        }
    }

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

export default BlueRegionLayer;
