OpenLayers Troubleshooting – ArcGIS REST Fails in OpenLayers TileArcGISRest but Works on Desktop

arcgis-rest-apiopenlayers

I'm trying to load ArcGIS REST map into OpenLayers and having trouble.

The demo from https://openlayers.org/en/latest/examples/arcgis-tiled.html works great and I've modified it to try other URLs and basic stuf from arcgisonline works fine for that. I've included my modified main.js and index.html below.

The issue is changing to this URL:
https://services.wvgis.wvu.edu/arcgis/rest/services/Imagery_BaseMaps_EarthCover/wv_imagery_WVGISTC_leaf_off_mosaic/MapServer

The service seems to up and down a lot, but even when working, I get a black/white checkerboard instead of details when zooming into a city block. It does load using the "ArcGIS Online Map Viewer" and on my desktop QGIS, but I can't get it into OpenLayers.

Is this ArcGIS REST different, and how do I handle it?

main.js

import Map from 'ol/Map.js';
import TileLayer from 'ol/layer/Tile.js';
import View from 'ol/View.js';
import {OSM, TileArcGISRest} from 'ol/source.js';

var url = '';
//url = 'https://sampleserver6.arcgisonline.com/ArcGIS/rest/services/USA/MapServer';
//url = 'https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer'
url = 'https://services.wvgis.wvu.edu/arcgis/rest/services/Imagery_BaseMaps_EarthCover/wv_imagery_WVGISTC_leaf_off_mosaic/MapServer';

const layers = [
  new TileLayer({
    source: new OSM(),
  }),
  new TileLayer(
{    extent: [-13884991, 2870341, -7455066, 6338219],
    source: new TileArcGISRest({
      url: url,
    }),
  }),
];
const map = new Map({
  layers: layers,
  target: 'map',
  view: new View({
    center: [-9041148, 4489099],
    zoom: 10,
  }),
});

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Tiled ArcGIS MapServer</title>
    <link rel="stylesheet" href="node_modules/ol/ol.css">
    <style>
      .map {
        width: 100%;
        height: 600px;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>
    <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/elm-pep.js"></script>
    <script type="module" src="main.js"></script>
  </body>
</html>

Best Answer

If you look at the docs of TileArcGISRest tile source you'll see this description:

Layer source for tile data from ArcGIS Rest services. Map and Image Services are supported.

For cached ArcGIS services, better performance is available using the XYZ data source.

Looks like there is performance problem with this service, since tiles are generated on the fly when using TileArcGISRest tile source. Here is an example of such a tile request:

https://services.wvgis.wvu.edu/arcgis/rest/services/Imagery_BaseMaps_EarthCover/wv_imagery_WVGISTC_leaf_off_mosaic/MapServer/export?F=image&FORMAT=PNG32&TRANSPARENT=true&SIZE=293%2C293&BBOX=-9001224.450862356%2C4578883.742395198%2C-8962088.692380344%2C4618019.500877208&BBOXSR=3857&IMAGESR=3857&DPI=103

Alternative is to use cached tile source. You can find all the necessary info for constructing XYZ tile source with the right tile grid at https://services.wvgis.wvu.edu/arcgis/rest/services/Imagery_BaseMaps_EarthCover/wv_imagery_WVGISTC_leaf_off_mosaic/MapServery.

Code for this tile layer could then look something like this (tested):

new ol.layer.Tile({
  source: new ol.source.XYZ({
    url: 'https://services.wvgis.wvu.edu/arcgis/rest/services/Imagery_BaseMaps_EarthCover/wv_imagery_WVGISTC_leaf_off_mosaic/MapServer/tile/{z}/{y}/{x}?blankTile=false',
    tileGrid: new ol.tilegrid.TileGrid({
      origin: [-9325754.0, 4989694.0],
      extent: [-9294707.135673312, 4498859.250759878, -8556631.190551685, 4922014.639346593],
      tileSize: 256,
      resolutions: [611.4962262813797, 305.74811314055756, 152.87405657041106, 76.43702828507324, 38.21851414253662, 19.10925707126831, 9.554628535634155, 4.77731426794937, 2.388657133974685, 1.1943285668550503, 0.5971642835598172, 0.29858214164761665, 0.14929107082380833, 0.07464553541190416, ]   
    })
  })
})

Here is the result:

enter image description here

And here is an example of high zoom:

enter image description here

Related Question