googlemaps / googlemaps/react-wrapper

[ Map, Marker ] WebGL Uncaught Error: Not initialized. - Next js

Ouverte
#641 1 commentaire 3 réactions 1 personne assignée Réclamée par @wangela Voir sur GitHub
triage me type: bug
Langage dominant
TypeScript
Étoiles
381
Forks
50
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Thanks for stopping by to let us know something could be better!

---
**PLEASE READ**

If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/). This will ensure a timely response.

Discover additional support services for the Google Maps Platform, including developer communities, technical guidance, and expert support at the Google Maps Platform [support resources page](https://developers.google.com/maps/support/).

If your bug or feature request is not related to this particular library, please visit the Google Maps Platform [issue trackers](https://developers.google.com/maps/support/#issue_tracker).

Check for answers on StackOverflow with the [google-maps](http://stackoverflow.com/questions/tagged/google-maps) tag.

---

Please be sure to include as much information as possible:

#### Environment details

1. Specify the API at the beginning of the title (for example, "Places: ...")
2. OS type and version
3. Library version and other environment information

#### Steps to reproduce

1. Refresh

#### Code example

_app.tsx
```jsx







```

some_page.tsx
```jsx

console.info(marker, latLng)}
/>


```

Map.tsx
```tsx
import { useDeepCompareEffectForMaps } from "@/hooks/useDeepCompareEffectForMaps";
import React from "react";
import useDeepCompareEffect from "use-deep-compare-effect";

type MapProps = {
style: { [key: string]: string };
onClick?: (e: google.maps.MapMouseEvent) => void;
onIdle?: (map: google.maps.Map) => void;
} & google.maps.MapOptions &
React.PropsWithChildren;

const Map = ({ onClick, onIdle, children, style, ...options }: MapProps) => {
const ref = React.useRef(null);
const [map, setMap] = React.useState();

React.useEffect(() => {
if (ref.current && !map) {
setMap(new window.google.maps.Map(ref.current, options));
}
}, [ref, map]);

useDeepCompareEffectForMaps(() => {
if (map) {
map.setOptions(options);
}
}, [map, options]);

React.useEffect(() => {
if (map) {
["click", "idle"].forEach((eventName) =>
google.maps.event.clearListeners(map, eventName)
);

if (onClick) {
map.addListener("click", onClick);
}

if (onIdle) {
map.addListener("idle", () => onIdle(map));
}
}
}, [map, onClick, onIdle]);
// [END maps_react_map_component_event_hooks]

// [START maps_react_map_component_return]
return (
<>


{React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
// set the map prop on the child component
// @ts-ignore
return React.cloneElement(child, { map });
}
})}

);
};

export default Map;
```

#### Stack trace
```console
Uncaught Error: Not initialized.
at aZ (webgl.js:182:509)
at D8a.wj (webgl.js:965:13)
at C8a.wj (webgl.js:551:262)
at B8a.m (webgl.js:552:228)
at Sla (map.js:18:28)
at Rla (map.js:19:203)
at Ru (map.js:16:496)
at Object.Lj (map.js:62:233)
at HTMLDivElement. (common.js:210:701)
```

Following these steps will guarantee the quickest resolution possible.

Thanks!

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.