如何在Openlayer 3 WMS(mapserver)中修改CRS?

时间:2017-05-01 10:29:09

标签: openlayers-3 mapserver

我正在使用Openlayer3通过MapServer WMS添加栅格图层。 加载页面时,CRS值在WMS URL中更改为3857。

使用Mapserver网址

http://localhost/cgi-bin/mapserv.exe?map=D:\地图服务器\ actualimage.map&安培; SERVICE = WMS&安培; VERSION = 1.3.0&安培; REQUEST =的GetMap&安培; LAYERS =古吉拉特&安培;花柱=安培; CRS = EPSG:32643&安培; BBOX = 361600.51891405135,2404154.8014285564, 366487.01241288986,2409041.294927395&安培; WIDTH = 800安培; HEIGHT = 500安培; FORMAT =图像/ PNG

openlayer正在请求以下网址

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=

解码为

http://localhost/cgi-bin/mapserv.exe?map=D:\地图服务器\ actualimage.map&安培; SERVICE = WMS&安培; VERSION = 1.3.0&安培; REQUEST =的GetMap&安培; FORMAT =图像/ PNG&安培; TRANSPARENT =真安培; LAYERS =古吉拉特&安培; CRS = EPSG:3857&安培; BBOX = 360378.8955393417,2402933.1780538466,367708.6357875995,2410262.918302105&安培; WIDTH = 1&安培; HEIGHT = 1&安培;花柱=

以下是Openlayer代码

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
            })
        });

1 个答案:

答案 0 :(得分:2)

除非您已将'EPSG:32643'注册为投影(例如,通过使用和配置proj4js),ol.proj.get('EPSG:32643')将返回null。如果您正确地注册了投影,OpenLayers会将您的WMS图层重新投影到视图投影('EPSG:3857'),您可能想要也可能不想要它。

要进行光栅重投影,请在这种情况下配置projection: 'EPSG:32643' on both your ol.source.ImageWMS and your ol。查看. Also note that the coordinates of the view's中心need to be in ``'EPSG:32643'