3
votes

I'd like to use Mapbox's terrain-rgb tiles as a layer in a Mapbox GL map. The examples I've seen that manipulate terrain-rgb data use L.tileLayer to construct the tiles for the new layer: https://www.mapbox.com/blog/terrain-rgb/

With MapboxGL.js, I've tried to add the layer this way:

    map.on('load', function () {

      map.addSource('terrain-rgb', {
          type: 'vector',
          url: 'https://api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=pk.eyJ1IjoibWF0dCIsImEiOiJTUHZkajU0In0.oB-OGTMFtpkga8vC48HjIg'
      });
      map.addLayer({
          'id': 'terrain-rgb',
          'type': 'fill',
          'source': 'terrain-rgb',
          'layout': {
              'visibility': 'visible'
          },
          'paint': {
             'fill-color': 'rgba(15,148,179,.4)'
          },
          'source-layer': 'terrain-rgb'
      });

    });

I tried the fill, line, and circle type, but it's not working. I get these console errors:

GET https://api.mapbox.com/v4/mapbox.terrain-rgb/%7Bz%7D/%7Bx%7D/%7By%7D.pngraw…ss_token=pk.eyJ1IjoibWF0dCIsImEiOiJTUHZkajU0In0.oB-OGTMFtpkga8vC48HjIg 404 (Not Found)  ajax.js:25 

Object {type: "error", target: t, isSourceLoaded: false, source: Object, sourceId: "terrain-rgb"}   evented.js:104 

How do I properly add a the terrain-rgb source to mapboxgl.js?

1

1 Answers

1
votes

Ok, after looking through the issues on github, it seems this isn't possible yet: https://github.com/mapbox/mapbox-gl-js/issues/3730