1

I was trying to reproject a WMS layer from EPSG:25830 to EPSG:3857, but it didn't work. I read that it is not possible to reproject a WMS, only a WFS, It is true?

Here is the code:

<!doctype html>
<html>
<head> 
<script src="http://openlayers.org/en/v3.15.1/build/ol.js"></script>
<script src="C:\Users\agarrucho\Desktop\proj4js-2.3.14\dist\proj4.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js"></script>
<script src="http://epsg.io/25830.js"></script> 
</head>
<body>
<div id="map" class="map"></div>
<script>
  proj4.defs("EPSG:25830","+proj=utm +zone=30 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");

  var extent = [-3.54211, -2.95951, 40.8618, 41.274];
  var projection = ol.proj.get('EPSG:25830');
  projection.setExtent(extent);
    // Declare a Tile layer with an OSM source
    var osmLayer = new ol.layer.Tile({
      source: new ol.source.OSM()
    });
    var par = new ol.layer.Image({
      source: new ol.source.ImageWMS({
        url: 'https://qgiscloud.com/corting/aada/wms'
      })
    })
    // Create latitude and longitude and convert them to default projection
    var birmingham = ol.proj.transform([-1.81185, 52.44314], 'EPSG:25830', 'EPSG:3857');
    // Create a View, set it center and zoom level
    var view = new ol.View({
      center: birmingham,
      zoom: 6
    });
    // Instanciate a Map, set the object target to the map DOM id
    var map = new ol.Map({
      target: 'map',
      projection:projection,

    });
    // Add the created layer to the Map
    map.addLayer(osmLayer);
    map.addLayer(par);
    // Set the view for the map
    map.setView(view);
</script>
</body>
</html>

I now created other code that has the CRS, even though I continue to have the same problem:

<!doctype html>
<html>
<head>
<title>Single Image WMS</title>
<link rel="stylesheet" href="http://openlayers.org/en/v3.15.1/css/ol.css" type="text/css">
<script src="http://openlayers.org/en/v3.15.1/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
  var layers = [
    new ol.layer.Tile({
      source: new ol.source.MapQuest({layer: 'sat'})
    }),
    new ol.layer.Image({
      source: new ol.source.ImageWMS({
        url: 'https://qgiscloud.com/corting/para/wms',
        params: {'LAYERS': 'topp:states'},
        serverType:'qgis'
      })
    })
  ];
  var map = new ol.Map({
    layers: layers,
    target: 'map',
    view: new ol.View({
      center: [-10997148, 4569099],
      zoom: 4
    })
  });
</script>
</body>
</html>
  • No it's not true; you can request a WMS layer or A WFS feature type in whatever format is supported by the respective service (that is usually the best option), and if the service doesn't offer the CRS you need you can reproject the result in your client – nmtoken Dec 10 '17 at 21:38
3

You don't need to reproject a WMS layer, OpenLayers should make the request in the map projection for you automatically. The only time there might be an issue is if the WMS Server doesn't support the projection of your map, but checking the capabilities of your server shows that the layers are available in 3 CRS:

<CRS>EPSG:25830</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:3857</CRS>

So you should be fine.

  • Thanks iantMy sevice had this CRs, now i make oher, but i follow have the same problem, it is the code – corting May 6 '16 at 17:57
2

Try loading proj4 before OL3. I had issues until I was told to load them in that order.

1

latest versions of ol3 support client reprojection for both raster and vector data. even for tile layers. example here and here I think your fault is that you use the projection config on map and not on view. The rest of our code seems to be correct. Try this

var view = new ol.View({
      center: birmingham,
      projection:projection,
      zoom: 6
    });
    // Instanciate a Map, set the object target to the map DOM id
    var map = new ol.Map({
      target: 'map'
    });
  • Thanks pavlos, but the problem don't disappears. Now I "view" the service (shared in QGIS cloud), but for example the base map dont' show. I follow try resolved it – corting May 13 '16 at 9:28

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.