0

I fetch the data from database which is not a geoJson, so I use array.map function dynamically making one base on the data I fetched, then passing to component. But it seems this geoJson paste to URL as GET parameters...

if I save the geoJson as static file then import, it works.

How can I change the GET method to POST method in React-map-gl??

 <Source
  type="geojson"
  data={myData}
  ref={_sourceRef}
  >
 <Layer {...stopPointLayer} />
 </Source>

1 Answers1

0

We can identify the root cause here by looking at the source code for uber/react-map-gl and mapbox/mapbox-gl-js. When you pass data={myData} in your Source component, /react-map-gl relies on Mapbox's GeoJSONSource#setData, as indicated in src/components/source.js here:

if (type === 'geojson') {
  source.setData(sourceOptions.data);
}

As indicated in the API reference for setData, the data argument must be a GeoJSON data object or a URL to one. It sounds like it might be the case that when you are passing myData dynamically, it might not be in the correct format, but it is when you configure it as a static file. I don't see a reason why the issue would be related to GET vs POST requests in this particular scenario.

Adriana Babakanian
  • 1,239
  • 6
  • 8