Ped*_*ost 3 leaflet reactjs redux react-redux react-leaflet
我无法理解如何使用 react-leaflet 正确更新我的标记。使用这个例子:
import React from 'react';
import { render } from 'react-dom';
import { connect } from 'react-redux';
import { Map, Marker, TileLayer } from 'react-leaflet';
const map = props => (
<Map center={[51.505, -0.09]} zoom={13}>
<TileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
/>
{props.markers.map(m => (
<Marker position={m.position} />
))}
</Map>
);
const mapStateToProps = state => ({
markers: state.markers // array of objects with positions. this can change
});
render(connect(mapStateToProps)(map), document.getElementById('map-container'));
Run Code Online (Sandbox Code Playgroud)
这有效,但我不知道这是否是正确的做法。因为在这种情况下,当标记更新其位置(或有更多标记)时,Leaflet 将删除标记并放置新标记,而不是更新原始标记的位置。
所以我的问题是。我做得对还是这不是最高效的方式?
谢谢!
| 归档时间: |
|
| 查看次数: |
3174 次 |
| 最近记录: |