【发布时间】:2020-03-23 09:19:42
【问题描述】:
我已经在我的 react 项目 https://react-leaflet.js.org/en/ 中实现了传单地图库,并实现了如下所示的 geojson 地图组件
class MapContainer extends React.Component {
state = {
greenIcon: {
lat: 8.3114,
lng: 80.4037
},
zoom: 8
};
grenIcon = L.icon({
iconUrl: leafGreen,
iconSize: [24, 24], // size of the icon
//iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
popupAnchor: [-3, -16]
});
render() {
const positionGreenIcon = [
this.state.greenIcon.lat,
this.state.greenIcon.lng
];
return (
<div className="mapdata-container">
<Map className="map" style={{height:'100%',width:'100%'}} center={positionGreenIcon} zoom={this.state.zoom}>
<GeoJSON data={geo}/>
<Marker position={positionGreenIcon} icon={this.grenIcon}>
<Popup>I am a green leaf</Popup>
</Marker>
</Map>
</div>
);
}
}
export default MapContainer;
看起来像这样
我想用不同的颜色为每个省份着色,但文档中没有很多关于如何做到这一点的内容。
这是我使用的 geojson 文件。 https://raw.githubusercontent.com/thejeshgn/srilanka/master/electoral_districts_map/LKA_electrol_districts.geojson
我如何fill每个省有不同的颜色。
【问题讨论】:
标签: javascript reactjs leaflet geojson react-leaflet