I am attempting to make a choropleth in react
using react-leaflet-choropleth
.
I have leaflet working fine.
Now when I try to load a geojson (crimes_by_district) using the library I am getting an error when mapping through the features, specifically:
Cannot read property 'map' of undefined
It seems I'm not accurately referencing the right array to map.
I have looked at the issues in the git repo and tried the suggestions with no luck. I am wondering if perhaps I am referencing the incorrect values from the geoJson
I am using.
Below is my code:
Leaf.js (rendered in App.js)
import React, { Component } from 'react';
import { Map, TileLayer } from 'react-leaflet';
import classes from './leaf.module.css'
import Choropleth from 'react-leaflet-choropleth'
import geojson from "./assets/crimes_by_district.geojson";
const style = {
fillColor: '#F28F3B',
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.5
};
class Leaf extends Component {
render() {
return (
<Map>
<Choropleth
data= {{type: 'FeatureCollection', features: geojson.features}}
valueProperty={(feature) => feature.properties.value}
// visible={(feature) => feature.id !== active.id}
scale={['#b3cde0', '#011f4b']}
steps={7}
mode='e'
style={style}
onEachFeature={
(feature, layer) => layer.bindPopup(feature.properties.label)
}
ref={(el) => this.choropleth = el.leafletElement}
/>
</Map>
);
}
}
export default Leaf;