ElemeFE / react-amap

基于 React 封装的高德地图组件。AMap Component Based On React.
https://elemefe.github.io/react-amap/articles/start
MIT License
1.04k stars 151 forks source link

Polyline 组件数组 重绘时未完全清除上一次绘制的线条 #38

Closed crcrcry closed 7 years ago

crcrcry commented 7 years ago

react-amap version

OS/Browers version

Reproduction Link

Steps to reproduce

Code

export default class MapArea extends Component {
  constructor(){
    super();

    this.mapPlugins = ['ToolBar'];
    this.mapEvents = {
      click: (e) => {
        this.props.changePosition(e.lnglat);
      }
    }
  }

  render(){
    const polylineArr = this.props.roads.map((item, index) => {
      return(
        <Polyline
          key={`polyline${index}`}
          path={[{
              longitude:item.coordinates[0][0],
              latitude: item.coordinates[0][1],
            }, {
              longitude:item.coordinates[1][0],
              latitude: item.coordinates[1][1],
            }]}
          style={{strokeColor: '#f00', strokeOpacity: 0.5+0.5*Number.parseFloat(item.probability), strokeWeight: 7}}
        />
      )
    });

    return (
      <div>
        <div style={style.mapArea}>
          <Map plugins={this.mapPlugins} center={this.props.position} events={this.mapEvents} zoom={17}>
            <Marker
              position={this.props.position}
            />
            {polylineArr}
          </Map>
        </div>
      </div>
    )
  }
}

What is Expected?

What is actually happening?

Screenshot

上一轮查询,ui + 控制台

2017-08-13 4 24 50

本轮查询,ui + 控制台

2017-08-13 4 25 10
crcrcry commented 7 years ago

多测试了几次发现:如果新的 polyline 数组没有老的数组长,那老的数组长出来的那部分线条则不会重绘,仍然留在地图上。

ioslh commented 7 years ago

很抱歉,确实是个 bug,今天会发个新版本修复这个问题。

ioslh commented 7 years ago

你好,更新 1.0.3 版本修复了这个问题

crcrcry commented 7 years ago

非常感谢,饿了么大前端很赞