GithubHelp home page GithubHelp logo

Comments (7)

joelkravets avatar joelkravets commented on May 20, 2024 2

I noticed this problem as well when we were using this project internally in our own ReactJS application.

Instead of using:
import SnazzyInfoWindow from 'snazzy-info-window';

Use the following:
let SnazzyInfoWindow = require('snazzy-info-window');

The reason the bug exists is because of this line right here:
export default class SnazzyInfoWindow extends google.maps.OverlayView {

We might be able to resolve this issue by adding a wrapper object around SnazzyInfoWindow which checks for the existence of google before trying to create the subclass.

Thanks for the feedback. Hopefully the above solution will work for you in the mean time.

from snazzy-info-window.

yeedle avatar yeedle commented on May 20, 2024 1

Thanks, the above solution works like a charm. And thanks for responding so fast!

One more question, how do I import the css?

from snazzy-info-window.

joelkravets avatar joelkravets commented on May 20, 2024 1

You can import the css in your project with the following snippet:

import 'snazzy-info-window/dist/snazzy-info-window.min.css';

Note to self:
Add documentation about imports when fixing this bug.

from snazzy-info-window.

goldfinch avatar goldfinch commented on May 20, 2024 1

Any updates on this?

I'm using the following as well:
let SnazzyInfoWindow = require('snazzy-info-window');

but Uncaught ReferenceError: google is not defined still appears occasionally and stops all other scripts

from snazzy-info-window.

yeedle avatar yeedle commented on May 20, 2024

Thanks once again! You're awesome!

from snazzy-info-window.

pttsky avatar pttsky commented on May 20, 2024

@goldfinch where exactly do you place that line in the code?

I was having literally the same issue after just replacing import to require statements in the top of my file. But that changes nothing in general.

But there is one benefit - you are allowed to use require statements anywhere in your file.

I used <script src=https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=initMap async defer'></script> and then in my JS:

window.initMap = function() {
  const SnazzyInfoWindow = require('snazzy-info-window');
  new SnazzyInfoWindow({ /* ... */ });
}

P.S. For this case, const is more suitable over let.

from snazzy-info-window.

goldfinch avatar goldfinch commented on May 20, 2024

@pttsky sorry for the late response,

I solved this issue using callback, to make sure that the google library loads first, eg:

<script>
window.initSnazzy = function(){
    
    let SnazzyInfoWindow = require('snazzy-info-window');
    
    // ....
};
</script>

<script async defer src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initSnazzy"></script>

from snazzy-info-window.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.