小编Tit*_*lav的帖子

使用react-leaflet渲染GeoJSON

我有一个简单的组件来在地图上选择点,然后显示与此点相关的一些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)

reactjs redux react-redux react-leaflet

8
推荐指数
2
解决办法
8364
查看次数

标签 统计

react-leaflet ×1

react-redux ×1

reactjs ×1

redux ×1