I am getting the following error in the yellow background below. Can anyone explain why i get this?
I am not using any bundler i include the ol.js
javascript file in the footer
Group.js:209 Uncaught TypeError: t.getLayerStatesArray is not a function
at Group.js:209
at e.forEach (Collection.js:137)
at e.getLayerStatesArray (Group.js:208)
at e.renderFrame_ (PluggableMap.js:1198)
at e. (PluggableMap.js:191)
<script>
var wmsSource = new ol.source.ImageWMS({
url: 'http://webip/geoserver/wms',
params: {'LAYERS': 'sweb:Streets'},
serverType: 'geoserver',
crossOrigin: 'anonymous'
});
var wmsLayer = new ol.source.Image({
source: wmsSource
});
var baseLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
target: 'map',
layers: [baseLayer,wmsLayer],
view: new ol.View({
center: ol.proj.fromLonLat([33.21441650390625, 35.03449433167977]),
zoom: 10
})
});
map.on('click', function(evt){
console.log(ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326'));
});
</script>
Best Answer
401 suggests authentication is needed so you will need to load using xhr with appropriate http headers (including cross origin if required) set via a customer loader. See https://github.com/openlayers/openlayers/issues/4213#issuecomment-145149625 That link refers to TileWMS, but it will be very similar for Image WMS: