/**
 * @description
 * @author       朱琦
 * @date         2022/1/7 17:23
 */
import MapSdk from "./";
import mapPublic from './map-public'


class MapSdkF extends MapSdk {
    constructor(map, mapId, mapConfig, pointClick) {
        super(map, mapId, mapConfig, pointClick);
    }

    /**
     * 创建点聚合
     * @param data  Array
     *          - name '' 图标提示信息
     *          - path [lng,lat] 经纬度
     *          - icon '' 图标名称
     *          - size [32,32] 图标大小
     * @param config 点聚合自定义样式
     *          - className class名
     *          - size 尺寸
     *          - content 内容 设置改属性其他style属性都失效
     *          - backgroundColor 背景色
     *          - color 字体色
     * @param callback   单个标记点点击回调
     *          - e 标记点对象
     *          - item 标记点data
     *
     * @returns {AMap.MarkerClusterer}
     */
    createMvMapMarkerCluster(data, config = {}, callback) {
        return new Promise((resolve) => {
            let points = [];
            if (data) {
                points = this.createMvMapMarkerLayer(data, config, callback)
            }
            let cluster = new AMap.MarkerClusterer(this.map, points, {
                renderClusterMarker: (context) => mapPublic.renderClusterMarker(context, config),
                ...config
            })
            cluster.on('click', e => {
                if (e.markers && e.markers.length !== 0) {
                    callback(e, e.markers, { ...config, CLICK_TYPE: 'Cluster' })
                }
            })
            resolve(cluster)
        })

    }

    /**
     * 添加地图控件
     * @param controls( ['scale','toolBar','controlBar','overView'] )-Array
     *          -- scale        比例尺
     *          -- toolBar      工具条
     *          -- controlBar   工具条方向盘
     *          -- overView     显示鹰眼
     */
    addMvMapControl(controls, config = {}) {
        let mapControl = null
        switch (controls) {
            case 'scale':
                mapControl = new AMap.Scale()
                this.map.addControl(mapControl)
                break;
            case 'toolBar':
                mapControl = new AMap.ToolBar({
                    position: { top: '10px', right: '10px' }
                })
                this.map.addControl(mapControl)
                break;
            case 'controlBar':
                mapControl = new AMap.ControlBar(config)
                this.map.addControl(mapControl)
                break;
            case 'overView':
                mapControl = new AMap.OverView()
                this.map.addControl(mapControl);
                mapControl.open()
                break;

            default:
                break;
        }
        return mapControl
    }
    /**
     * 创建热力图
     *  - data Array
     *      lng  [Number] 经度
     *      lat  [Number] 纬度
     *      count  [Number] 总数
     *  - config Object
     *      radius  热力图中单个点的半径
     *      opacity 热力图透明度区间
     *      zooms 支持的缩放级别范围
     *      gradient    热力图的渐变区间
     *      max 最大权重值
     */
    createMvMapHeatMap(data, config = {}) {
        let self = this;
        let heatMap = new AMap.Heatmap(self.map, {
            radius: config.radius || 25,
            opacity: config.opacity || [0, 1],
            zooms: config.zooms || [3, 20],
            gradient: config.gradient || {
                0.5: 'blue',
                0.65: 'rgb(117,211,248)',
                0.7: 'rgb(0, 255, 0)',
                0.9: '#ffea00',
                1.0: 'red'
            }
        });
        heatMap.setDataSet({
            data: data,
            max: config.max || 100
        });
        return heatMap;
    }
}
export default MapSdkF;