0

In my case there are two layers:

  • raster from ArcGIS REST service (red) and
  • vector in MVT format (blue)

The problem is that the raster layer is offset from the vector layer. It is assumed that the vector is more correct. Therefore, I need to "move" the raster layer a bit.

Is there a way this can be done in OpenLayers?

Reprojection doesn't seem to be the right thing to dig into, because both layers have the same original projection of EPSG:3857 (the red one is EPSG:102100). But maybe some custom projection with some transformation functions? Idk. I just need some guidance on this matter.

2
  • ArcGIS accepts custom projections in WKT format, e.g. web mercator with offset false easting and false northing codesandbox.io/s/arcgis-image-forked-xzrt4?file=/main.js Without proj4 OpenLayers will not attempt to reproject that (which you would not want because it would undo the deliberate offset) It will work equally well with tile or image sources.
    – Mike
    Commented Jan 22, 2022 at 13:49
  • Thanks, @Mike! The source that was used for ArcGIS tiles doesn't accept projection in WKT format (for whatever reason). It actually doesn't accept any deviation from specific format. But you put the thinking in the right direction: to change the URL itself, instead of the resulting layer. So I came up with altering bbox parameter, by changing tileExtent in getRequestUrl_ method of ol/source/TileArcGISRest class. Don't know if it's a good solution, but, roughly, it fixes the offset. Commented Jan 24, 2022 at 3:58

1 Answer 1

0

This may not be the most elegant solution in context of OpenLayers, but for the time it is what I ended up with. And it is not to change or transform the layer itself, but to change URL of ArcGIS exported tile (thanks to @Mike for the help). What you do is you alter tile bounding box in a private method of a ol/source/TileArcGISRest class. The method is getRequestUrl_().

import TileArcGISRest from 'ol/source/TileArcGISRest';

export default class CustomTileArcGISRest extends TileArcGISRest
{
   getRequestUrl_(
        tileCoord,
        tileSize,
        tileExtent,
        pixelRatio,
        projection,
        params
    ) {

        // Altering tileExtent
        var xOffset = -1;
        var yOffset = -4.5;
        tileExtent = tileExtent.map((n, i) => i % 2 ? n + yOffset : n + xOffset);

        return super.getRequestUrl_(
            tileCoord,
            tileSize,
            tileExtent,
            pixelRatio,
            projection,
            params
        );
    }
}

tileExtent is in a form of an array, like [xmin, ymin, xmax, ymax], where xmin, ymin are floats.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.