Uncaught TypeError: Cannot read property 'Input' of undefined

纵然是瞬间 提交于 2019-12-25 18:35:14

问题


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?


回答1:


ol.dom.Input was removed in 3.5.0

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;
  }
});


来源:https://stackoverflow.com/questions/40808639/uncaught-typeerror-cannot-read-property-input-of-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!