0

I have successfully combined mapserver and openlayers-3 in a custom projection, using proj4 library. As soon as I add osm layer, I can't see the mapserver layer anymore, even if it is the last to be called. Is it a problem of projection ? I have read that osm data can be reprojected now since OL3 3.11.

<!doctype html>
<html lang="en">
 <head>
 <link rel="stylesheet" href="http://openlayers.org/en/v3.17.1/css/ol.css"     type="text/css">
<style>
   #map {
    height: 256px;
    width: 512px;
   }
</style>
<script src="/proj4js-2.3.14/dist/proj4.js" type="text/javascript"></script>
<script src="http://openlayers.org/en/v3.17.1/build/ol.js" type="text/javascript"></script>
<title>OpenLayers 3</title>

proj4.defs("EPSG:2154","+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m   +no_defs");

  var map = new ol.Map({
    target: 'map',
    controls: ol.control.defaults({
        attributionOptions: ({
            collapsible: false //ceci ne fonctionne QUE si un fond OSM est appelé !!
                })
            }).extend([
        new ol.control.ScaleLine(),
        new ol.control.MousePosition({
                coordinateFormat: ol.coordinate.createStringXY(4),
                projection: 'EPSG:2154' //juste à l'affichage
            })
        ]),
    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_ol3.map',
          params: {'LAYERS': 'Interregions',
                    //'CRS': 'EPSG:2154',
                    'FORMAT': 'image/png'},
          serverType: 'mapserver',
          extent: [93501.1, 6044342.00, 1248133.25, 7115784.50]
        })
      }),
      new ol.layer.Tile({
        source: new ol.source.OSM()
        })
    ],
    view: new ol.View({
      projection: new ol.proj.Projection({
      code:'EPSG:2154',
      units: 'm'
        }),
      //extent: [93501.1, 6044342.00, 1248133.25, 7115784.50], 
      center: [681845, 6606361],
      zoom: 6
    })  
  });
</script>

0

This is not a projection issue, but the layer order is wrong. The OSM layer is opaque, so it needs to be added first, not last. Otherwise it will cover everything rendered underneath it.

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.