Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript react google maps Uncaught TypeError:无法读取属性';过度使用目标';空的_Javascript_Google Maps_Reactjs - Fatal编程技术网

Javascript react google maps Uncaught TypeError:无法读取属性';过度使用目标';空的

Javascript react google maps Uncaught TypeError:无法读取属性';过度使用目标';空的,javascript,google-maps,reactjs,Javascript,Google Maps,Reactjs,我正在使用react google maps软件包,当我离开包含该地图的页面时,会收到错误消息: Uncaught TypeError: Cannot read property 'overlayMouseTarget' of null 以下是GoogleMap组件的代码: const GMap = withGoogleMap((props) => ( <GoogleMap ref={props.onMapMounted} defaultZoom={12}

我正在使用react google maps软件包,当我离开包含该地图的页面时,会收到错误消息:

Uncaught TypeError: Cannot read property 'overlayMouseTarget' of null
以下是GoogleMap组件的代码:

const GMap = withGoogleMap((props) => (
  <GoogleMap
    ref={props.onMapMounted}
    defaultZoom={12}
    zoom={props.zoom}
    onDragEnd={props.onZoomChanged}
    onZoomChanged={props.onZoomChanged}
    defaultCenter={props.defaultCenter}
    center={props.center}
  >
    {
      props.markers && props.markers.map((data, index) => (
        <OverlayView
          key={index}
          position={{
            lat: data.get('loc').get('geo').get('lat'),
            lng: data.get('loc').get('geo').get('lng'),
          }}
          mapPaneName={OverlayView.OVERLAY_MOUSE_TARGET}
          getPixelPositionOffset={(width, height) => ({ x: -(width / 2), y: -(height) })}
        >
          <WnmMarker
            text={data.get('text')}
            highlight={data.get('highlight')}
          />
        </OverlayView>
      ))
    }
  </GoogleMap>
));
constgmap=withGoogleMap((道具)=>(
{
props.markers&&props.markers.map((数据,索引)=>(
({x:-(宽度/2),y:-(高度)})
>
))
}
));
有人能告诉我是什么引起的吗


谢谢

似乎当您离开页面时,map元素不再存在,但绑定到它的事件仍然存在

根据React组件生命周期,我们可能希望在您的组件中包含以下两项:componentDidMount和*componentWillUnmount*

constructor(props) {
  super(props);
  // ...
}

componentDidMount() {
  // bind the event
}

componentWillUnmount() {
  // unbind the event
}

render() {
  // ...
}
我不知道你是否已经有了上面的一对来初始化你的地图和它的事件

然而,仍然有很多GoogleMap库,但不确定它们是否都能根据React组件生命周期很好地处理所有事件。下面还有一个,我也有基于它的简单指南:

我的向导:

图书馆:


如果这仍然不是您想要的,请随时发布更多您的代码以供参考,然后我们可能会一起找到最好的方法

您的答案有意义。我认为这个问题与在GoogleMap组件本身中呈现覆盖视图列表有关,并且在移除Map实例之前它们没有被移除。我将尝试从呈现GMap组件的组件生成列表,看看它是否会改变行为。至于GoogleMapReact,我以前使用过它,我发现它更完整了,所以决定切换到react GoogleMaps。