I've an OpenLayers map in html that use WMS layers from a MapServer (in a docker) and the layer come from PostGIS.
When I'm on the map and drag the map, after two or three seconds the map goes back to the left
and the weirdest thing : Even if I zoom in, the scalebar change but my map still a the same scale
When I use the openlayers template for mapserver (something like http://127.0.0.1/?map=/etc/mapserver/mapfile.map&layer=rail&mode=browse&template=openlayers), I've no problem to drag and zoom in.
I've this problem with PostGIS layer and also spatialite layer (so I guess for all types of wms)
Any Ideas ? Codes below
EDIT1 when I drag the scale is already changing, I think it's a projection problem but I can't find where
<meta charset="UTF-8">
<!Doctype html>
<html>
<head>
<title>
map
</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/css/ol.css" type="text/css">
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/build/ol.js"></script>
<style>
.map{
height: 400px;
width: 50%;
}
</style>
</head>
<body>
<h2>My Map</h2>
<div id="map" class="map"></div>
<script type="text/javascript">
var projection = new ol.proj.Projection({
code: 'EPSG:31370',
units: 'm'
});
var couche_wms= new ol.layer.Image({
source: new ol.source.ImageWMS({
url:'http://127.0.0.1/?map=/etc/mapserver/mapfile.map',
params:{
'LAYERS':'reg + rail',
'MODE':'map',
'TRANSPARENT' : 'true',
'FORMAT': 'image/png',
'tiled': 'true'
},
serverType: 'mapserver',
extent: [140000, 160000, 160000, 180000]
})
})
var map = new ol.Map({
renderer: 'webgl',
controls: ol.control.defaults().extend([
new ol.control.MousePosition({
coordinateFormat: ol.coordinate.createStringXY(0),
className:'custom-mouse-position',
undefinedHTML:' '
}),
new ol.control.ScaleLine()
]),
layers :[couche_wms],
target: 'map',
view: new ol.View({
projection: projection,
zoom: 2,
center: [150000,170000],
})
});
</script>
</body>
</html>
Here is my Mapfile
MAP
IMAGETYPE PNG
EXTENT 140000 160000 160000 180000
SIZE 600 600
DEBUG ON
PROJECTION
"init=EPSG:31370"
END
WEB
METADATA
"wms_title" "WMS Server Demonstration"
"wms_onlineresource" "http://127.0.0.1/?map=/etc/mapserver/mapfile.map"
"wms_srs" "EPSG:31370"
"wms_enable_request" "*"
END
END
LAYER
NAME StreetSurface
TYPE POLYGON
CONNECTIONTYPE ogr
CONNECTION "UrbAdmSpatialite.sqlite"
DATA "select geometry from urb_a_ss"
STATUS ON
CLASS
NAME "street_surfaces"
STYLE
COLOR 95 196 95
END
END
END
LAYER
NAME reg
TYPE LINE
CONNECTIONTYPE POSTGIS
CONNECTION "connectionstring"
DATA "geom from region using unique id using srid=31370"
STATUS ON
CLASS
NAME "Test"
STYLE
COLOR 0 0 0
END
END
END
LAYER
NAME bu
TYPE POLYGON
CONNECTIONTYPE POSTGIS
CONNECTION "connectionstring"
DATA "geom from bu using unique id using srid=31370"
STATUS ON
CLASS
NAME "Test"
STYLE
COLOR 0 0 0
END
END
END
LAYER
NAME rail
TYPE LINE
CONNECTIONTYPE POSTGIS
CONNECTION "connectionstring"
DATA "geom from rail using unique id using srid=31370"
STATUS ON
CLASS
NAME "Test"
STYLE
COLOR 194 118 222
END
END
END
END
GET http://127.0.0.1/?map=/etc/mapserver/mapfile.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=reg&CRS=EPSG:31370&STYLES=&WIDTH=944&HEIGHT=400&BBOX=149668.125,169859.375,150331.875,170140.625