question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose Resize Event on Google Maps

See original GitHub issue

So I’ve been using this component for a while and ran into a known issue with the Google Maps Api v3. Namely this issue. The upshot being that when the component updates I need to trigger a resize event. Currently I’m doing this in the most horrible way imaginable:

export const ListingsMap = compose<WithScriptjsProps & WithGoogleMapProps, MapProps>(
  withProps({
    googleMapURL: `https://maps.googleapis.com/maps/api/js?key=${googleMapsApiKey}&v=3.exp&libraries=geometry,drawing,places`,
    loadingElement: <div style={{height: `100%`}}/>,
    containerElement: <div id="map" className="map"/>,
    mapElement: <div id="map" className="map" ref="map"/>,
  }),
  withScriptjs,
  withGoogleMaps,
  lifecycle({
    componentDidMount() {
      google.maps.event.trigger((window as any).googleMapsObject, 'resize');
    },
    componentDidUpdate() {
      google.maps.event.trigger((window as any).googleMapsObject, 'resize');
    },
    componentWillMount() {
      const refs: { map?: GoogleMap} = {};
      this.setState({
        onMapWillMount: ref => {
          refs.map = ref;
          (window as any).googleMapsObject = (refs.map as Component<any>).context['__SECRET_MAP_DO_NOT_USE_OR_YOU_WILL_BE_FIRED'];
        },
      });
    },
  }),
)((props) => (
  <GoogleMap
    ref={props.onMapWillMount}
    options={mapOptions}
  />
));

I’ve cut a lot out for brevity, essentially my issue is that I want to have the ability to resize as an exposed feature. Or via the map object itself exposed via some stable means; I’m open to suggestions. However, I think we should at least in principal expose as much of the Google Maps Api as possible/feasible?

I am more than happy to work on this an submit a PR but thought I’d get some guidance first about implementation. Hopefully I’ve been thorough enough and you guys think this is worth some time 😄

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
tomchentwcommented, Oct 31, 2017

Yeah, I remove the event trigger in v8.0.0 rewrite.

Since we have a jscodeshift API, I’m thinking we can just add event trigger function on the component itself:

refs.map.trigger('resize');

// in GoogleMap.js
trigger(...args) {
  return google.maps.event.trigger(this.context[MAP], ...args);
}

What do you think?

3reactions
StefanoPastorecommented, Jan 22, 2018

@tomchentw can i make a PR with your solution:

refs.map.trigger('resize');

// in GoogleMap.js
trigger(...args) {
  return google.maps.event.trigger(this.context[MAP], ...args);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Maps API v3 resize event - Stack Overflow
Resize event : Developers should trigger this event on the map when the div changes size. Therefore I am using: google.maps.event.trigger(map, ' ...
Read more >
Maps JavaScript API Release Notes - Google Developers
Fixes an issue where google.maps.event. ... The MapsNetworkError , MapsRequestError , and MapsServerError classes are now publicly exposed and documented.
Read more >
ngmap - npm
The Simplest AngularJS Google Maps V3 Directive. ... you need to trigger the "resize" event and possible recenter the map. var center =...
Read more >
React Google Maps Api Style Guide
The GoogleMap component uses React Context internally to pass the map instance around. For the convenience the value is exposed with hook useGoogleMap...
Read more >
[Google Maps Library] Correctly remove "resize" event listener.
If AutoFitOnWindowResize is False the event listener EventListener("resize", $parameters.ObjResize) won't be set and no error will be logged in console. There ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found