Base Map in EPSG:2056 projection

88 views
Skip to first unread message

Heinrich Baur

unread,
Mar 25, 2025, 4:52:35 PMMar 25
to GeoAdminCh API
I can display the "Base Map" Vector Tiles with Openlayers and the following Vanilla Code:

// Mapbox layer definitions
// ------------------------

var baseMapSource = new ol.source.VectorTile({
  format: new ol.format.MVT(),
  url: 'https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.base.vt/v1.0.0/{z}/{x}/{y}.pbf',
});

var baseMapLayer = new ol.layer.VectorTile({
    id: "base-map-layer",
    source: baseMapSource,
});

var view = new ol.View({
  projection: "EPSG:3857",
  center: [922300, 5902000],
  zoom: 10,
});

var map = new ol.Map({
  target: "map",
  layers: [baseMapLayer],
  controls: [],
  view: view
});

olms.apply(map, 'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json');

Is it possible to get the Vector Tiles in projection EPSG:2056 instead of EPSG:3857 and if yes, Is there an example script or what should I change in my script?

Thanks and best regards, Heiri

Heinrich Baur

unread,
Mar 27, 2025, 12:51:45 PMMar 27
to GeoAdminCh API
There is another issue: Waters are labeled with incomprehensible character strings (see attached screenshot).Bach.png Is there a problem in the file "style.json"?

Cheers, Heiri

Heinrich Baur

unread,
Mar 27, 2025, 1:24:28 PMMar 27
to GeoAdminCh API
Addendum: The labeling issue only exists with Microsoft Edge. Firefox labels correctly (see screenshot).Mirrenbach.png

Sorry, Heiri

Heinrich Baur

unread,
Apr 1, 2025, 10:35:31 AMApr 1
to GeoAdminCh API
The labeling issue is solved when I specify the character set in the HTML file:

    <meta charset="UTF-8">

But I am still interested in any hint about Mapbox Vector Tiles in EPSG:2056 projection

Best regards, Heiri

Pascal Barth

unread,
Apr 4, 2025, 3:59:03 AMApr 4
to geoadm...@googlegroups.com
Hi Heiri,

We haven't yet officially added VectorTiles to our map viewer, but there's some work-in-progress done here if you want to have a glimpse on how we will achieve it.

To summarize what we do :
We load everything in LV95 with OpenLayers (as it is currently done) and add the VectorTile layer with the help of MapLibre and a bridge component found here

We edited this bridge-component to be able to transform our LV95 zoom level into Mercator zoom on-the-fly, we hope to be able to add this change in the bridge-component itself in the future.

TL;DR;
We show VectorTiles with MapLibre in Mercator
We add that to OpenLayers that runs in LV95, and transform position/zoom on-the-fly to sync MapLibre

Hope it helps, don't hesitate if you want more details on something.

Cheers,
Pascal

--
You received this message because you are subscribed to the Google Groups "GeoAdminCh API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geoadmin-api...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/geoadmin-api/611926ce-1319-496b-bbdf-50a467412632n%40googlegroups.com.

Heinrich Baur

unread,
Apr 10, 2025, 10:51:40 AMApr 10
to GeoAdminCh API
Hi Pascal,

Thank you very much for the link to your interesting work on the integration of Mapbox Vector Tiles into web-mapviewer. As you say, it is "work-in-progress": panning and zooming is not yet as smooth as in the swisstopo Android app. WMTS and MVT layers do not always match perfectly (see "Wanderwege" in BaseMap_web-mapviewer.jpg).BaseMap_web-mapviewer.jpg

I am currently trying a different approach: I am using two separate ol.map objects named mapMVT and map respectively. Two separate <div>s are the targets of the two map objects. One of the <div>s is completely covering the other. The two map objects have different views named viewMercator and viewLV95 respectively. As the names suggest the views use "EPSG:3857" and "EPSG:2056" respectively. I am applying the olms.js bridge to the mapMVT with web-mercator projection:

olms.apply(mapMVT, 'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json');

In order to match the two maps I am synchronizing the view centers and resolutions of the maps. To synchronize the centers I convert the LV95 coordinates to WGS84 lon/lat coordinates and from there to web-mercator coordinates. To adjust the resolution I am using the following code:

var MVTperLV95resolution = 1/Math.cos(Math.PI * lat / 180);
viewMercator.setResolution(viewLV95.getResolution()*MVTperLV95resolution);

This works but speeds of panning and zooming are comparable to speeds with your approach. MVT and WMTS layers again do not match perfectly (see BasMap_GPS_Schweiz.jpg).BasMap_GPS_Schweiz.jpg

In contrast "ch.swisstopo.swisstlm3d-wanderwege" is matching perfectly with "ch.swisstopo.pixelkarte-farbe" (see Pixelkarte_GPS_Schweiz.jpg).Pixelkarte_GPS_Schweiz.jpg 

Also the match is perfect in the swisstopo Android app (see BaseMap_swisstopo_app.jpg).BaseMap_swisstopo_app.jpg Presumably this app is not based on Openlayers, do you know what framework they use?

I have two additional questions about the swisstopo implementations of the "basemap" and the "basemap-winter":
  1. The API documentation about Mapbox Vector Tiles (api3.geo.admin.ch) does not list an example of an URL to get one pbf tile for the "basemap-winter". My guess "https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.base-winter.vt/v1.0.0/7/67/44.pbf" is not working. Is there a correct URL for "basemap-winter"?
  2. The Edge developer console reports the following error:
    olms.js:1
    Expected value to be of type number, but found string instead.
    evaluate @ olms.js:1

    on execution of the following line:
    olms.apply(mapMVT, 'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json');
    Is there an error in the style.json file?
Cheers, Heiri

Reply all
Reply to author
Forward
0 new messages