I have some experiences with OpenLayers 2 now I want to combine OpenLayers 3 and MapServer and I tried the below configs and code on OpenLayers and MapServer but the OpenLayers loads white and blank tiles.
Software I used:
MapServer : MapServer version 6.0.3 (MS4W 3.0.6)
OpenLayers : OpenLayers v3.1.1
DataBase: PostgreSQL v9.4 + PostGIS v2.1.5
mapfile code:
MAP
NAME "DEMO"
IMAGETYPE PNG
EXTENT -97.238976 41.619778 -82.122902 49.385620
SIZE 400 300
IMAGECOLOR 255 255 255
WEB
TEMPLATE "template.html"
METADATA
"wms_title" "WMS Demo Server"
"wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=/ms4w/apps/tutorial/htdocs/example1-4.map&"
"wms_srs" "EPSG:4326"
"wms_enable_request" "GetCapabilities GetMap GetFeatureInfo"
END
END
PROJECTION
"init=epsg:4326"
END
LAYER
NAME "curves_poly"
STATUS DEFAULT
TYPE POLYGON
CONNECTIONTYPE postgis
CONNECTION "user=postgres password=postgres dbname=map host=localhost port=5432"
DATA 'geodata from geo_data using SRID=-1 using unique id'
CLASS
STYLE
COLOR 255 0 0
OUTLINECOLOR 255 255 255
END
END
END
END
OpenLayers Code:
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="ol.css" type="text/css">
<script src="ol.js" type="text/javascript"></script>
<style>
.map {
width: 600px;
height: 400px;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<script>
var layers = [
new ol.layer.Image({
extent: [373204.15,4128154.94,377063.25,4131409.17],
source: new ol.source.ImageWMS({
url: 'http://localhost:88/cgi-bin/mapserv.exe?map=D:/ms4w/workshop/test2.map',
params: {
'LAYERS': 'curves_poly',
'BBOX': '373204.15,4128154.94,377063.25,4131409.17',
'WIDTH': '800',
'HEIGHT': '500',
'FORMAT': 'image/png'
},
serverType: 'mapserver'
})
})
];
var map = new ol.Map({
layers: layers,
target: 'map',
view: new ol.View({
zoom: 7
})
});
</script>
</body>
</html>
DataBase Data Sample:
"POLYGON((51.4561496155646 36.661039635849,51.456233084707 36.6610173775795,51.4562711873731 36.6609998347394,51.4562694463067 36.6609886494578,51.4562997261622 36.6609830019377,51.4562961094751 36.6609683576276,51.4563034085495 36.660967070288,51.45629725248 36.6609470312967,51.4562890550895 36.6609477820871,51.456284912788 36.6609307211027,51.4562652307292 36.6609345250491,51.4562645637318 36.6609329896687,51.4561295112782 36.6609608823809,51.4561496155646 36.661039635849))"
"POLYGON((51.4560077749321 36.6610492398268,51.456032921871 36.6610482700056,51.4560321045462 36.6610383216287,51.4560665757203 36.6610352841492,51.4560599866736 36.6609930522129,51.4560041201758 36.6609975905458,51.4560056199772 36.6610096133343,51.456000163107 36.6610104058986,51.4560001852903 36.6610141668142,51.4559968878491 36.6610141794386,51.4559966831994 36.6610289961481,51.4559929511242 36.6610471384228,51.4560077467405 36.6610474955589,51.4560077749321 36.6610492398268))"
"POLYGON((51.455972399246 36.6611958234988,51.4560402329409 36.661169844388,51.4561168280393 36.66113250902,51.456221273358 36.6612562524741,51.4564172811864 36.6611619815264,51.4565972917386 36.6610702234354,51.4564617373872 36.660906248836,51.4563196574924 36.660980670059,51.4559628056602 36.6611571594235,51.455972399246 36.6611958234988))"
"POLYGON((52.788958 29.858053,52.788851 29.857997,52.788729 29.858142,52.788827 29.858208,52.788958 29.858053))"
"POLYGON((51.4564088660334 36.6611194059305,51.4565077726914 36.6611080494817,51.4565062361454 36.6610953128637,51.4565436009946 36.6610892586003,51.4565220936502 36.6610035799526,51.4563930473991 36.6610117200147,51.4564088660334 36.6611194059305))"
I correct extent in map file and i got a preview in openlayers template:
EXTENT 48 25.973848 56.535645 37.836686
The preview :
![Mapserver Internal OpenLayers Preview][1]But I still don't know how to use it as a tile server?