Source: ext/geom/index.js

import * as maptalks from "../../libs/maptalks";
import { EasyMap } from "../../easyMap";
import InfoWindow from "../InfoWindow";
class Geom {
    /**
     * 覆盖物类
     * @constructor
     * @class Geom
     * @param {object} geometry 原生的覆盖物类
     * @param {string} type 覆盖物类型
     */
    constructor(geometry, type) {
        this._animate = null;
        this._geometry = geometry;
        this.type = type;
        geometry ? (this.id = geometry.getId()) : "";
        this._handlers = [];
    }

    /**
     *创建点实例
     * @param {Array} position 点标记坐标
     * @param {Boolean} options.id
     * @param {Boolean} options.visible 是否可见
     * @param {Boolean} options.editable 是否可以编辑
     * @param {Boolean} options.interactive 是否可以交互
     * @param {String} options.cursor 鼠标悬停在几何上时的光标样式,与CSS中的定义相同
     * @param {String} options.measure 坐标系,默认EPSG:4326
     * @param {Boolean} options.draggable 是否可以拖动
     * @param {Boolean} options.dragShadow 如果为true,则在拖动几何图形期间,将在移动几何图形之前拖动阴影
     * @param {Boolean} options.dragOnAxis 如果设置,则只能沿指定的轴拖动几何,可能的值:x,y
     * @param {Number} options.zIndex 初始zIndex
     * @param {Object} options.symbol 点标记的默认符号
     * @return {Geom} 返回Geom实例
     * @memberof Geom
     */
    createPointFeature(position, options) {
        if (position && Array.isArray(position)) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.Marker(position, options);
            this.type = this._geometry.type;
            return this;
        }
    }

    /**
     *创建图标实例
     * @param {Array} position 点标记坐标
     * @param {object} options 点标记配置项,同上
     * @return {Geom} 返回Geom实例
     * @memberof Geom
     */
    createIconFeature(position, options) {
        if (position && Array.isArray(position)) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.Marker(position, options);
            this.type = this._geometry.type;
            return this;
        }
    }

    /**
     *创建线类型实例
     *
     * @param {Array} positions 线覆盖物坐标集合,坐标要两个或两个以上;例如[[-0.131049, 51.498568],[-0.107049, 51.498568]]
     * @param {object} options 线覆盖物配置项
     * @param {Boolean} options.id
     * @param {Boolean} options.visible 是否可见
     * @param {Boolean} options.editable 是否可以编辑
     * @param {Boolean} options.interactive 是否可以交互
     * @param {String} options.cursor 鼠标悬停在几何上时的光标样式,与CSS中的定义相同
     * @param {String} options.measure 坐标系,默认EPSG:4326
     * @param {Boolean} options.draggable 是否可以拖动
     * @param {Boolean} options.dragShadow 如果为true,则在拖动几何图形期间,将在移动几何图形之前拖动阴影
     * @param {Boolean} options.dragOnAxis 如果设置,则只能沿指定的轴拖动几何,可能的值:x,y
     * @param {Number} options.zIndex 初始zIndex
     * @param {String | Array.<Number>} options.arrowStyle 箭头样式,可以是预定义值或数组[arrow-width,arrow-height](数组中的值是线宽的倍数)例如:classic ([3, 4])
     * @param {String} options.arrowPlacement  箭头的位置:vertex-first, vertex-last, vertex-firstlast, point
     * @param {Number} options.smoothness  对线进行平滑处理,默认情况下为0
     * @param {Boolean} options.enableSimplify  是否在渲染之前简化线条
     * @param {Number} options.simplifyTolerance  该值越高,线条简化越激烈
     * @param {Boolean} options.enableClip  是否用地图的当前范围剪切线条
     * @param {Object} options.symbol 线条的默认符号
     * @return {Geom} 返回Geom实例
     * @memberof Geom
     */
    createLineStringFeature(positions, options) {
        if (positions && Array.isArray(positions) && positions.length > 1) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.LineString(positions, options);
            this.type = this._geometry.type;
            return this;
        }
    }

    /**
     *直线连接线
     *
     * @param {Geom} src 连接源覆盖物
     * @param {Geom} target 目标覆盖物
     * @param {Object} options 连接线配置项
     * @param {String} options.showOn 何时显示连接线('moving', 'click', 'mouseover', 'always')
     * @param {String | Array.<Number>} options.arrowStyle 箭头样式,同上
     * @param {String} options.arrowPlacement 箭头的位置(vertex-first, vertex-last, vertex-firstlast, point)
     * @param {Number} options.smoothness 对线进行平滑处理,默认情况下为0
     * @param {Boolean} options.enableSimplify 是否在渲染之前简化路径
     * @param {Number} options.simplifyTolerance 简化路径的容忍度越高,简化越激烈
     * @param {Boolean} options.enableClip 是否用地图的当前范围剪切路径
     * @param {Boolean} options.id 几何体的ID
     * @param {Boolean} options.visible 几何是否可见
     * @param {Boolean} options.editable 是否可以编辑几何。
     * @param {Boolean} options.interactive 几何是否可以交互。
     * @param {String} options.cursor 鼠标悬停在几何上时的光标样式,与CSS中的定义相同。
     * @param {Boolean} options.draggable 是否可以拖动几何。
     * @param {Boolean} options.dragShadow 如果为true,则在拖动几何图形期间,将在移动几何图形之前拖动阴影。
     * @param {Boolean} options.dragOnAxis 如果设置,则只能沿指定的轴拖动几何,可能的值:x,y
     * @param {Number} options.zIndex 几何的初始zIndex
     * @param {Number} options.measure 坐标系,默认EPSG:4326
     * @param {Object} options.symbol 路径的默认符号
     * @return {Geom}
     * @memberof Geom
     */
    createConnectorLineFeature(src, target, options) {
        if (src && target) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.ConnectorLine(
                src._geometry,
                target._geometry,
                options
            );
            this.type = this._geometry.type;
            return this;
        }
    }

    /**
     *曲线连接线
     *
     * @param {Geom} src 连接源覆盖物
     * @param {Geom} target 目标覆盖物
     * @param {Object} options 连接线配置项
     * @param {String} options.showOn 何时显示连接线('moving', 'click', 'mouseover', 'always')
     * @param {Number} options.arcDegree 圆弧度
     * @param {String | Array.<Number>} options.arrowStyle 箭头样式,同上
     * @param {String} options.arrowPlacement 箭头的位置(vertex-first, vertex-last, vertex-firstlast, point)
     * @param {Number} options.smoothness 对线进行平滑处理,默认情况下为0
     * @param {Boolean} options.enableSimplify 是否在渲染之前简化路径
     * @param {Number} options.simplifyTolerance 简化路径的容忍度越高,简化越激烈
     * @param {Boolean} options.enableClip 是否用地图的当前范围剪切路径
     * @param {Boolean} options.id 几何体的ID
     * @param {Boolean} options.visible 几何是否可见
     * @param {Boolean} options.editable 是否可以编辑几何。
     * @param {Boolean} options.interactive 几何是否可以交互。
     * @param {String} options.cursor 鼠标悬停在几何上时的光标样式,与CSS中的定义相同。
     * @param {Boolean} options.draggable 是否可以拖动几何。
     * @param {Boolean} options.dragShadow 如果为true,则在拖动几何图形期间,将在移动几何图形之前拖动阴影。
     * @param {Boolean} options.dragOnAxis 如果设置,则只能沿指定的轴拖动几何,可能的值:x,y
     * @param {Number} options.zIndex 几何的初始zIndex
     * @param {Number} options.measure 坐标系,默认EPSG:4326
     * @param {Object} options.symbol 路径的默认符号
     * @return {Geom}
     * @memberof Geom
     */
    createArcConnectorLineFeature(src, target, options) {
        if (src && target) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.ArcConnectorLine(
                src._geometry,
                target._geometry,
                options
            );
            this.type = this._geometry.type;
            return this;
        }
    }
    /**
     *创建多边形实例
     *
     * @param {Array} positions 多边形坐标集合,坐标要三个或三个以上;例如[[-0.131049, 51.498568],[-0.107049, 51.498568],[-0.157049, 52.498568]]
     * @param {object} options 多边形配置项
     * @param {Boolean} options.id
     * @param {Boolean} options.visible 是否可见
     * @param {Boolean} options.editable 是否可以编辑
     * @param {Boolean} options.interactive 是否可以交互
     * @param {String} options.cursor 鼠标悬停在几何上时的光标样式,与CSS中的定义相同
     * @param {String} options.measure 坐标系,默认EPSG:4326
     * @param {Boolean} options.draggable 是否可以拖动
     * @param {Boolean} options.dragShadow 如果为true,则在拖动几何图形期间,将在移动几何图形之前拖动阴影
     * @param {Boolean} options.dragOnAxis 如果设置,则只能沿指定的轴拖动几何,可能的值:x,y
     * @param {Number} options.zIndex 初始zIndex
     * @param {Number} options.smoothness  对多边形进行平滑处理,默认情况下为0
     * @param {Boolean} options.enableSimplify  是否在渲染之前简化多边形
     * @param {Number} options.simplifyTolerance  该值越高,多边形简化越激烈
     * @param {Boolean} options.enableClip  是否用地图的当前范围剪切多边形
     * @param {Object} options.symbol 多边形的默认符号
     * @return {Geom} 返回Geom实例
     * @memberof Geom
     */
    createPolygonFeature(positions, options) {
        if (positions && Array.isArray(positions) && positions.length > 2) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.Polygon(positions, options);
            this.type = this._geometry.type;
            return this;
        }
    }

    /**
     *创建矩形实例
     *
     * @param {Array} coordinates 矩形左上角坐标;例如[-0.157049, 52.498568]
     *  @param {number} width 矩形宽度,以米为单位
     * @param {number} height 矩形高度,以米为单位
     * @param {object} options 矩形配置项,同上
     * @return {Geom} 返回Geom实例
     * @memberof Geom
     */
    createRectangleFeature(coordinates, width, height, options) {
        if (coordinates && Array.isArray(coordinates)) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.Rectangle(
                coordinates,
                width,
                height,
                options
            );
            this.type = this._geometry.type;
            return this;
        }
    }

    /**
     *创建圆形实例
     *
     * @param {Array} coordinates 圆心;例如[-0.157049, 52.498568]
     *  @param {number} radius 圆的半径,以米为单位
     * @param {object} options 圆形配置项,同上
     * @param {number} options.numberOfShellPoints 将圆转换为多边形时的点数
     * @return {Geom} 返回Geom实例
     * @memberof Geom
     */
    createCircleFeature(coordinates, radius, options) {
        if (coordinates && Array.isArray(coordinates)) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.Circle(coordinates, radius, options);
            this.type = this._geometry.type;
            return this;
        }
    }

    /**
     *创建文本框实例
     *
     * @param {String} content 文字内容
     * @param {Array} coordinates 中心点坐标
     * @param {Number} width 像素宽度
     * @param {Number} height 像素高度
     * @param {Object} options 配置项
     * @param {Object} options.textStyle 文字样式
     * @param {Boolean} options.textStyle.wrap 是否自动换行文本框中的文本
     * @param {Boolean} options.textStyle.padding 	框中的文本padding
     * @param {Boolean} options.textStyle.verticalAlignment 文字的垂直对齐
     * @param {Boolean} options.textStyle.horizontalAlignment 文字的水平对齐
     * @param {Boolean} options.textStyle.symbol 文字内容的符号
     * @param {Object} options.boxSymbol 文本框的框符号
     * @param {Boolean} options.id
     * @param {Boolean} options.visible 是否可见
     * @param {Boolean} options.editable 是否可以编辑
     * @param {Boolean} options.interactive 是否可以交互
     * @param {String} options.cursor 鼠标悬停在几何上时的光标样式,与CSS中的定义相同
     * @param {String} options.measure 坐标系,默认EPSG:4326
     * @param {Boolean} options.draggable 是否可以拖动
     * @param {Boolean} options.dragShadow 如果为true,则在拖动几何图形期间,将在移动几何图形之前拖动阴影
     * @param {Boolean} options.dragOnAxis 如果设置,则只能沿指定的轴拖动几何,可能的值:x,y
     * @param {Number} options.zIndex 初始zIndex
     * @return {Geom} 返回Geom实例
     * @memberof Geom
     */
    createLableFeature(content, coordinates, width, height, options) {
        if (coordinates && Array.isArray(coordinates)) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.TextBox(
                content,
                coordinates,
                width,
                height,
                options
            );
            this.type = this._geometry.type;
            return this;
        }
    }

    /**
     *创建HTMLElement实例
     *
     * @param {Array} coordinates 坐标
     * @param {Object} options 配置项
     * @param {Boolean} options.draggable 是否可以拖动标记
     * @param {Number} options.single 标记是全局单个标记
     * @param {String | HTMLElement	} options.content 标记的内容可以是字符串类型的HTML代码或HTMLElement。
     * @param {Boolean} options.eventsPropagation 是否阻止冒泡
     * @param {Boolean} options.eventsToStop
     * @param {Number} options.dx x轴上的像素偏移
     * @param {Number} options.dy y轴上的像素偏移
     * @param {Boolean} options.autoPan 是否地图进行平移动画打开
     * @param {Boolean} options.autoPanDuration 自动平移动画的持续时间
     * @param {Boolean} options.animation fade | scale 在显示和隐藏时淡入,缩放,添加动画效果
     * @param {Number} options.animationDuration 动画持续时间(以毫秒为单位)
     * @param {Boolean} options.pitchWithMap 是否与地图倾斜
     * @param {Boolean} options.rotateWithMap 是否随地图旋转
     * @return {Geom} 返回Geom实例
     * @memberof Geom
     */
    createHtmlOverlay(coordinates, options) {
        if (coordinates && Array.isArray(coordinates)) {
            options && options.id ? (this.id = options.id) : "";
            this._geometry = new maptalks.ui.UIMarker(coordinates, options);
            this.type = "HtmlPoint";
            return this;
        }
    }

    /**
     *事件绑定
     *
     * @param {*} eventsOn 要注册的事件类型
     * @param {Function} handler 要调用的处理函数
     * @param {*} context 处理程序的上下文
     * @return {Function} 返回处理过的回调,用于移除绑定
     * @memberof Geom
     */
    on(eventsOn, handler, context) {
        let h = (e) => {
            e.target = this;
            handler(e);
        };
        this._geometry.on(eventsOn, h, context);
        this._handlers.push({ name: eventsOn, handler: h });
        return h;
    }

    /**
     *事件绑定,别名
     *
     * @param {*} eventsOn 要注册的事件类型
     * @param {Function} handler 要调用的处理函数
     * @param {*} context 处理程序的上下文
     * @return {Function} 返回处理过的回调,用于移除绑定
     * @memberof Geom
     */
    addMapEventListener(eventsOn, handler, context) {
        let h = (e) => {
            e.target = this;
            handler(e);
        };
        this._geometry.addEventListener(eventsOn, h, context);
        this._handlers.push({ name: eventsOn, handler: h });
        return h;
    }

    /**
     *单次事件绑定,调用一次后移除
     *
     * @param {*} eventsOn 要注册的事件类型
     * @param {Function} handler 要调用的处理函数
     * @param {*} context 处理程序的上下文
     * @memberof Geom
     */
    once(eventsOn, handler, context) {
        let h = (e) => {
            e.target = this;
            handler(e);
        };
        this._geometry.once(eventsOn, h, context);
        this._handlers.push({ name: eventsOn, handler: h });
        return h;
    }

    /**
     *事件移除
     *
     * @param {*} eventsOn 要移除的事件类型
     * @param {Function} handler 要移除的处理函数,该函数为绑定事件时返回的函数,如不传既移除该事件所有绑定(可选)
     * @param {*} context 处理程序的上下文
     * @memberof Geom
     */
    un(eventsOn, handler, context) {
        if (handler) {
            this._geometry.off(eventsOn, handler, context);
        } else {
            let len = this._handlers.length - 1;
            for (let i = len; i >= 0; i--) {
                if (eventsOn === this._handlers[i].name) {
                    this._geometry.off(
                        eventsOn,
                        this._handlers[i].handler,
                        context
                    );
                    this._handlers.splice(i, 1);
                }
            }
        }
    }

    /**
     *事件移除,别名
     *
     * @param {*} eventsOn 要移除的事件类型
     * @param {Function} handler 要移除的处理函数,该函数为绑定事件时返回的函数,如不传既移除该事件所有绑定(可选)
     * @param {*} context 处理程序的上下文
     * @memberof Geom
     */
    removeMapEventListener(eventsOn, handler, context) {
        if (handler) {
            this._geometry.removeEventListener(eventsOn, handler, context);
        } else {
            let len = this._handlers.length - 1;
            for (let i = len; i >= 0; i--) {
                if (eventsOn === this._handlers[i].name) {
                    this._geometry.removeEventListener(
                        eventsOn,
                        this._handlers[i].handler,
                        context
                    );
                    this._handlers.splice(i, 1);
                }
            }
        }
    }

    /**
     *将覆盖物添加到默认图层
     *
     * @param {object} map map||layer 地图或图层对象,必传
     * @param {boolean} [fitview=false] 是否自动将地图设置为合适的中心并缩放覆盖物
     * @memberof Geom
     */
    addTo(map, fitview = false) {
        if (map && map instanceof EasyMap) {
            //传的地图
            if (this.type === "HtmlPoint") {
                this._geometry.addTo(map.map);
            } else {
                const defaultLayer = map.getLayer("default_vector");
                this._geometry.addTo(defaultLayer.layer, fitview);
                defaultLayer._geometries.push(this);
                this._geomLayer = defaultLayer;
            }
        } else {
            //传的图层
            this._geometry.addTo(map, fitview);
            map._geometries.push(this);
            this._geomLayer = map;
        }
        return this;
    }

    /**
     * 获取覆盖物的ID。ID由setId或构造函数选项设置。
     * @return {*} 返回覆盖物ID
     * @memberof Geom
     */
    getId() {
        return this.id || null;
    }

    /**
     *设置覆盖物的ID
     *
     * @param {*} id
     * @memberof Geom
     */
    setId(id) {
        try {
            this._geometry.setId(id);
        } catch (error) {
        } finally {
            this.id = id;
        }
    }

    /**
     *从图层中删除自身(如果存在)
     *
     * @memberof Geom
     */
    RemoveFeature() {
        let layerArr = this._geomLayer._geometries;
        for (let i = layerArr.length; i >= 0; i--) {
            if (layerArr[i] === this) {
                layerArr.splice(i, 1);
            }
        }
        this._geometry.remove();
    }

    /**
     *返回该覆盖物所在图层
     *
     * @return {*}
     * @memberof Geom
     */
    getLayer() {
        return this._geomLayer;
    }

    /**
     *获取对象地理中心坐标
     *
     * @return {Array}  返回坐标数组[x,y]
     * @memberof Geom
     */
    getCenter() {
        let coordinate =
            this.type === "HtmlPoint"
                ? this._geometry.getCoordinates()
                : this._geometry.getCenter();
        return [coordinate.x, coordinate.y];
    }

    /**
     *打开信息窗体
     *
     * @param {Array} coordinate 可选,信息窗体打开的位置,例如[0,0],默认为覆盖物中心
     * @memberof Geom
     */
    openInfoWindow(coordinate) {
        if (this.type === "HtmlPoint") {
            this._infoWindow.show(this.getCoordinates());
        } else {
            this._geometry.openInfoWindow(
                coordinate ? new maptalks.Coordinate(coordinate) : ""
            );
        }
    }

    /**
     *关闭信息窗体
     *
     * @memberof Geom
     */
    closeInfoWindow() {
        if (this.type === "HtmlPoint") {
            this._infoWindow.hide();
        } else {
            this._geometry.closeInfoWindow();
        }
    }

    /**
     *移除信息窗体
     *
     * @memberof Geom
     */
    removeInfoWindow() {
        if (this.type === "HtmlPoint") {
            this._infoWindow.remove();
        } else {
            this._geometry.removeInfoWindow();
        }
    }

    /**
     *获取信息窗体实例
     *
     * @return {*}
     * @memberof Geom
     */
    getInfoWindow() {
        if (this.type === "HtmlPoint") {
            return this._infoWindow;
        } else {
            let infoWindow = new InfoWindow(this._geometry.getInfoWindow());
            return infoWindow;
        }
    }

    /**
     *设置信息窗体
     *
     * @param {*} options
     * @memberof Geom
     */
    setInfoWindow(options) {
        if (this.type === "HtmlPoint") {
            this._infoWindow = new InfoWindow(options);
            this._infoWindow.addTo(this);
        } else {
            this._geometry.setInfoWindow(options);
        }
    }

    /**
     *开始编辑(HTML覆盖物不支持)
     *
     * @memberof Geom
     */
    startEditFeature() {
        this._geometry.startEdit();
    }

    /**
     *结束编辑(HTML覆盖物不支持)
     *
     * @memberof Geom
     */
    stopEditFeature() {
        this._geometry.endEdit();
    }

    /**
     *开启拖拽
     *
     * @memberof Geom
     */
    startDragFeatures() {
        this._geometry.config("draggable", true);
    }

    /**
     *结束拖拽
     *
     * @memberof Geom
     */
    stopDragFeatures() {
        this._geometry.config("draggable", false);
    }

    /**
     *获取覆盖物符号(HTML覆盖物不支持)
     *
     * @memberof Geom
     */
    getSymbol() {
        return this._geometry.getSymbol();
    }

    /**
     *设置一个新符号以设置覆盖物样式(HTML覆盖物不支持)
     * @param {Object} symbol 新符号样式
     * @return {Geom}  返回修改后的覆盖物对象
     * @memberof Geom
     */
    setSymbol(symbol) {
        this._geometry.setSymbol(symbol);
        return this;
    }

    /**
     *更新覆盖物图形的当前符号(HTML覆盖物不支持)
     *
     * @param {Object} symbol 当前覆盖物图形已有的符号
     * @return {Geom}  返回修改后的覆盖物对象
     * @memberof Geom
     */
    updateSymbol(symbol) {
        this._geometry.updateSymbol(symbol);
        return this;
    }

    /**
     *获取覆盖物属性(HTML覆盖物不支持)
     *
     * @return {Object} 覆盖物的属性
     * @memberof Geom
     */
    getProperties() {
        return this._geometry.getProperties();
    }

    /**
     *为覆盖物设置新属性(HTML覆盖物不支持)
     *
     * @param {Object} properties 覆盖物的新属性
     * @return {Geom} 修改后的覆盖物对象
     * @memberof Geom
     */
    setProperties(properties) {
        this._geometry.setProperties(properties);
        return this;
    }

    /**
     *将覆盖物放在顶部(HTML覆盖物不支持)
     *
     * @return {Geom} 修改后的覆盖物对象
     * @memberof Geom
     */
    bringToFront() {
        this._geometry.bringToFront();
        return this;
    }

    /**
     *将覆盖物放在后面(HTML覆盖物不支持)
     *
     * @return {Geom} 修改后的覆盖物对象
     * @memberof Geom
     */
    bringToBack() {
        this._geometry.bringToBack();
        return this;
    }

    /**
     *按给定的偏移量移动覆盖物(HTML覆盖物不支持)
     *
     * @param {Number} x x偏移
     * @param {Number} y y偏移
     * @return {Geom} 修改后的覆盖物对象
     * @memberof Geom
     */
    translate(x, y) {
        this._geometry.translate(x, y);
        return this;
    }

    /**
     *闪烁覆盖物图形
     *
     * @param {Number} intervalopt 闪烁间隔,以毫秒为单位(毫秒)
     * @param {Number} countopt 闪烁次数
     * @param {Function} cbopt Flash结束时的回调函数
     * @param {*} contextopt 上下文信息
     * @return {Geom} 覆盖物对象
     * @memberof Geom
     */
    flash(intervalopt, countopt, cbopt, contextopt) {
        this._geometry.flash(intervalopt, countopt, cbopt, contextopt);
        return this;
    }

    /**
     *显示覆盖物
     *
     * @return {Geom} 覆盖物对象
     * @memberof Geom
     */
    show() {
        this._geometry.show();
        return this;
    }

    /**
     *隐藏覆盖物
     *
     * @return {Geom} 覆盖物对象
     * @memberof Geom
     */
    hide() {
        this._geometry.hide();
        return this;
    }

    /**
     *覆盖物是否可见
     *
     * @return {boolean} 是否可见
     * @memberof Geom
     */
    isVisible(){
        return this._geometry.isVisible()
    }

    /**
     *覆盖物是否可见
     *
     * @return {Boolean}
     * @memberof Geom
     */
    isVisible() {
        return this._geometry.isVisible();
    }

    /**
     *获取覆盖物层级,默认是0(HTML覆盖物不支持)
     *
     * @return {Number}
     * @memberof Geom
     */
    getZIndex() {
        return this._geometry.getZIndex();
    }

    /**
     *设置覆盖物层级(HTML覆盖物不支持)
     *
     * @param {Number} num
     * @return {Geom} 覆盖物对象
     * @memberof Geom
     */
    setZIndex(num) {
        this._geometry.setZIndex(num);
        return this;
    }

    /**
     *获取覆盖物坐标
     *
     * @return {Array} 覆盖物的坐标
     * @memberof Geom
     */
    getCoordinates() {
        let coordinate = this._geometry.getCoordinates();
        if (Array.isArray(coordinate)) {
            return coordinate.map(function (val) {
                if (Array.isArray(val)) {
                    return val.map((item) => {
                        return [item.x, item.y];
                    });
                } else {
                    return [val.x, val.y];
                }
            });
        } else {
            return [coordinate.x, coordinate.y];
        }
    }

    /**
     *修改覆盖物坐标
     *
     * @param {Array} array 覆盖物坐标
     * @return {Geom} 覆盖物对象
     * @memberof Geom
     */
    setCoordinates(array) {
        this._geometry.setCoordinates(new maptalks.Coordinate(array));
        return this;
    }
    /**
     *获取矩形宽度(仅限矩形)
     *
     * @return {*}
     * @memberof Geom
     */
    getWidth() {
        return this._geometry.getWidth();
    }

    /**
     *设置矩形宽度(仅限矩形)
     *
     * @param {*} num
     * @return {*}
     * @memberof Geom
     */
    setWidth(num) {
        this._geometry.setWidth(num);
        return this;
    }

    /**
     *获取矩形高度(仅限矩形)
     *
     * @return {*}
     * @memberof Geom
     */
    getHeight() {
        return this._geometry.getHeight();
    }

    /**
     *设置矩形高度(仅限矩形)
     *
     * @param {*} num
     * @return {*}
     * @memberof Geom
     */
    setHeight(num) {
        this._geometry.setHeight(num);
        return this;
    }
    /**
     *获取圆的半径
     *
     * @return {Number} 圆形的半径
     * @memberof Geom
     */
    getRadius() {
        return this._geometry.getRadius();
    }

    /**
     *设置圆的半径
     *
     * @param {Number} num 半径
     * @return {Geom} 圆形覆盖物对象
     * @memberof Geom
     */
    setRadius(num) {
        this._geometry.setRadius(num);
        return this;
    }

    /**
     *设置覆盖物的options与默认options合并
     *
     * @param {Object} options 覆盖物options
     * @return {Geom} 覆盖物对象
     * @memberof Geom
     */
    setOptions(options) {
        this._geometry.setOptions(options);
        //触发页面元素重新渲染
        this.updateSymbol({});
        return this;
    }

    /**
     *获取html元素的内容
     *
     * @return {String} 内容
     * @memberof Geom
     */
    getContent() {
        if (this.type === "HtmlPoint") {
            return this._geometry.getContent();
        }
    }

    /**
     *设置html元素的内容
     *
     * @param {String} content HTMLElement
     * @return {Geom} 覆盖物对象
     * @memberof Geom
     */
    setContent(content) {
        if (this.type === "HtmlPoint") {
            this._geometry.setContent(content);
            return this;
        }
    }

    /**
     *覆盖物的动画声明(HTML覆盖物不支持)
     *
     * @param {*} styles 动画样式
     * @param {*} options 动画选项
     * @param {Number} options.duration 时间
     * @param {Number} options.startTime 动画开始时间以毫秒为单位
     * @param {string} options.easing 动画缓动样式 in, out, inAndOut, linear, upAndDown
     * @param {boolean} options.repeat  动画是否循环
     * @param {*} step 动画步进过程中的回调,参数为当前动画状态
     * @memberof Geom
     */
    animate(styles, options, step) {
        let h = step
            ? (f) => {
                  step(f.state.playState);
              }
            : "";
        this._animate = this._geometry.animate(styles, options, h);
        this._symbol = this.getSymbol()
    }

    /**
     *开始动画播放(如果有)
     *
     * @memberof Geom
     */
    animatePlay() {
        if (this._animate) {
            this._animate.play();
        }
    }

    /**
     *暂停动画播放(如果有)
     *
     * @memberof Geom
     */
    animatePause() {
        if (this._animate) {
            this._animate.pause();
        }
    }

    /**
     *取消本次动画播放(如果有)并准备再次播放
     *
     * @memberof Geom
     */
    animateCancel() {
        if (this._animate) {
            this._animate.cancel();
        }
    }

    /**
     *完成动画播放(如果有),无法再播放
     *
     * @memberof Geom
     */
    animateFinish() {
        if (this._animate) {
            this._animate.finish();
        }
        this.updateSymbol(this._symbol)
    }

    /**
     *线,面类型的展开动画(声明后自动显示展开动画)
     *
     * @param {*} options 动画选项
     * @param {*} options.duration  动画时间
     * @param {*} options.easing  动画缓动样式 in, out, inAndOut, linear, upAndDown
     * @param {*} callback 动画步进过程中的回调,参数为当前动画状态和当前动画步进坐标
     * @memberof Geom
     */
    animateShow(options, callback) {
        let h = callback
            ? (f, coordinate) => {
                  callback(f.state.playState, [coordinate.x, coordinate.y]);
              }
            : "";
        this._animate = this._geometry.animateShow(options, h);
    }
}
export default Geom;