React中的Google Maps MeasureTool-缩放后测量线消失

时间:2018-06-21 11:08:52

标签: javascript reactjs google-maps google-maps-api-3

React应用使用measuretool-googlemaps-v3

import {MapControl} from 'google-react-maps'
import MeasureTool from 'measuretool-googlemaps-v3/lib/MeasureTool'

MeasureTool的构造:

  createMeasureTool() {

    this.measureTool = new MeasureTool(this.props.map, {
      showSegmentLength: false,
      tooltip: false,
      contextMenu: false
    })
    this.measureTool._helper.formatLength = function(value) {
      return this._formatLengthMetric(value) + " / " + this._formatLengthImperial(value * 3.28084)
    }
  }

在用户放大或缩小地图之前,测量效果良好。然后,测量线消失,需要重新创建MeasureTool实例以再次使用测量功能。缩放过程中不会重新渲染Map / MeasureTool / MapControl。

缩放后如何保留测量线?

1 个答案:

答案 0 :(得分:0)

google-react-maps^1.1.26更新为^1.2.26,添加了google-maps-api": "^2.0.1,就解决了这个问题。