4

I use vector tiles in crs ETRS89/UTM zone 32N (EPSG:25832) in OpenLayers and it works properly with default style.

But my problem is that if I apply a style.json from Maputnik in form of Mapbox Style by using th library olm-mapbox-style, it will be ignored. The same style.json works fine with "EPSG:3857".

I guess it is related to view because the olms uses map.getView().getZoom() function by updating the style.

How can I resolve this problem? Any idea? Many thanks.

...
import {apply, applyStyle} from 'ol-mapbox-style';

...
proj4.defs("EPSG:25832","+proj=utm +zone=32 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
register(proj4);
var projection = getProjection("EPSG:25832");

const map = new Map({
  target: 'map',
  layers:[
    new TileLayer({
      source: new OSM()
    }),
    vectorTile
  ],
  view: new View({
    center: transform([7.012, 51.4], "EPSG:4326", projection),
    projection:projection,
    zoom: 6
  })
});

const jsonPath = require('./data/style.json');
apply(map, jsonPath);
Arash Gh.
  • 41
  • 3
  • Vector tiles cannot be reprojected in OpenLayers. See https://github.com/openlayers/openlayers/issues/4491 and https://github.com/openlayers/openlayers/issues/6059 – Mike Oct 31 '19 at 11:12
  • I should add that I produce the grid and tiles via T-rex server for "EPSG:25832". It works without any problem in OpenLayers but the style.json can not be applied. – Arash Gh. Oct 31 '19 at 11:43
  • 1
    If you have already created a working layer in OpenLayers you can use applyStyle instead of apply, for example https://codesandbox.io/s/mapbox-vector-tiles-gfyfn – Mike Oct 31 '19 at 13:54
  • 1
    You could try something along the lines of https://openlayers.org/en/latest/examples/vector-tiles-4326.html. – ahocevar Oct 31 '19 at 21:32
  • Thanks a lot for your both answers and provided examples. I got it to work with the example of Mike. – Arash Gh. Nov 04 '19 at 08:11

0 Answers0