我有一个简单的组件来在地图上选择点,然后显示与此点相关的一些GeoJSON数据:
import React, { Component } from 'react';
import { Map, Marker, TileLayer, GeoJSON } from 'react-leaflet';
import 'leaflet/dist/leaflet.css';
import { connect } from 'react-redux';
import './style.css';
import { setPoint, fetchData } from '../../actions/map';
@connect(store => {
return {
map: store.map
}
})
class MyMap extends Component {
mapClick(e) {
this.props.dispatch(setPoint(e.latlng));
this.props.dispatch(fetchData(e.latlng));
}
render() {
const marker = () => {
if(this.props.map.point) {
return <Marker position={this.props.map.point} />;
}
};
const data = () => {
if(this.props.map.data.length > 0) {
const …Run Code Online (Sandbox Code Playgroud)