1

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 Load White And Blank Tiles.

Sofware I Used:

  • Mapserver : MapServer version 6.0.3 (MS4W 3.0.6)

  • Openlayers : Openlayers v3.1.1

  • DataBase: PostgerSql 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

But I Still Don't Know How Use It As Tile Server?

  • Having your srid as -1 seems problematic to me? It should be 4326. Have you enabled logging on your postgresql database and look at the pg_log files to see what kind of queries map server is sending. That's what I do and then I test the query to see the bottleneck – LR1234567 Feb 15 '15 at 14:03
  • Can you guide me to do that? – MSS Feb 15 '15 at 14:06
1

I would try those steps:

  • Update the mapfile with a generic request for the layer ( i.e. DATA "geodata from geo_data");
  • Add EPSG:3857 in the METADATA (i.e. "wms_srs" "EPSG:4326 EPSG:3857"); this is the default SRS used by OL3.
  • Test the WMS service in a Desktop application and request the layer in EPSG:3857.
  • Thanks @doktoreas . How Can I Test The WMS Server In A Desktop App (Which App?)? – MSS Feb 16 '15 at 4:17
  • If I Write Request For Layer As "geodata from geo_data" I Would An Error Like It: msDrawMap(): Image handling error. Failed to draw layer named 'curves_poly'. msPostGISLayerWhichShapes(): Query error. Error executing query: ERROR: column "oid" does not exist LINE 1: ...nary(ST_Force_2D("geodata"),'NDR'),'hex') as geom,"oid" from... – MSS Feb 16 '15 at 4:23
  • Keep then the "unique id". – user30184 Feb 16 '15 at 13:05
  • @MSS QGIS or gvSIG. Both support WMS layers – doktoreas Feb 17 '15 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.