简体   繁体   English

如何在react-google-maps中停止鼠标悬停和onmouseout事件上的标记闪烁?

[英]How to stop flickering of Markers on mouseover and onmouseout events in react-google-maps?

I'm using React.js and react-google-maps to implement this. 我正在使用React.js和react-google-maps来实现这一点。 I'm trying to display the InfoWindow on Hovering any Marker and hiding when mouse leaves the Marker. 我试图显示InfoWindow悬停任何标记并在鼠标离开标记时隐藏。 Here's the link for code. 这是代码的链接。 ( https://codesandbox.io/s/loving-microservice-88oop ) https://codesandbox.io/s/loving-microservice-88oop

It's quite simple actually. 实际上这很简单。 Let's go through this together. 让我们一起来看看。

  1. You are hovering the element 你正在徘徊这个元素
  2. The element gets visible, you are now with your mouse cursor over the element 元素变得可见,现在您将鼠标光标放在元素上
  3. Because you are now no longer hovering the marker (you are now actually hovering the popup) the popup get's hidden. 因为你现在不再盘旋标记(你现在实际上正在盘旋弹出窗口)弹出窗口隐藏了。
  4. Now that the popup is hidden you are basically starting from 1) again 现在弹出窗口被隐藏了,你基本上是从1)开始

How to prevent this: 如何防止这种情况:

Option 1: Change your hover so that it's also applied to the popup and not just for the marker 选项1:更改悬停,以便它也应用于弹出窗口,而不仅仅是标记

Option 2: Change the markers position. 选项2:更改标记位置。 You can do this by changing this line (line 36 in your example): 您可以通过更改此行(示例中的第36行)来执行此操作:

position={{
            lat: selectedPark.geometry.coordinates[1] + 0.0500,
            lng: selectedPark.geometry.coordinates[0]
          }}

I solved this by using pixelOffset option available as props. 我通过使用pixelOffset选项作为道具来解决这个问题。 In the other answer, It was using lat as offset but when we zoom, it no longer persists in that position. 在另一个答案中,它使用lat作为偏移,但是当我们缩放时,它不再保持在那个位置。

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

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