I am trying to highlight features in a tileset-layer based on this tutorial: https://jsfiddle.net/oyjLzfq4/1/
The grey layer is stored as a tileset in Mapbox studio. The feature under the mouse cursor is transferred to a dynamic layer in the frontend code. This works rather well, but some polygons appear to be split by Mapbox. No such split is visible when opening the same layer in QGIS.
The screenshot below shows the problem. It might be a coincidence, but the label (seperate layer in Mapbox studio) appears to be also split along this line.
It seems that this splitting could be processing or rendering artifact. Maybe the feature is not copied completly, but just the part of the feature that is on the current rendering tile. Is there any way this can be prevented?
I use this method to create the hover effect, because filtering the polygons is a lot slower and in this case unusably slow. See the discussion here: https://github.com/mapbox/mapbox-gl-js/issues/2492
Edit
Currently my best solution to the problem is to load the part of the feature on the current tile and let the filter on the hover-layer run at the same time. That means that part of the feature is highlighted right away and the full feature after about 3 seconds.
map.addSource("dynamic_source", {
"type": "geojson",
"data": {"type": "FeatureCollection", "features": []}
});
map.addLayer({
"id": "dynamic_layer",
"type": "fill",
"source": "dynamic_source",
"layout": {},
"paint": {
"fill-color": "#f00",
"fill-opacity": 1
}
});
map.on("mousemove", function(event) {
var features = this.map.queryRenderedFeatures(event.point, {
layers: ["MyLayer"]
});
// Instant hover, but only part of feature on current tile
map.getSource("dynamic_source").setData({
"type": "FeatureCollection",
"features": features.map(function (f) {
return {"type": "Feature", "geometry": f.geometry};
})
});
// 3s delayed hover, but complete feature
if (features.length) {
map.setFilter("MyLayer", ["==", "name", features[0].properties.name]);
} else {
map.setFilter("MyLayer", ["==", "name", ""]);
}
});
This forked example from the Github issue shows that this example also sometimes leads to incomplete hover higlighting at tile boundaries: https://jsfiddle.net/t2sks4pz/
That being said, one could use the id field in the protobuf to store information necessary for reconstructing polygons
.