【问题标题】:Polyline not rendering on react-google-map折线未在 react-google-map 上呈现
【发布时间】:2018-09-18 08:21:24
【问题描述】:

我正在为多种类型的几何 POINT、LINESTRING、POLYLINE 等制作地理数据可视化工具,方法是根据类型动态生成 。

基本上数据是这样的,普通geojson等

"geometry": {
   "type": "Point",
   "coordinates": [
       144.25178598,
       -36.73540441
   ]
},
"geometry": {
    "type": "LineString",
    "coordinates": [[
        144.25178598,
        -36.73540441
    ], [
        144.25178598,
        -36.73540441
    ]]
}

当构建一个圆形时可以完美呈现,但当它切换到多段线时它永远不会显示。

render() {
  return (
    <Polyline
      path={[
        { lat: -36.73540441, lng: 144.25178598 },
        { lat: -36.73590441, lng: 144.25178198 }
      ]}

      //tried both these to no avail
      // path={this.getPositions(mkr.geometry.coordinates)}

      defaultPath={this.getPositions(mkr.geometry.coordinates)}
      key={mkr.id}
      label={"Test"}
      clickable
      options={{
        strokeColor: '#ff2343',
        strokeOpacity: '0.0',
        strokeWeight: 2
      }}
      visible
    />
  );
}

当硬编码path 并从数据源中派生它时。我打算为 Polygon、MultiPolygon 等做这个。

【问题讨论】:

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


    【解决方案1】:

    我已经复制了您的代码,并且它适用于我。由于您的 strokeOpacity 设置为零并且它变得完全透明,因此您看不到任何绘制的折线。

    strokeOpacity: '0.0',
    

    将此设置为大于零的值。喜欢:

    strokeOpacity: '0.5',
    

    这是关于 stackblitz 的示例:
    https://stackblitz.com/edit/react-rppnco

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-02
    • 2014-03-24
    • 2022-06-22
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    相关资源
    最近更新 更多