import VectorSource from 'ol/source/Vector.js';
import WKT from 'ol/format/WKT.js';
import Feature from 'ol/Feature.js';
import VectorLayer from 'ol/layer/Vector.js';
import Draw from "ol/interaction/Draw";
import Text from "ol/style/Text";
import Icon from "ol/style/Icon";
import {Circle, Fill, Stroke, Style} from 'ol/style.js';

export function getRadius(zoom){
    if(zoom >= 20){
        return 120;
    }
    if(zoom >= 19){
        return 70;
    }
    if(zoom >= 18){
        return 30;
    }
    if(zoom >= 17){
        return 15;
    }
    return 10;
}

export function getScale(zoom){
    if(zoom >= 20){
        return 0.8;
    }
    if(zoom >= 19){
        return 0.4;
    }
    if(zoom >= 18){
        return 0.2;
    }
    if(zoom >= 17){
        return 0.1;
    }
    return 0.1;
}

export function isShow(zoom,id){

    if(zoom > 18){
        return true;
    }
    if(zoom >= 18){
        return mo(id, 4)
    }
    if(zoom >= 17){
        return mo(id, 5)
    }
    return  mo(id, 5)
}
export function mo(id,midu){
    return id % midu == 0
}

export const colors = ["#9EFE0C","#FEC30C","#FE760C","#FE0B0C","#0DCAFE","#A80BFF","#E4FE0C","#1A0BFF"];
export const imgs = ["point6.png","point1.png","point2.png","point3.png","point4.png","point5.png","point6.png","point7.png","point8.png"]
export const pz = ["未知","白糖罂","桂味","井岗红糯","糯米糍","岭丰糯","进奉","冰荔","妃子笑"]

export function getIndex(name){
    let i = 0;
    for(let item of pz){
        if(name === item){
            return i;
        }
        i++;
    }
}

/**
 *
 * @param data
 * @param geomField 形状的字段
 * @param sign 标识
 * @returns {Feature<{geometry: any}>}
 */
export const newPoint = (data, geomField, sign)=>{
    let point = new WKT().readGeometry(data[geomField])
    let feature = new Feature({
        geometry: point
    });
    feature.setId(data.id)
    feature.set("nodeType",sign)
    for(let key in data){
        if(key != geomField && data[key]){
            feature.set(key,data[key])
        }
    }
    return feature;
}

export const newGeomPoint = (data)=>{
    let point = new WKT().readGeometry(data["geom"])
    let feature = new Feature({
        geometry: point
    });
    feature.setId(data.id)
    feature.set("nodeType","tree")
    for(let key in data){
        if(key != "geom" && data[key]){
            feature.set(key,data[key])
        }
    }
    return feature;
}

export const newPolymerFeature = (data)=>{
    let geom = new WKT().readGeometry(data["wkt"])
    let feature = new Feature({
        geometry: geom
    });
    feature.set("nodeType","polymer");
    feature.setId(data.id)
    for(let key in data){
        if(key != "wkt"){
            feature.set(key,data[key])
        }
    }
    return feature;
}

export const newAreaFeature = (data)=>{
    let geom = new WKT().readGeometry(data["geom"])
    let feature = new Feature({
        geometry: geom
    });
    feature.set("nodeType","area");
    feature.setId(data.id)
    for(let key in data){
        if(key != "geom"){
            feature.set(key,data[key])
        }
    }
    return feature;
}
export const pointToFormat = (pointString)=> {
    let geom = new WKT().readGeometry(pointString)
        const longitude = geom.getCoordinates()[0];
        const latitude = geom.getCoordinates()[1];
        // 转换为度的格式
        const formattedLongitude = `${longitude.toFixed(0)}°E`;
        const formattedLatitude = `${latitude.toFixed(0)}°N`;

        const result = `${formattedLongitude},${formattedLatitude}`;
        console.log(result); // 输出: 111.011490207°E,21.7739355047°N
        return result

}


