IControl

所有控件都需要实现该接口。


示例

// 用ES6标准实现控件类
class HelloWorldControl {
    onAdd(map) {
        this._map = map;
        this._container = document.createElement('div');
        this._container.className = 'wmapgl-ctrl';
        this._container.textContent = 'Hello, world';
        return this._container;
    }

    onRemove() {
        this._container.parentNode.removeChild(this._container);
        this._map = undefined;
    }
}

// 用ES5标准实现控件的原型类
function HelloWorldControl() { }

HelloWorldControl.prototype.onAdd = function(map) {
    this._map = map;
    this._container = document.createElement('div');
    this._container.className = 'wmapgl-ctrl';
    this._container.textContent = 'Hello, world';
    return this._container;
};

HelloWorldControl.prototype.onRemove = function () {
     this._container.parentNode.removeChild(this._container);
     this._map = undefined;
};

方法

方法 返回值 描述
getDefaultPosition() 获取控制的默认位置
onRemove(map:Map) 移除控件时调用该方法
onAdd(map:Map) 添加到地图上时调用该方法

results matching ""

    No results matching ""