1

I'm currently trying to create a map based on GeoServer and OpenLayers 3.

My main issue at this point is the coordinate system. I want to use EPSG:25832 (EUREF89 Zone 32).

This is how far I´ve got:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="http://openlayers.org/en/v3.18.2/build/ol.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.12/proj4.js"></script>
<script src="http://epsg.io/25832.js"></script>
<script type="text/javascript">

window.onload = function() 
{
var euref89z32proj = ol.proj.get('EPSG:25832');
var osmLayer = new ol.layer.Tile(
{
    source: new ol.source.OSM()
})

var format = 'image/png';
var linjetest = new ol.layer.Image({
    source: new ol.source.ImageWMS({
        ratio: 1,
        url: 'http://localhost:8080/geoserver/postgre/wms',
        params: {'FORMAT': format,
                'VERSION': '1.1.1',  
                STYLES: '',
                LAYERS: 'postgre:linjetest',
        }
    })
});

var map = new ol.Map({
target: 'map1',
layers: [
    linjetest
],
view: new ol.View({
center: ol.proj.fromLonLat([10.09, 56.45]),
    maxExtent: new ol.extent.boundingExtent(384015, 5846682, 516991, 5931295),
    zoom: 15
    })
});

var mousePosition = new ol.control.MousePosition({
        coordinateFormat: ol.coordinate.createStringXY(5),
        projection: euref89z32proj,
        target: document.getElementById('location'),
        undefinedHTML: '&nbsp;'
      });
 map.addControl(mousePosition); 
}

When I move the mouse around in the map correct coordinates are displayed, but when I use Chromes debugger and look at the the network tab, the URL to GeoServer is based on EPSG:3587 coordinates. Is it possible to configure OpenLayers to use EPSG:25832 instead?

1

Stumbled upon the solution myself. I just needed to add projection to the layer like this:

    var linjetest = new ol.layer.Image({
    source: new ol.source.ImageWMS({
        ratio: 1,
        url: 'http://localhost:8080/geoserver/postgre/wms',
        params: {'FORMAT': format,
                'VERSION': '1.1.1',  
                STYLES: '',
                LAYERS: 'postgre:linjetest',
        },
        projection: euref89z32proj
    })
});
0

You need to add the projection in view of your map object, as below:

var map = new ol.Map({
target: 'map1',
layers: [
    linjetest
],
view: new ol.View({
projection: euref89z32proj,
center: ol.proj.fromLonLat([10.09, 56.45]),
    maxExtent: new ol.extent.boundingExtent(384015, 5846682, 516991, 5931295),
    zoom: 15
    })
});
  • Before I add projection:euref89z32proj the URL contains SRS=EPSG:3857 and BBOX=1121443.667167902,7647569.032526296,1124983.657040359,7649479.958233425 - After adding projection:euref89z32proj the SRS changes to EPSG:25832 but the BBOX argument is the same so geoserver creates a blank image. Any suggestions to why the BBOX argument isn´t projected rigth? – K.M.Rasmussen Oct 27 '16 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.