Remove support() check (#2508)

This commit is contained in:
Xiaoji Chen 2025-03-20 09:41:27 -07:00 committed by GitHub
parent 2ab613129a
commit d57e469018
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 48 deletions

View File

@ -59,24 +59,18 @@ function _Map(props: MapProps, ref: React.Ref<MapRef>) {
throw new Error('Invalid mapLib');
}
// workerUrl & workerClass may change the result of supported()
// https://github.com/visgl/react-map-gl/discussions/2027
setGlobals(mapboxgl, props);
if (!mapboxgl.supported || mapboxgl.supported(props)) {
if (props.reuseMaps) {
mapbox = Mapbox.reuse(props, containerRef.current);
}
if (!mapbox) {
mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);
}
contextValue.map = createRef(mapbox);
contextValue.mapLib = mapboxgl;
setMapInstance(mapbox);
mountedMapsContext?.onMapMount(contextValue.map, props.id);
} else {
throw new Error('Map is not supported by this browser');
if (props.reuseMaps) {
mapbox = Mapbox.reuse(props, containerRef.current);
}
if (!mapbox) {
mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);
}
contextValue.map = createRef(mapbox);
contextValue.mapLib = mapboxgl;
setMapInstance(mapbox);
mountedMapsContext?.onMapMount(contextValue.map, props.id);
})
.catch(error => {
const {onError} = props;

View File

@ -59,24 +59,18 @@ function _Map(props: MapProps, ref: React.Ref<MapRef>) {
throw new Error('Invalid mapLib');
}
// workerUrl & workerClass may change the result of supported()
// https://github.com/visgl/react-map-gl/discussions/2027
setGlobals(mapboxgl, props);
if (!mapboxgl.supported || mapboxgl.supported(props)) {
if (props.reuseMaps) {
mapbox = Mapbox.reuse(props, containerRef.current);
}
if (!mapbox) {
mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);
}
contextValue.map = createRef(mapbox);
contextValue.mapLib = mapboxgl;
setMapInstance(mapbox);
mountedMapsContext?.onMapMount(contextValue.map, props.id);
} else {
throw new Error('Map is not supported by this browser');
if (props.reuseMaps) {
mapbox = Mapbox.reuse(props, containerRef.current);
}
if (!mapbox) {
mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);
}
contextValue.map = createRef(mapbox);
contextValue.mapLib = mapboxgl;
setMapInstance(mapbox);
mountedMapsContext?.onMapMount(contextValue.map, props.id);
})
.catch(error => {
const {onError} = props;

View File

@ -59,24 +59,18 @@ function _Map(props: MapProps, ref: React.Ref<MapRef>) {
throw new Error('Invalid mapLib');
}
// workerUrl & workerClass may change the result of supported()
// https://github.com/visgl/react-map-gl/discussions/2027
setGlobals(mapboxgl, props);
if (!mapboxgl.supported || mapboxgl.supported(props)) {
if (props.reuseMaps) {
maplibre = Maplibre.reuse(props, containerRef.current);
}
if (!maplibre) {
maplibre = new Maplibre(mapboxgl.Map, props, containerRef.current);
}
contextValue.map = createRef(maplibre);
contextValue.mapLib = mapboxgl;
setMapInstance(maplibre);
mountedMapsContext?.onMapMount(contextValue.map, props.id);
} else {
throw new Error('Map is not supported by this browser');
if (props.reuseMaps) {
maplibre = Maplibre.reuse(props, containerRef.current);
}
if (!maplibre) {
maplibre = new Maplibre(mapboxgl.Map, props, containerRef.current);
}
contextValue.map = createRef(maplibre);
contextValue.mapLib = mapboxgl;
setMapInstance(maplibre);
mountedMapsContext?.onMapMount(contextValue.map, props.id);
})
.catch(error => {
const {onError} = props;