What is @mapbox/mapbox-gl-supported?
@mapbox/mapbox-gl-supported is a utility package that helps developers determine if the current browser environment supports Mapbox GL JS. This is useful for conditionally loading Mapbox GL JS maps or providing fallback content for unsupported browsers.
What are @mapbox/mapbox-gl-supported's main functionalities?
Check if Mapbox GL JS is supported
This feature allows you to check if the current browser environment supports Mapbox GL JS. If supported, you can proceed to load Mapbox GL JS maps; otherwise, you can provide alternative content.
const mapboxglSupported = require('@mapbox/mapbox-gl-supported');
if (mapboxglSupported()) {
console.log('Mapbox GL JS is supported');
} else {
console.log('Mapbox GL JS is not supported');
}
Check if Mapbox GL JS is supported with specific options
This feature allows you to check if the current browser environment supports Mapbox GL JS with specific options, such as failing if there is a major performance caveat. This can help ensure a better user experience by avoiding loading maps in suboptimal conditions.
const mapboxglSupported = require('@mapbox/mapbox-gl-supported');
const options = { failIfMajorPerformanceCaveat: true };
if (mapboxglSupported(options)) {
console.log('Mapbox GL JS is supported with the given options');
} else {
console.log('Mapbox GL JS is not supported with the given options');
}
Other packages similar to @mapbox/mapbox-gl-supported
detect-browser
The 'detect-browser' package is a lightweight library for detecting the browser name and version. While it does not specifically check for Mapbox GL JS support, it can be used to implement custom logic for browser compatibility, including Mapbox GL JS.
bowser
The 'bowser' package is a browser detection library that can identify the browser and its version. Similar to 'detect-browser', it does not directly check for Mapbox GL JS support but can be used to create custom compatibility checks for various features, including Mapbox GL JS.
Mapbox GL JS Supported
This library determines if a browser supports Mapbox GL JS.
Testing Your Browser
You may test your browser here.
Using Mapbox GL JS Supported with a <script>
tag
<script src='mapbox-gl-supported.js'></script>
<script>
if (mapboxgl.supported()) {
...
} else {
...
}
</script>
Using Mapbox GL JS Supported with Browserify
npm install --save @mapbox/mapbox-gl-supported
var mapboxglSupported = require('@mapbox/mapbox-gl-supported');
if (mapboxglSupported.supported()) {
...
}