I use MapboxGL JS v2 with mapbox://styles/mapbox/streets-v11
style.
And I use this code to display 3D buildings on my map:
map.addLayer({
'id': '3d-buildings',
'source': 'composite',
'source-layer': 'building',
'filter': ['==', 'extrude', 'true'],
'type': 'fill-extrusion',
'minzoom': 15,
'paint': {
'fill-extrusion-color': '#666',
'fill-extrusion-height': ['interpolate', ['linear'], ['zoom'], 15, 0, 15.05, ['get', 'height']],
'fill-extrusion-base': ['interpolate', ['linear'], ['zoom'], 15, 0, 15.05, ['get', 'min_height']],
'fill-extrusion-opacity': 0.9,
}
});
It's working as expected, as seen in this example.
Now, what I want is to load these buildings at lower zoom level, for example 10 instead of 15.
So, I changed minzoom
from 15
to 10
, and I also changed the interpolate
stuff to use linear interpolation from 10
to 15.05
.
Here is the final code:
map.addLayer({
'id': '3d-buildings',
'source': 'composite',
'source-layer': 'building',
'filter': ['==', 'extrude', 'true'],
'type': 'fill-extrusion',
'minzoom': 10,
'paint': {
'fill-extrusion-color': '#666',
'fill-extrusion-height': ['interpolate', ['linear'], ['zoom'], 10, 0, 15.05, ['get', 'height']],
'fill-extrusion-base': ['interpolate', ['linear'], ['zoom'], 10, 0, 15.05, ['get', 'min_height']],
'fill-extrusion-opacity': 0.9,
}
});
Unfortunately it's not working, it looks like it still waits for zoom level 15 to load, and I didn't find anything on the internet to make it work.
In Mapbox GL JS, all tiles are offset by one zoom level. This means that when a Mapbox GL JS map is zoomed to zoom level 2, it will display the same geographic area as a Mapbox.js map zoomed to zoom level 1.
It renders map data from Mapbox Vector Tiles, using the Mapbox Style specification and hardware-accelerated graphics (WebGL). Mapbox GL JS is part of a cross-platform ecosystem, which also includes native SDKs for applications on Android and iOS.
Mapbox-GL-JS v2 (GL-JS v2) is the next generation of our vector-tile based maps SDK for browsers. It includes: Performance improvements With a faster time to load the map library and to render the initial viewport. 3D rendering Rendering vector maps with terrain elevation and sky layers.
In our benchmarks, a map that may have loaded in 1900ms in v1, loads in 1350ms in v2. The speed index, a measure of when map content starts to display, is 35% faster as well. What can I do with 3D rendering in Mapbox GL JS v2?
It seems like tile set's for building are generated after zoom level 13.
READ HERE
So, when we query map queryRenderedFeatures({ layers: ["3d-buildings"] });
on zoom level below 13 no feature's get added on Map. But once the zoom level is greater then 13 few building feature's get added.
Screenshot zoom level<13
Screenshot zoom level>13
UPDATE
In order to make it work from zoom level 10 to 15, You have to create your own tileset using Tilesets CLI where you have to make a recipe json and have to provide zoom levels like:
{
"version": 1,
"layers": {
"building_footprints": {
"source": "mapbox://tileset-source/username/building-footprints",
"minzoom": 10, //<---
"maxzoom": 15
}
}
}
Screenshot:
Step by Step Creation
Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With