import { ControlOutlined } from '@ant-design/icons-vue';
import * as turf from '@turf/turf'

// js生成UUID
const generateUUID = ()=>{

    var d = new Date().getTime(); //Timestamp
    var d2 = (performance && performance.now && (performance.now()*1000)) || 0;
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random() * 16; 
        if(d > 0) {
            r = (d + r)%16 | 0;
            d = Math.floor(d/16);
        } else { 
            r = (d2 + r)%16 | 0;
            d2 = Math.floor(d2/16);
        }
        return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
    });
}

// js 针对后端post接口参数拼接到url的情况 将json参数转换为 ?key1=value1&key2=value2
const ObjectToUrl = (obj)=>{
    let params = "?";
    for(let item in obj){
        params+=item+"="+obj[item]+"&"
    }
    return params;
}


// turf获取几何图形的中心
const getGeometryCenter = (geometry)=>{
    let coordinates = [];
    switch(geometry.geometry.type.toUpperCase()){
        case "POINT": 

            break;
        case "MULTIPOINT":

            break;
        case "LINESTRING":

            break;
        case "MULTILINESTRING":

            break;
        case "POLYGON":
            coordinates = geometry.geometry.coordinates
            break;
        case "MULTIPOLYGON":
            coordinates = geometry.geometry.coordinates[0]
            break;
    }
    
    // let polygon = turf.polygon(coordinates);
    // let center = turf.centerOfMass(polygon);
    return [coordinates[0][0][0],coordinates[0][0][1]];
    // return [117.732878836452,35.1320944773393]
}

export { generateUUID,ObjectToUrl,getGeometryCenter }