1

I am new to OpenLayers and I was making a demo application which displays administrative areas based on zoom level. I am getting an error Cannot read property 'register' of undefined in map.events.register("zoomend", this, function(){});.

Here is my code:

var admin1 = new ol.layer.Tile({
title: 'Country Map with administrative level 1',
source: new ol.source.TileWMS({
  url: 'http://localhost:8080/geoserver/abc/wms',
  params: {
    LAYERS:'abc:abc',
    TILED:true,
    transparent: true,
    format:'image/png'
  }
})
});
var view = new ol.View({
   projection: 'EPSG:4326',
   center: [85.0583449970001, 28.006449365],
   zoom: 6
});
var map = new ol.Map({
    target: 'map',
    layers: [admin1],
    view: view
  }); 
Window.map = map;

map.events.register("zoomend", this, function(){
  var zLevel = map.getZoom();     

    if( zLevel == 13 || zLevel == 14 || zLevel == 15  )
    {
        admin1.setVisibility(false);
    }
});
Madan
  • 11
  • 3

0 Answers0