Tag Archives: openlayers

openlayers — Cannot read property ‘slice‘ of null—Map cannot be loaded

When loading the GeoServer WMS service, the map could not be loaded with an error:

View.js:1552 Uncaught TypeError: Cannot read property 'slice' of null
at xs (View.js:1552)
at e.applyOptions_ (View.js:378)
at new e (View.js:330)
at test.html:115

My code to load the service is:


		var imagery = new ol.layer.Image({
	            source: new ol.source.ImageWMS({
	                ratio: 1,
	                url: 'http://localhost:8999/geoserver/dem/wms',
	                params: {
	                    'FORMAT': 'image/jpeg',//'image/jpeg',//
	                    'VERSION': '1.1.1',
	                    "STYLES": '',
	                    "LAYERS": 'dem:hhu_fill_dem',
	                    "exceptions": 'application/vnd.ogc.se_inimage',
	                },
	                crossOrigin:''
	            })
	    });
		var projection = new ol.proj.Projection({
		            code: 'EPSG:3857',
		            units: 'm',
		            global: true
		    });

       	var map = new ol.Map({
            controls: ol.control.defaults({
                attribution: false
            }).extend([mousePositionControl]),
            target: container,
            layers: [
                imagery
            ],
            view: new ol.View({
                projection: projection,
            }),
            
        });

The error is loading the view View: new ol.view ({projection: projection}), . After eliminating the problem step by step, we find that the problem is in:

var projection = new ol.proj.Projection({
		            code: 'EPSG:3857',
		            units: 'm',
		            global: true
		    });

There is a problem with Global: true , and the default attribute of Global is false . Comment it out, and the map can be loaded normally if no error is reported

Whether the projection is valid for the whole globe.

However, in the source code of GeoServer loading the service, global is set to true and loaded successfully. It is not clear why??