mapbox-gl-js version: 0.38.0
The function should return features of the buildings inside the viewport.
The function should return features that have completely different coordinates.
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [20, 45],
zoom: 4
});
part of the code where i add buildings:
map.on('load', function () {
map.showTileBoundaries = true;
map.addLayer({
'id': '3d-buildings',
'source': 'composite',
'source-layer': 'building',
'filter': ['==', 'extrude', 'true'],
'type': 'fill-extrusion',
'minzoom': 15,
'paint': {
'fill-extrusion-color': '#aaa',
'fill-extrusion-height': {
'type': 'identity',
'property': 'height'
},
'fill-extrusion-base': {
'type': 'identity',
'property': 'min_height'
},
'fill-extrusion-opacity': .6
}
});
});
part of the code where try to get building features:
map.on('dblclick', function (e) {
var feature = map.querySourceFeatures("composite", { sourceLayer: ['building'], filter: ['==', 'extrude', 'true'] });
console.log(feature);
});
If somebody know why this happens, or knows some other workaround for "selecting" the whole building please help.
Hi @lp6191, thanks for the report. To make sure we're on the same page about what exactly this issue is, could you please put together a small self-contained example on JSFiddle that demonstrates the unexpected behavior you're seeing?
here is the fiddle: https://jsfiddle.net/Lt8voqdo/7/
just double click on any of the grey buildings and check the console. The first output in the console are click coords, and the second is the array of features, check coordinates of any of the features.. This happens at zoom levels grater than 15 I think.
You're using querySourceFeatures, which returns all features in the source. Here's the example modified to use queryRenderedFeature with the desired point: https://jsfiddle.net/vbxh9qtr/1/
Thanks, but there is still something I don't understand the same function, querySourceFeatures at zoom level 15 returns normal coordinates(around 14.5 , 46), but when you zoom in on the same building past zoom 17 for example the coordinates change drastically(-155, 83).
Yes, I tried to use querySourceFeatures because my goal is to select the whole building even if it's cut in half with tile boundary. In the next lines i would check with turf.js if the clicked point is inside a feature and try to collect the entire feature and display it.. Is there any other known workaround for this problem(getting the whole building)?
The domain of the query includes all currently-loaded vector tiles and GeoJSON source tiles: this function does not check tiles outside the currently visible viewport.
from the docs. how is it possible to get coordinates like (-82,74), when i click around (46,14)?