我已经构建了一个自定义控件,并将其添加到我的地图中,如下所示:
const BoundingBox = (function (Control) {
function BoundingBox(optOptions) {
const options = optOptions || {};
const button = document.createElement('button');
button.innerHTML = '[]';
const element = document.createElement('div');
element.className = 'bounding-box ol-unselectable ol-control';
element.appendChild(button);
Control.call(this, {
element,
target: options.target,
});
button.addEventListener('click', this.handleBoundingBox.bind(this), false);
}
if (Control) BoundingBox.__proto__ = Control;
BoundingBox.prototype = Object.create(Control && Control.prototype);
BoundingBox.prototype.constructor = BoundingBox;
BoundingBox.prototype.handleBoundingBox = function handleBoundingBox() {
this.getMap().addInteraction(extent);
};
return BoundingBox;
}(Control));接下来,在初始化地图时,我将该控件添加到地图中。这工作得很好。现在,我正在尝试找到一种方法来关闭BoundingBox控件。我想我可以使用.removeInteraction()方法。然而,我不确定这是否正确。另外,应该在单独的函数中应用还是在我的BoundingBox控件中应用?
发布于 2020-10-22 03:53:47
我可以通过检查ol/interaction/ value的属性并将active属性的值设置为false来实现这一点。
extent.setProperties({ active: false });https://stackoverflow.com/questions/64451402
复制相似问题