Accessing nested properties of a TileSet

I am trying to access all the features of a specific tileset generated threw MapBoxStudio.

Reading the API doc I guess I should be able to get all the nested parameters from the method : map.querySourceFeatures(IdOfMyLayer);

However, the output of this is empty.

map.querySourceFeatures('words');

Where 'words' is the ID of the layer I got from map.getStyle().layers

I would expect to get access to the properties of this particular layer. However, I get an empty result.

Sorry for the noob question but I am missing something crucial here in the way MapBox is working, any help from you would be very much appreciated.

Upvotes: 0

Views: 268

Answers (2)

I get it now. The proper way to retrieve all the features of a dataset is to use the DataSet API:

https://docs.mapbox.com/api/maps/#retrieve-a-dataset

This is what I've done :

$.ajax({
            url: 'https://api.mapbox.com/datasets/v1/*****/{dataset_id}/features?limit=50&access_token=********',
            type:'GET',
            success:function(data){console.log(data)},
            error:function(error){console.log('ERROR')}
        })

With the {dataset_id} taken from mapboxStudio.

I can limit and store the variable to process the JSON response. Thanks a lot :)

Upvotes: 0

Steve Bennett
Steve Bennett

Reputation: 126095

If you are trying to access all the features of a tileset that you created in Studio, you should probably consider a different workflow. By definition, a tileset is a transformation of a dataset optimised for displaying a map, not querying.

If you use a Mapbox dataset rather than a tileset, you can access the whole dataset as a clean GeoJSON object - assuming it's small enough to load into the browser. Alternatively, you could create a GeoJSON by some other means, then upload it.

If querySourceFeature() is returning [], then most likely no features have loaded in the current viewport (yet). Perhaps you need to trigger the call at a later time, when the source data has loaded.

Upvotes: 1

Related Questions