OpenLayers map.events.register抛出TypeError

时间:2015-10-08 10:29:45

标签: javascript openlayers-3

我需要在OpenLayers 3中看到我的地图事件,但我的JavaScript不起作用。

这是我的代码:

var map = new ol.Map({
  layers: [raster, vector],
  target: 'map',
  view: new ol.View({
            projection: 'EPSG:900913',
            center: [-110000, 4600000],
            zoom:5
        })
});
 map.events.register("zoomend", this, function (e) {
    if (map.getZoom() === this.mapMaxZoom) {
        // Don't cluster at this level. No matter what.
        this.vector.strategies[0].threshold = 1000;
        console.log("setting the clustering strategy to 1000");
    }
});

控制台输出:

Uncaught TypeError: Cannot read property 'register' of undefined

请帮帮我。

1 个答案:

答案 0 :(得分:0)

尝试将map.on()与'moveend'事件一起使用,如下所示:

map.on('moveend', function(e) {...});

有关完整示例,请参阅以下内容:

http://openlayers.org/en/v3.9.0/examples/moveend.html