function mapboxFitBounds(
coordinates: [number, number][],
mapInstance: mapboxgl.Map,
options: mapboxgl.FitBoundsOptions = {
padding: 50,
}
) {
// Create a 'LngLatBounds' with both corners at the first coordinate.
const bounds = new mapboxgl.LngLatBounds(coordinates[0], coordinates[0]);
// Extend the 'LngLatBounds' to include every coordinate in the bounds result.
for (const coord of coordinates) {
bounds.extend(coord);
}
mapInstance.fitBounds(bounds, options);
}
mapbox 多余 label 标签移除
function removeExtraLabel(instance: mapboxgl.Map) {
const layers = instance.getStyle().layers;
if (layers) {
for (let i = 0; i < layers.length; i++) {
if (/-label$/.test(layers[i].id)) {
instance.removeLayer(layers[i].id);
}
}
}
}
mapbox
地图方法mapbox 地图自适应缩放比例
mapbox 多余 label 标签移除
deck.gl based on mapbox (react) 地图视野自适应
react component logic
JSX