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??
Read More:
- [Solved] uview u-sticky Error: Cannot read property ‘bottom‘ of null
- El-cascader error: Cannot read property’level’ of null
- VUE Echarts Loading Error TypeError: Cannot read property getAttribute of null?
- Vue ElementUI el-dropdown Error: Uncaught TypeError: Cannot read property ‘disabled‘ of null
- [Solved] Unreal Engine Error: Widget Blueprint could not be loaded because it derives from an invalid class
- Rendering Problems The following classes could not be instantiated: xml layout file could not be loaded
- cesium CLAMP_TO_GROUND Error Cannot read property ‘globe‘ of undefined
- [Solved] Neo4j error: Cannot merge the following node because of null property value for ‘casualty’
- How to Fix Word Opening Error: the resource dll cannot be loaded
- [Solved] Vue + uniapp Uncaught TypeError: Cannot read property ‘getters‘ of undefined
- Can’t read property ‘push’ of undefined [How to Solve]
- [Solved] Vue Error: Uncaught TypeError: Cannot read property ‘getters‘ of undefined
- [Solved] Parcel Package Error: Cannot read property ‘length‘ of undefined
- [Solved] TypeError: Cannot read property ‘indexOf‘ of undefined at VueComponent.resetFields
- [Solved] Echarts Error: Cannot read property ‘init‘ of undefined
- [Vue warn]: Error in render: TypeError: Cannot read property ‘xxxx’of undefined
- [Solved] Cannot read properties of undefined (reading ‘ajax‘); Cannot read property ‘ajax‘ of undefined
- Vue error in render: “typeerror: cannot read property ‘length’ of undefined”
- Vue Error in callback for immediate watcher “height”: “TypeError: Cannot read property ‘style’ of