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。
缩放后如何保留测量线?
答案 0 :(得分:0)
将google-react-maps
从^1.1.26
更新为^1.2.26
,添加了google-maps-api": "^2.0.1
,就解决了这个问题。