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: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: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):
Here is the result:
And here is an example of high zoom: