Edit

Vector tiles reprojected

vectortiles6 tile10 mapbox8 maplibre1 ol-mapbox-style3 reprojection8

Example showing vector tiles in EPSG:4326, reprojected to a polar projection.

Vector tile layers can be reprojected to other projections. This example shows vector tiles in geographic coordinates (EPSG:4326) reprojected to North Pole Lambert Azimuthal Equal Area (ESRI:102017). For polar regions, vector tiles in geographic coordinates are recommended, because Web Mercator tiles do not work beyond 85° North and South.

Note: Make sure to get your own API key at https://www.maptiler.com/cloud/ when using this example. No map will be visible when the API key has expired.

main.js
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import VectorTileLayer from 'ol/layer/VectorTile.js';
import {register} from 'ol/proj/proj4.js';
import {fromLonLat} from 'ol/proj.js';
import VectorTileSource from 'ol/source/VectorTile.js';
import {createXYZ} from 'ol/tilegrid.js';
import {applyBackground, applyStyle} from 'ol-mapbox-style';
import proj4 from 'proj4';

// Register proj4 definition for North Pole Lambert Azimuthal Equal Area
proj4.defs(
  'ESRI:102017',
  '+proj=laea +lat_0=90 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs',
);
register(proj4);

const key = 'Get your own API key at https://www.maptiler.com/cloud/';
const url = 'https://api.maptiler.com/maps/basic-4326/style.json?key=' + key;

const layer = new VectorTileLayer({
  declutter: true,
  source: new VectorTileSource({
    projection: 'EPSG:4326',
    // Match the server resolutions
    tileGrid: createXYZ({
      extent: [-180, -90, 180, 90],
      tileSize: 512,
      maxResolution: 180 / 512,
      maxZoom: 13,
    }),
  }),
});
applyStyle(layer, url);
applyBackground(layer, url);

const map = new Map({
  target: 'map',
  layers: [layer],
  view: new View({
    projection: 'ESRI:102017',
    minZoom: 3,
    zoom: 4,
    center: fromLonLat([0, 90], 'ESRI:102017'),
  }),
});
index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Vector tiles reprojected</title>
    <link rel="stylesheet" href="node_modules/ol/ol.css">
    <style>
      .map {
        width: 100%;
        height: 400px;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map" style="background:none;"></div>

    <script type="module" src="main.js"></script>
  </body>
</html>
package.json
{
  "name": "vector-tiles-reprojected",
  "dependencies": {
    "ol": "10.8.0",
    "ol-mapbox-style": "^13.2.1",
    "proj4": "2.20.2"
  },
  "devDependencies": {
    "vite": "^3.2.3"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build"
  }
}