/* eslint-disable consistent-return */
declare const TMap: any;
const init = (mapId: any) => {
    // const elem = document.getElementById(mapId);
    // console.log(elem, 'elem');
    return new TMap.Map(mapId, {
        zoom: 11,
        center: new TMap.LatLng(32.255903, 118.333417),
        renderOptions: {
            enableBloom: true // 泛光
        }
    });
};

const latLng = (e: any, e1: any) => {
    return new TMap.LatLng(e, e1);
};

const marker = (map: any, center: any) => {
    return new TMap.MultiMarker({
        map,
        styles: {
            // 点标记样式
            marker: new TMap.MarkerStyle({
                width: 20, // 样式宽
                height: 30, // 样式高
                anchor: { x: 10, y: 30 } // 描点位置
            })
        },
        geometries: [
            // 点标记数据数组
            {
                // 标记位置(纬度，经度，高度)
                position: center,
                id: 'marker'
            }
        ]
    });
};

const search: any = () => {
    return new TMap.service.Search({
        pageSize: 20
    });
    // return new Promise((resolve) => {
    //     upload.searchRectangle(opt).then((res: any) => {
    //       resolve(res.data);
    //     });
    // });
};

const geocoder: any = () => {
  return new TMap.service.Geocoder();
  
    // return new Promise((resolve) => {
    //     upload.searchRectangle(opt).then((res: any) => {
    //       resolve(res.data);
    //     });
    // });
};

const multiPolyline = (e: any, pathArr: any) => {
    return new TMap.MultiPolyline({
        map: e, // 绘制到目标地图
        // 折线样式定义
        styles: {
            style_blue: new TMap.PolylineStyle({
                color: '#3777FF', // 线填充色
                width: 4, // 折线宽度
                borderWidth: 2, // 边线宽度
                borderColor: '#FFF', // 边线颜色
                lineCap: 'round', // 线端头方式
                eraseColor: 'rgba(190,188,188,1)'
            })
        },
        geometries: [
            {
                id: 'car',
                styleId: 'style_blue',
                paths: pathArr
            }
        ]
    });
};

const multiPolyline1 = (map: any, pathArr: any) => {
    return new TMap.MultiPolyline({
        map, // 绘制到目标地图
        // 折线样式定义
        styles: {
            style_blue: new TMap.PolylineStyle({
                color: '#3777FF', // 线填充色
                width: 4, // 折线宽度
                borderWidth: 2, // 边线宽度
                borderColor: '#FFF', // 边线颜色
                lineCap: 'round', // 线端头方式
                eraseColor: 'rgba(190,188,188,1)'
            })
        },
        geometries: [
            {
                id: 'car',
                styleId: 'style_blue',
                paths: pathArr
            }
        ]
    });
};

const multiMarker = (map: any, e: any) => {
    return new TMap.MultiMarker({
        map,
        styles: {
            'car-down': new TMap.MarkerStyle({
                color: '#3777FF', // 颜色属性
                angle: 0, // 文字旋转属性
                alignment: 'center', // 文字水平对齐属性
                verticalAlignment: 'middle', // 文字垂直对齐属性
                size: 16, // 标注点文本文字大小
                offset: { x: 0, y: -30 }, // 标注点文本文字基于direction方位的偏移属性
                width: 20,
                height: 44,
                faceTo: 'map',
                rotate: 180,
                // src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/car.png'
                src: 'https://sjcdn.oss-cn-hangzhou.aliyuncs.com/image/1724755875530.png'
            }),
            start: new TMap.MarkerStyle({
                width: 25,
                height: 35,
                anchor: { x: 16, y: 32 },
                src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/start.png'
            }),
            end: new TMap.MarkerStyle({
                width: 25,
                height: 35,
                anchor: { x: 16, y: 32 },
                src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/end.png'
            })
        },
        geometries: [
            {
                id: 'car',
                styleId: 'car-down',
                position: e[0],
                content: '川S8888' // 标记显示内容
            },
            {
                id: 'start',
                styleId: 'start',
                position: e[0]
            }
        ]
    });
};

export { init, latLng, search, geocoder, multiPolyline, multiPolyline1, multiMarker, marker };
