0

I try to show a WMS layer with OpenLayers 4.6.5 but the tiles don't show up.

I use the following code to load the WMS layer as ArcGIS REST service:

new ol.layer.Tile({
  source: new ol.source.TileArcGISRest({
    url: "https://geoportal.amb.cat/arcgis/rest/services/Cartografia/MapaTopograficAMB1M_ETRS89/MapServer",
    projection: 'EPSG:25831',
    params: {'LAYERS': 'Nivell 1k'}
  })
})  

The browser network tab shows that tiles get loaded, but they are all transparent.

Here is the jsfiddle.

2

The location may need adjusting by about 10km as tiles are not loading where you centered the view. The main problem was that EPSG:25831 needed to be defined using proj4. You will need to include the library <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>

proj4.defs("EPSG:25831","+proj=utm +zone=31 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");

var layers = [
        new ol.layer.Tile({
          source: new ol.source.OSM()
        }),
        new ol.layer.Tile({
          source: new ol.source.TileArcGISRest({
            url: "https://geoportal.amb.cat/arcgis/rest/services/Cartografia/MapaTopograficAMB1M_ETRS89/MapServer",
            projection: 'EPSG:25831',
            params: {'LAYERS': 'Nivell 1k'}
          })
        })
];
var map = new ol.Map({
  layers: layers,
  target: 'map',
  view: new ol.View({
    center: [232350, 5070153],
    zoom: 15,
    minZoom: 12,
    maxZoom: 20
  })
});
  • Thanks, you are right about the 2 problems: 1. Tiles are not offered for the centered area and 2. EPSG:25831 needs to be defined using proj4. – geraldo Jun 17 at 9:01
0

ArcGIS Tile Services are wierd and don't allways act the same way as other WMTS.
your code missed the new projection = ol.proj.Projection declaration and also misplaced.

Besides that you also had the map startiong location out of the layer bounds.
I set it to the service's minimal coordinates, you can modify it further from there.

A fixed code would look like this:

var layers = [
        /*new ol.layer.Tile({
          source: new ol.source.OSM()
        }),*/
        new ol.layer.Tile({
          source: new ol.source.TileArcGISRest({
            url: "https://geoportal.amb.cat/arcgis/rest/services/Cartografia/MapaTopograficAMB1M_ETRS89/MapServer"
          })
        })
];
var projection 
var map = new ol.Map({
  layers: layers,
  target: 'map',
  view: new ol.View({
    center: [423690,4582541],
    zoom: 15,
    minZoom: 12,
    maxZoom: 20,
    projection: new ol.proj.Projection({
        code:  'EPSG:25831',
        units: 'm'
    })
  })
});
  • There is nothing wrong with placement of projection (see openlayers.org/en/v4.6.5/apidoc/ol.source.TileArcGISRest.html) and there is nothing wrong with format of the projection (see openlayers.org/en/v4.6.5/apidoc/ol.html#.ProjectionLike). Can you also explain what your statement "ArcGIS Tile Services are wierd" means in context of this question. – TomazicM Jun 16 at 19:15
  • It means they don't act like normal WMTS. Either way the oslution does work, it seems the main problem was the starting location of his map. – Dror Bogin Jun 16 at 19:39
  • 1
    You have simply changed the view projection, which wasn't a requirement, and without the full definition of the projection needed to enable reprojection any other layers such as a background OSM wouldn't match the data overlay. – Mike Jun 16 at 21:19

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.