visgl / react-map-gl

React friendly API wrapper around MapboxGL JS
http://visgl.github.io/react-map-gl/
Other
7.8k stars 1.35k forks source link

[Bug] Input data given to 'xxx' is not a valid GeoJSON object #2381

Closed elvince closed 2 months ago

elvince commented 5 months ago

Description

hi,

With my source setup like: <Source id="missions" type="geojson" data={routes} lineMetrics={true}>

with routes be set as undefined, I have this warning: Input data given to 'missions' is not a valid GeoJSON object

Expected Behavior

no warning as data can be undefined as per typsecript definition

Steps to Reproduce

create a map component with souce like <Source id="missions" type="geojson" data={routes} lineMetrics={true}> with routes as

  const [routes, setRoutes] = useState<
    turf.FeatureCollection<turf.LineString, {test:string}> | undefined
  >(undefined);

Environment

Logs

No response

elvince commented 3 months ago

Hi,

As per mapbox documentation, data should be optional: https://docs.mapbox.com/style-spec/reference/sources/#geojson

data
Optional .
A URL to a GeoJSON file, or inline GeoJSON.

Could you please fix this so undefined is properly managed? As of now, I must send an empty feature collection to avoid the warning.

Thanks,

elvince commented 3 months ago

Might be linked to : https://github.com/mapbox/mapbox-gl-js/issues/5986

Pessimistress commented 2 months ago

Layer component prop types are directly imported from mapbox-gl. This is an issue that should be fixed upstream.