1

I am trying to include a mapserver WMS in Openlayers-3 using custom projection without proj4j.js, according to this. I have no image, no error message and Openlayers is getting mapserver .map according to debug tools, window network. enter image description here I suppose a problem of projection (?) but can't identify it.

<!doctype html>
 <html lang="en">
     <head>
      <style>
      #map {
        height: 256px;
        width: 512px;
  }
  .ol-attribution a{
    color: black;
  }
      </style>
<script src="http://openlayers.org/en/v3.17.1/build/ol.js" type="text/javascript"></script> 
<title>OpenLayers 3</title>
</head>
  <body>           
<div id="map"></div>
<script type="text/javascript"> 
  var map = new ol.Map({
    target: 'map',
    layers: [
      new ol.layer.Image({
        title: 'operations Inrap',
        source: new ol.source.ImageWMS({
          url: 'http://10.3.1.51:8080/cgi-bin/mapserv.exe?map=C:\OSGeo4W\apache\htdocs\fond_mapserver.map',
          params: {'LAYERS': 'Interrégions',
                    //'CRS': 'EPSG:2154',
                    'FORMAT': 'image/jpeg'},
          serverType: 'mapserver',
          extent: [93501.1, 6044342.00, 1248133.25, 7115784.50]
        })
      })
    ],
    view: new ol.View({
      projection: new ol.proj.Projection({
      code:'EPSG:2154',
      units: 'm'
        }),       
      center: [681845, 6606361],
      zoom:10
    }),
     controls: ol.control.defaults({
        attributionOptions: {
            collapsible: true
            }
        }), 
  });
</script>

1

try to declare your projection and add it to the ol namespace

   var projection = new ol.proj.Projection({
    code: 'EPSG:2154',
    extent: [-378305.81,6093283.21, 1212610.74,7186901.68],
    units: 'm'
  });
  ol.proj.addProjection(projection);

Then asign this projection to your view

.......
view: new ol.View({
      projection: projection,
..........
  • I just tried this way but get neither error message nor image. I can't see the difference between my code and the one I put in link :'(... – Leehan Aug 25 '16 at 7:28
  • the only diff is -->ol.proj.addProjection(projection); check this example -->openlayers.org/en/latest/examples/… – pavlos Aug 25 '16 at 8:17
  • Yes I saw that in this example and in the lines you wrote. And I have tested it unsuccessfully. In this link : openlayersbook.github.io/… it seems so "easy", but something is wrong in my code...Thx anw – Leehan Aug 25 '16 at 8:30
  • The example you refernce is based on a very old version of ol3. Better stick with the latest ol3 official examples as many changes on the projection's functionality has been made – pavlos Aug 25 '16 at 10:08
  • I have a doubt : the request sent to mapserver by openlayers begins with : 10.3.1.51:8080/cgi-bin/mapserv.exe?map=C:OSGeo4Wapachehtdocs%0Cond_mapserver.map&SERVICE=WMS &... I can't see the "/" between C: and OSGeo4W for example, neither the others ??! – Leehan Aug 25 '16 at 12:21

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.