Andrzej S.
Andrzej S.

Reputation: 33

OpenLayers 3 WMS Layer - Misplaced tiles in EPSG:2180 projection

I'm trying to display map of Poland using OpenLayers 3. I need it to be in projection EPSG:2180. Ewerything is ok until I switch the projection.

This works fine:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://openlayers.org/en/v3.7.0/build/ol.js" type="text/javascript"></script>
<script src="proj4js/proj4-src.js" type="text/javascript"></script>
<script>

proj4.defs('EPSG:2180', "+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 +y_0=-5300000 +ellps=GRS80 +units=m +no_defs");

function init()
{
    var p = ol.proj.get('EPSG:3857');

    var mapTiles = new ol.Map({
        target: 'map',
        renderer: 'canvas',
        layers: [
            new ol.layer.Tile({
                source: new ol.source.TileWMS({
                    url: 'http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer',
                    params: {
                        'LAYERS': 'Raster'
                    }
                }),
                isBaseLayer: true,
                projection: p
            })
        ],

        view: new ol.View({
            center: ol.proj.transform([19, 52], 'EPSG:4326', 'EPSG:3857'),
            zoom: 6,
            projection: p
        })
    });
}

</script>
</head>
<body onload="init()">
    <div id="map"></div>
</body>
</html>

When i switch projection to EPSG:2180 tiles are misplaced.

Code with EPSG:2180

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<script src="http://openlayers.org/en/v3.7.0/build/ol.js" type="text/javascript"></script>
<script src="proj4js/proj4-src.js" type="text/javascript"></script>
<script>

proj4.defs('EPSG:2180', "+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 +y_0=-5300000 +ellps=GRS80 +units=m +no_defs");

function init()
{
    var p = ol.proj.get('EPSG:2180');

    var mapTiles = new ol.Map({
        target: 'map',
        renderer: 'canvas',
        layers: [
            new ol.layer.Tile({
                source: new ol.source.TileWMS({
                    url: 'http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer',
                    params: {
                        'LAYERS': 'Raster',
                        'CRS': 'EPSG:2180'
                    }
                }),
                isBaseLayer: true,
                projection: p
            })
        ],

        view: new ol.View({
            center: ol.proj.transform([19, 52], 'EPSG:4326', 'EPSG:2180'),
            zoom: 6,
            projection: p
        })
    });
}

</script>
</head>
<body onload="init()">
    <div id="map"></div>
</body>
</html>

Any idea what is the problem?

https://jsfiddle.net/b2L6qppd/

Upvotes: 3

Views: 1473

Answers (1)

Jakub Bobrowski
Jakub Bobrowski

Reputation: 46

I have add one element - it prevent of axes problem.

            params: {
                'LAYERS': 'Raster',
                'CRS': 'EPSG:2180',
                'VERSION': '1.1.1'
            }

try with this: jsfiddle.net/b2L6qppd/2/

Upvotes: 3

Related Questions