未捕获的TypeError:无法读取未定义的属性“输入" [英] Uncaught TypeError: Cannot read property 'Input' of undefined

查看:242
本文介绍了未捕获的TypeError:无法读取未定义的属性“输入"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从OpenLayers v3.0.0更改为3.19.1,现在以下行不起作用:

I changed from OpenLayers v3.0.0 to 3.19.1 and now following line doesn't work:

var visible = new ol.dom.Input(document.getElementById('visible'));

切换回旧版本,一切正常.怎么了?

Switching back to the older version, everything is ok. What's going wrong?

推荐答案

ol.dom.Input在3.5.0中已删除

ol.dom.Input was removed in 3.5.0

已删除实验性ol.dom.Input组件.如果需要将dom Input元素的状态与ol.Object同步,则可以使用更改事件的侦听器来实现.例如,您可以将复选框类型输入的状态与图层的可见性进行绑定,如下所示:

The experimental ol.dom.Input component has been removed. If you need to synchronize the state of a dom Input element with an ol.Object, this can be accomplished using listeners for change events. For example, you might bind the state of a checkbox type input with a layer's visibility like this:

var layer = new ol.layer.Tile();
var checkbox = document.querySelector('#checkbox');

checkbox.addEventListener('change', function() {
  var checked = this.checked;
  if (checked !== layer.getVisible()) {
    layer.setVisible(checked);
  }
});

layer.on('change:visible', function() {
  var visible = this.getVisible();
  if (visible !== checkbox.checked) {
    checkbox.checked = visible;
  }
});

这篇关于未捕获的TypeError:无法读取未定义的属性“输入"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆