swaraj
swaraj

Reputation: 109

How to modify CRS in Openlayer 3 WMS (mapserver)?

I am using Openlayer3 to add a raster layer via MapServer WMS. When loading the page CRS value is changing to 3857 in the WMS URL.

Working Mapserver URL

http://localhost/cgi-bin/mapserv.exe?map=D:\mapserver\actualimage.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=Gujarat&STYLES=&CRS=EPSG:32643&BBOX=361600.51891405135,2404154.8014285564,366487.01241288986,2409041.294927395&WIDTH=800&HEIGHT=500&FORMAT=image/png

The openlayer is requesting the URL below

http://localhost/cgi-bin/mapserv.exe?map=D:%5Cmapserver%5Cactualimage.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=Gujarat&CRS=EPSG%3A3857&BBOX=360378.8955393417%2C2402933.1780538466%2C367708.6357875995%2C2410262.918302105&WIDTH=1&HEIGHT=1&STYLES=

decoded as

http://localhost/cgi-bin/mapserv.exe?map=D:\mapserver\actualimage.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=Gujarat&CRS=EPSG:3857&BBOX=360378.8955393417,2402933.1780538466,367708.6357875995,2410262.918302105&WIDTH=1&HEIGHT=1&STYLES=

Below is the Openlayer code

var layers = [
            new ol.layer.Image({
                extent: [361600.51891405135,2404154.8014285564,366487.01241288986,2409041.294927395],
                source: new ol.source.ImageWMS({
                    url: encodeURI('http://localhost/cgi-bin/mapserv.exe?map=D:\\mapserver\\actualimage.map'),
                    params: {
                        'LAYERS': 'Gujarat',
                        'CRS': 'EPSG:32643',
                        'BBOX': '361600.51891405135,2404154.8014285564,366487.01241288986,2409041.294927395',
                        'WIDTH': '800',
                        'HEIGHT': '500',
                        'FORMAT': 'image/png'
                    },
                    serverType: 'mapserver',
                    projection: ol.proj.get('EPSG:32643'),
                })
            })
        ];
        var map = new ol.Map({
            layers: layers,
            target: 'map',
            view: new ol.View({
                center: [361600.51891405135, 2404154.8014285564],
                zoom: 1
            })
        });

Upvotes: 0

Views: 1084

Answers (1)

ahocevar
ahocevar

Reputation: 5648

Unless you have registered 'EPSG:32643' as projection (e.g. by using and configuring proj4js), ol.proj.get('EPSG:32643') will return null. If you have the projection registered properly, OpenLayers will raster reproject your WMS layer to the view projection ('EPSG:3857'), which you may or may not want.

To go without raster reprojection, configure projection: 'EPSG:32643' on both yourol.source.ImageWMSand yourol.View. Also note that the coordinates of the view'scenterneed to be in ``'EPSG:32643' in this case.

Upvotes: 2

Related Questions