AW: Vector tiles for basemap - only displaying specific layers

81 views
Skip to first unread message

David...@swisstopo.ch

unread,
Dec 6, 2021, 10:34:08 AM12/6/21
to geoadm...@googlegroups.com

I have never tried it. My solution would be adapting the style.json:

Download style here: https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte.vt/style.json

Edit style with https://maputnik.github.io/editor

Host style on your own. You can then render the style with OL e.g. like this:

 

    <!DOCTYPE html>

    <html>

    <head>

      <script src="https://cdn.maptiler.com/ol/v6.0.0/ol.js"></script>

      <script src="https://cdn.maptiler.com/ol-mapbox-style/v5.0.2/olms.js"></script>

      <link rel="stylesheet" href="https://cdn.maptiler.com/ol/v6.0.0/ol.css">

      <style>

        #map {position: absolute; top: 0; right: 0; bottom: 0; left: 0;}

      </style>

    </head>

    <body>

      <div id="map">

      

      </div><p> Data: © swisstopo</p>

    <script>

      var styleJson = 'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte.vt/style.json'; /*replace with your style.json*/

      var map = new ol.Map({

        target: 'map',

        view: new ol.View({

          constrainResolution: true,

          center: ol.proj.fromLonLat([7.67343, 46.30346]), /*set starting map load location and zoom */

          zoom: 15

        })

      });

      olms.apply(map, styleJson);

    </script>

    </body>

 

Not sure if CDN from maptiler can be used freely but I’m sure there are others that can be used.

 

 

Von: geoadm...@googlegroups.com <geoadm...@googlegroups.com> Im Auftrag von julien H.
Gesendet: Samstag, 4. Dezember 2021 10:18
An: GeoAdminCh API <geoadm...@googlegroups.com>
Betreff: Vector tiles for basemap - only displaying specific layers

 

Hello,

 

I m trying to create a basemap with vector tiles from swisstopo with Openlayers and I would like to display only specific layers (like building, rail, roads, water), without using a json.style.

 

I can already select only specific layers by adding this code :


 format: new ol.format.MVT({
  layers: 'water',

 

And i can give to each layer its style. So it's work fine for layer that only have one class corresponding to one style (like water, buildings)

 

But for layer like transportation that contains rail, roads, ... i m blocked to apply style to each class.

 

How can we apply a specific style to each class of a same vector layer in openlayers ?

Do you have maybe a code example ?

 

Thanks for your help.

 

Julien

1950 - Sion

 

--
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 on the web visit https://groups.google.com/d/msgid/geoadmin-api/9c2a656e-3eff-4e3b-9df6-2896eedbb7b8n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages