branflake2267 / GWT-Maps-V3-Api

GWT Maps V3 Javascript Bindings
Other
144 stars 113 forks source link

Loading Map without loadMapApi() #235

Open aouskaroui opened 7 years ago

aouskaroui commented 7 years ago

Hello everyone, Thank you for this great Gwt library ! I'm a beginner in GWT and I'm having some questions: Is it possible to run the Map without calling the loadMapApi() method ? Actually, when I call loadMapApi(), the Map loads fine for a first sight but it doesn't provide any interaction. It means that all buttons, markers or whatever I put on it are shown in the map but they don't really work ! Otherwise, when I just call the draw() method, without calling loadMapApi(), the map loads fine and all buttons, markers are interacting. The problem is when I want to add the AutoComplete text box. I get this error "Cannot read property 'Autocomplete' of undefined". However, when I call loadMapApi(), I don't get that error. The map loads fine with the Autocomplete box on it, but there is no interaction. I just get a good looking frozen Map ! I don't know if there is a problem with the Thread or something. I just copied the provided code with no change.

dpdearing commented 7 years ago

I'm also having a problem with using LoadApi.go()...if that's what you mean (although not the same problem that you describe). My issue is that the map does not appear when first loaded and doesn't show up until resizing the browser window. Anyway, I'll share what seems to work for me.

I've found that I can directly load the Maps API by including the <script> tag from the Google Maps API tutorial in my html page. I'm not sure if there's a race condition with determining if onModuleLoad happens before the script finishes loading. Might need to leave out the async attribute.

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
    async defer></script>
aouskaroui commented 7 years ago

Hello, I had the same problem once. I thought it was something with the GWT panels or the resize functions, so I tried many kinds of panels and the MapWidget.triggerResize() method but nothing worked for me. Finally, I figured out that the map needs some time to load (until getting the Ajax callbacks answers) so I put the draw() method within a Timer instance and the problem was resolved. Here is a snap of the way I did it: Timer timer = new Timer() { @Override public void run() { draw(); setContent(mapWidget);
} }; timer.schedule(4000); }

treethinker commented 7 years ago

Thanks. I hope to be able to apply this as well.

On 16 Jan,17, at 04:58, aouskaroui notifications@github.com wrote:

Hello, I had the same problem once. I thought it was something with the GWT panels or the resize functions, so I tried many kinds of panels and the MapWidget.triggerResize() method but nothing worked for me. Finally, I figured out that the map needs some time to load (until getting the Ajax callbacks answers) so I put the draw() method within a Timer instance and the problem was resolved. Here is a snap of the way I did it: Timer timer = new Timer() { @Override public void run() { draw(); setContent(mapWidget); } }; timer.schedule(4000); }

� You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

aouskaroui commented 7 years ago

Okay. If you're using the loadMapApi() method, you just have to call it inside the Timer run() like I did, but instead the draw() method. Please let me know if it fix the issue...

aouskaroui commented 7 years ago

Hello again, actually there are some differences between testing on local and on a web server. For me, MapWidget.triggerResize() resolved the problem described by "dpdearing" above.