Adding a Tileset from mapbox into my map
Asked Answered
C

3

5

I'm new working with mapbox, and recently I want to create a web map. I uploaded a shape into mapbox tilseset cloud, but when I try to add it into a map it doesn't display. This is the code funtion that I'm using:

        map.on('load', function() {
        map.addLayer({
            'id' : 'Resguardos',
            'type' : 'fill',
            "source" : {
                'type' : 'vector',
                'url' : 'mapbox://fabiofz1990.9lhgml6c',
            },
            'layout' : {},
            'paint' : {
                'fill-color' : '#0044b2',
                'fill-opacity' : 1
            }
        });

    });

Thank you

Caco answered 28/6, 2017 at 14:55 Comment(1)
have you added the api key to thisDiscretion
I
7

You can add tilesets directly from the Mapbox studio.

  1. Copy tileset URL.List item
  2. Add URL like this. url: "mapbox://+tilesetid"
map.addSource('tileset_data', {
    "url": "mapbox://abcqqq123.cklxcyxew1b9421lpb8shxf4x-2ikvs",
    "type": "vector"
});
  1. Add the source name from above source name "tileset_data" in your layer and get source-layer from above picture.
       map.addLayer({
           'id': 'circles',
           'type': 'circle',
           'source': 'tileset_data',
           'source-layer': 'children_obesity',
           'paint': {
               'circle-color': '#7F3121',
               'circle-opacity': 0.75,
               'circle-radius': 5
           }
       });

Then you good to go.

Impressionism answered 6/3, 2021 at 7:35 Comment(0)
C
2

I think to display it you would need to add the tileset data to the style that your are using.

There is an option for that in your mapbox account at: https://www.mapbox.com/studio/tilesets/

enter image description here

Canalize answered 4/7, 2017 at 14:3 Comment(0)
C
0

---- Updated 2023 ---- :

Add a raster tile source (mapbox official example)

https://docs.mapbox.com/mapbox-gl-js/example/map-tiles/

This is my working example. You will need:

step 1) add tile source

step 2) add tile layer based off the tile source you just created.

enter image description here

---- Original 2019 ---- :

you can NOT directly add mapbox TileSet into your browser client.

You have to create a new mapbox style, which use your tileSet.

This is working sample

https://transparentgov.net/cleargov1/766/new-2019-world-press-freedom-ranking-map-180-countries

https://transparentgov.net/json2tree/datahub.io/international/press-freedom-2019-mapbox-style.html

Culhert answered 24/4, 2019 at 23:6 Comment(1)
Is there no way to do this programmatically? What if you have hundreds of tiles and want your app to choose which to display based on user input?Wachter

© 2022 - 2024 — McMap. All rights reserved.