I've been trying to render GeoJSON data with React Leaflet & Typescript but can't seem to get it to work. I'm pretty sure my GeoJSON file is fine but typescript is complaining that is isn't the correct type. I am kinda stumped on what I'm supposed be passing the GeoJSON component if this isn't the correct type.
The error message getting:
Property 'type' is missing in type '({ type: string; geometry: { type: string; coordinates: number[]; }; properties: { prop0: string; prop1?: undefined; }; } | { type: string; geometry: { type: string; coordinates: number[][]; }; properties: { prop0: string; prop1: number; }; } | { ...; })[]' but required in type 'GeoJsonObject'.ts(2741)
index.d.ts(58, 5): 'type' is declared here.
GeoJSON.d.ts(7, 5): The expected type comes from property 'data' which is declared here on type 'IntrinsicAttributes & GeoJSONProps & RefAttributes<GeoJSON<any, Geometry>>'
Here is the GeoJSON file im using:
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
"properties": {"prop0": "value0"}
},
{ "type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
},
{ "type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
]
},
"properties": {
"prop0": "value0",
"prop1": {"this": "that"}
}
}
]
}
and last but not least my react code:
import test from "../test.json"
...
<MapContainer style={{height: 400, width: 600}} zoom={12} center={[0,0]}>
{this.state.geoJSON && ( <GeoJSON attribution="NEOM Map Data" data={test.features}/> )}
</MapContainer>
I also tried to pass in the value of my test json as a prop to to my map component. In this case, typescript didnt complain about incorrect typings but doesn't seem to render anything? At least to me it looks like my map is completely empty.