I try to print my geoserver layer on my website. My application and my geoserver instance are running on separate tomcats and use different ports.
I have noticed in my Firefox' network inspector logs that appropriate png images are downloaded from geoserver. I noticed http requests such as:
http://localhost:8081/geoserver/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=graves:graves&TILED=true&STYLES=graves&CQL_FILTER=not(id < 0)&WIDTH=256&HEIGHT=256&CRS=EPSG:2001&BBOX=4762.7,-7860.5599999999995,4905.6900000000005,-7717.57
and when I use such a link in a browser it gives me a png with some of my elements. However my application does not print any of the elements.
My code is somehow like that:
var projection = new ol.proj.Projection({
code: 'EPSG:2001',
extent: [4762.7, -8003.55, 4950.55, -7717.57],
units: 'm'
});
ol.proj.addProjection(projection);
var mapcenter = [4880, -7930];
var mapzoom = 2;
var view = new ol.View({
center: mapcenter,
projection: projection,
zoom: mapzoom
});
var wmsSource = new ol.source.TileWMS({
url: 'http://localhost:8081/geoserver/wms',
params: {'LAYERS': 'graves:graves', 'TILED': true, 'STYLES': 'graves' },
serverType: 'geoserver',
crossOrigin: 'anonymous'
});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: wmsSource
})
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}),
view: view });
Of course I have some div as well:
<div id="map" class="map" style="width: 1030px; height: 650px;border: 1px solid #0066CC;margin-bottom: 10px;"></div>
What may be the cause of this problem? I can see no error on Firefox javascript console. I was totally stuck.
Best Regards
I have finally solved the issue. The problem was in the line within tileWMS:
crossOrigin: 'anonymous'
After removing it everything works as expected. Thank you all for your support!