2

I found the below code in the MapBox website, I am unable to find out how exactly the data is received to plot the data-driven circles on the map. There is a url "mapbox://examples.8fgz4egr" present in the 'source' but what kind of data is it ? is it json or what ? How do I change the source and put my own ?

https://www.mapbox.com/mapbox-gl-js/example/data-driven-circle-colors/

<script> mapboxgl.accessToken = 'ACCESS_TOKEN; var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/light-v9',
    zoom: 12,
    center: [-122.447303, 37.753574] });

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

    map.addLayer({
        'id': 'population',
        'type': 'circle',
        'source': {
            type: 'vector',
            url: 'mapbox://examples.8fgz4egr'
        },
        'source-layer': 'sf2010',
        'paint': {
            // make circles larger as the user zooms from z12 to z22
            'circle-radius': {
                'base': 1.75,
                'stops': [[12, 2], [22, 180]]
            },
            // color circles by ethnicity, using data-driven styles
            'circle-color': {
                property: 'ethnicity',
                type: 'categorical',
                stops: [
                    ['White', '#fbb03b'],
                    ['Black', '#223b53'],
                    ['Hispanic', '#e55e5e'],
                    ['Asian', '#3bb2d0'],
                    ['Other', '#ccc']]
            }
        }
    }); }); </script>
ShashankAC
  • 1,016
  • 11
  • 25

1 Answers1

2

It's vector tiles as you can see from the type value of the source property. Here is an in depth explanation on what vector tiles are and how they work: https://www.mapbox.com/vector-tiles/

Very roughly it's GeoJSON sliced into map tiles.

For simplicity's sake you can switch out the source for a geojson source and connect the circle layer to it:

map.addLayer({
  type: 'circle',
  id: 'my-layer',
  source: {
    type: 'geosjon'
    data: /* url to GeoJSON or inlined FeaturedCollection */
  }
})
Scarysize
  • 4,131
  • 25
  • 37