简体   繁体   English

PolylinesOprtions DirectionRender react-google-maps/api

[英]PolylinesOprtions DirectionRender react-google-maps/api

I try to change marker on a DirectionRender from react-google-maps/api.我尝试从 react-google-maps/api 更改 DirectionRender 上的标记。 I already change de polyline color but i dont make change de marker A and B, my code.我已经更改了折线颜色,但我没有更改标记 A 和 B,我的代码。

<DirectionsRenderer
      getIcon={(icon) => console.log("icon render", icon)}
      options={{
        directions: response,
              polylineOptions: {
           strokeColor: "#c23531",
          icons: [{
            icon:{
              path:{to},
              strokeOpacity: 1
            },
            offset:'50%'
          },{
            icon:{
              path:{fromm},
              strokeOpacity: 1
            },
            offset:'50%'
          }],
        },
      }}
/>

The DirectionsRenderer of @react-google-maps/api library doesn't have a getIcon prop name just like you have in your code. @react-google-maps/api 库DirectionsRenderer没有像您在代码中那样的getIcon道具名称。 To change the icon of the markers in the DirectionsRenderer, you need to use the options which has the properties of google.maps.DirectionsRendererOptions interface .要更改 DirectionsRenderer 中标记的图标,您需要使用具有google.maps.DirectionsRendererOptions 接口属性的options

In there, you can see a markerOptions props name which uses the google.maps.MarkerOptions interface that have the icon properties.在那里,您可以看到一个markerOptions道具名称,它使用具有icon属性的google.maps.MarkerOptions 接口

Here's a sample code (put your API key on the index.js file of the code sample to make it work) and code snippet how to use the options properties to change the icon:这是一个示例代码(将您的 API 密钥放在代码示例的 index.js 文件上以使其工作)以及如何使用options属性更改图标的代码片段:


<DirectionsRenderer
              directions={this.state.directions}
              options={{
                markerOptions: {
                  icon:
                    'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'
                }
              }}
            />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM