[GIS] GeoWebCache and OpenLayers horizontal resolution error

geoservergeowebcacheopenlayers-2

I have a mapping application (the Arne G. Brekke Bygdebok Collection) which uses OpenLayers to load map tiles from a GeoWebCache server operated by the Statens Kartverk (Norwegian Mapping Authority).

It's worked nicely for two years, but this morning the tiles all load as pink, with errors like "400: Requested horizontal resolution: 0.0439453125 , best match: 0.03333333333333333 exceeds 10% threshold. Perhaps the client is configured with an incorrect set of scales (resolutions), or the DPI setting is off compared to the one in GWC?" if you view the image directly.

Here is a test case I worked out demonstrating the problem:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Arne G. Brekke Bygdebok Collection</title>
    <style type="text/css" media="screen">
        #map {
          border: 1px solid #BBBBBB;
          height: 425px;
          width: 675px;
        }
    </style>
</head>
<body>

<h2>Arne G. Brekke Bygdebok Collection</h2>

<div id="map"></div>

<script src="http://openlayers.org/api/OpenLayers.js" type="text/javascript"> </script>
<script type="text/javascript">
var map, base;

function init(){

    map = new OpenLayers.Map("map", {controls: [], projection: new OpenLayers.Projection('EPSG:4326')});

    base = new OpenLayers.Layer.WMS(
        "topo2 SK",
        "http://opencache.statkart.no/gatekeeper/gk/gk.open?",
        {layers: "topo2",format: 'image/jpeg'},
        {attribution:'Map: &copy;<a href="http://www.statkart.no/">Statens kartverk</a>'}
    );

    map.addLayer(base);

    map.setCenter(new OpenLayers.LonLat(17.0068359375, 62.9296875), 5);
}

window.onload = init;
</script>

</body>
</html>

That's the simplest test case I can work out for it. Based on that, OpenLayers generates URLs like this one (broken onto multiple lines for clarity):

http://opencache.statkart.no/gatekeeper/gk/gk.open
    ?LAYERS=topo2
    &FORMAT=image%2Fjpeg
    &SERVICE=WMS
    &VERSION=1.1.1
    &REQUEST=GetMap
    &STYLES=
    &SRS=EPSG%3A4326
    &BBOX=11.25,56.25,22.5,67.5
    &WIDTH=256
    &HEIGHT=256

How can I get it to work again? Bear in mind that I have zero control over the map server — I can only adjust the JavaScript on my end.

Best Answer

I guess that statkart.no GWC does not support EPSG:4326 projection

Try this:

<script type="text/javascript">
var map, base;

function init(){

    map = new OpenLayers.Map("map", {projection: new OpenLayers.Projection('EPSG:900913')});

    base = new OpenLayers.Layer.WMS(
        "topo2 SK",
        "http://opencache.statkart.no/gatekeeper/gk/gk.open?",
        {layers: "topo2"},
        {attribution:'Map: &copy;<a href="http://www.statkart.no/">Statens kartverk</a>'}
    );
    map.addLayer(base);
    map.zoomToMaxExtent();
}

window.onload = init;
</script>