When to use react-map-gl or plain mapbox-gl in React app?
question: Considerably lower FPS with react-map-gl compared to mapbox-gl
Comparison to Uber's react-map-gl
Mapbox blank map React-map-gl | ReactJS
Videos
I'm working on a React app with a mapbox component and am trying to understand the use case for react-map-gl vs the examples on the Mapbox site that just use mapbox-gl. From the React GitHub issues they mention this in regards to performance -
React may decide to render more than necessary than Mapbox would on its own, failing to account for how expensive the draw call is.
If you are using mapbox as nothing but a map display, generally speaking you do not need this library. If you are trying to match the map with any other React component, you will eventually run into the same issue.
But then the entire Mapbox studio is written I believe without any react wrappers...and there are plenty of React components in Studio besides the map, so it does not seem like this argument holds true. Anyone have thoughts or experience they can share?
» npm install react-map-gl
» npm install react-mapbox-gl
I know this is an old post..
As I understand it, the cause is that mapbox (not react-map-gl) has a bug in it that does not transpile correctly with "npm build".
Fortunately you do NOT have to eject your app as I learned in this link: https://github.com/mapbox/mapbox-gl-js/issues/10173#issuecomment-753662795
I had to npm install worker-loader
Then add the following lines.
// had this.
import ReactMapGL, { FlyToInterpolator, NavigationControl } from 'react-map-gl'; import 'mapbox-gl/dist/mapbox-gl.css';
// added the following 6 lines.
import mapboxgl from 'mapbox-gl';
// The following is required to stop "npm build" from transpiling mapbox code.
// notice the exclamation point in the import.
// @ts-ignore
// eslint-disable-next-line import/no-webpack-loader-syntax, import/no-unresolved
mapboxgl.workerClass = require('worker-loader!mapbox-gl/dist/mapbox-gl-csp-worker').default;
Since I'm using typescript and linting, I had to add some directives to ignore warnings/errors that would otherwise stop it from compiling.
Note that I did not have to install mapboxgl since react-map-gl uses it.
But, I did need to add eslint-disable-next-line import/no-unresolved
and eslint-disable-next-line import/no-webpack-loader-syntax
combined on the same line.
I am using "react-map-gl": "^6.1.17".
The issue is caused by the transpiler. It's a bug that Mapbox is working on. Follow the suggestions here:
https://github.com/mapbox/mapbox-gl-js/issues/10173
It's also in the official documentation now.
https://docs.mapbox.com/mapbox-gl-js/api/#transpiling-v2
Does anyone have any experience incorporating mapbox with plotted points from their json in a react app? There are a serious lack of tutorials out there, and the docs for Mapbox are insane.