import Layer from "ol/layer/Vector";
import config from "@/api/config.js";
import * as KMap from "@/utils/ol-map/KMap";
import Stroke from "ol/style/Stroke";
import * as util from "@/common/ol_common.js";
import { newAreaFeature } from "@/common/util";
import Style from "ol/style/Style";
import Icon from "ol/style/Icon";
import {Point } from 'ol/geom';
import Feature from "ol/Feature";
import WKT from "ol/format/WKT";

/**
 * @description 智能巡园地图层对象
 */
class AreaMap {
  constructor() {
    let that = this;
    let vectorStyle = new KMap.VectorStyle();
    this.vectorStyle = vectorStyle;
  }

  initMap(location, target) {
    let vectorStyle = new KMap.VectorStyle();
    // 位置图标
    this.blueRegionLayer = new KMap.VectorLayer("blueRegionLayer", 99999, {
        minZoom: 1,
        maxZoom: 22,
    });
    let level = 16;
    let coordinate = util.wktCastGeom(location).getFirstCoordinate();
    this.kmap = new KMap.Map( target, level, coordinate[0], coordinate[1], null, 1, 22 ,"vec", true, true);
    this.kmap.addLayer(this.blueRegionLayer.layer);
    let xyz = config.base_img_url + "map/lby/{z}/{x}/{y}.png";
    this.kmap.addXYZLayer(xyz, { minZoom: 8, maxZoom: 22 }, 2);
  }

  setData(item){
    let feature = newAreaFeature(item);
    this.blueRegionLayer.addFeature(feature);
  }

  fit(){
    this.kmap.fit(this.blueRegionLayer.source.getExtent(), [0, 0, 0, 0]);
  }

  // 重新渲染地图
  updateMap() {
    setTimeout(() => {
      this.kmap.map.updateSize()
    }, 1000);
  }

  // fit(geomOrExtent, padding) {
  //   this.kmap.fit(geomOrExtent, padding);
  // }
}

export default AreaMap;
