2

Using OpenLayers 7.3, my goal is to display a Vector Tile Layer (VTL) that has a coordinate system of EPSG:7856, with other layers (Tile and Vector layers) that have coordinate systems in EPSG:3857 (Web Mercator).

I've got the projection from EPSG's website and registered it in OpenLayers:

import proj4 from 'proj4';
import {register} from 'ol/proj/proj4.js';
import {get as getProjection} from 'ol/proj.js';

proj4.defs("EPSG:7856","+proj=utm +zone=56 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs"); register(proj4); let proj7856 = getProjection(projCode);

But I don't understand where I should be setting this. Thinking out loud, if I want to project all layers in the Map to one coord system, can I not use OpenLayers default projection of EPSG:3857, in which case would I expect OpenLayers to discover the VTL is in EPSG:7856 and automatically project it to EPSG:3857, along with the other layers?

Or do I set the projection on the Map View as well as all layers to EPSG:7856?

I haven't had success with either, hence my post. Trying either option, the VTL is rendered at a much larger scale than the other layers.

Taras
  • 32,823
  • 4
  • 66
  • 137
Steve
  • 123
  • 4
  • Please edit your question and add code of how you create/define your VTL layer. – TomazicM Apr 07 '23 at 07:38
  • 3
    Vector tiles can only be used in their native projection, but you can reproject other layers on the map to that projection. Also vector tiles in projections other than EPSG:3857 will use a custom tile grid which must be defined. For example EPSG:27700 vector tiles in a custom grid with the background OSM reprojected to EPSG:27700 https://codesandbox.io/s/simple-forked-rgxtkc?file=/main.js – Mike Apr 07 '23 at 10:47
  • 1
    @Mike - please make that comment an answer so we can up vote it – Ian Turton Apr 07 '23 at 16:06

1 Answers1

3

Vector tiles can only be used in their native projection, but you can reproject other layers on the map to that projection. Also vector tiles in projections other than EPSG:3857 will use a custom tile grid which must be defined. For example EPSG:27700 vector tiles in a custom grid with the background OSM reprojected to EPSG:27700 https://codesandbox.io/s/simple-forked-rgxtkc?file=/main.js

Mike
  • 12,458
  • 1
  • 11
  • 17
  • Thankyou @Mike, that's set me on the right track. I'm still having trouble lining up the layers but this is because the origin point is different to the extent. In your example, the VTL origin is the same point as the extent xmin and ymax (see https://api.os.uk/maps/vector/v1/vts?key=ufArYa1UUPHJcOYbiJDaKkA7Fb4oCkEs). Would you know how to configure openlayers if the origin point is different to the extent? – Steve Apr 10 '23 at 23:44
  • 2
    The normal extent of EPSG:27700 is [0, 0, 700000, 1300000] but overview maps often use a larger extent to include Ireland, so the example has increased the extent to match the tile grid. The tile grid for the example is defined by the service json for the style as in https://labs.os.uk/public/os-data-hub-examples/os-vector-tile-api/vts-27700-basic-map#openlayers but for simplicity I hardcoded the values and limited the zoom levels to those accessible with a free API key. – Mike Apr 11 '23 at 08:53