开发者

Mocking Google Maps Library in a GWT app

开发者 https://www.devze.com 2023-01-24 20:05 出处:网络
We\'re developing a GWT app that makes heavy use of the Google Maps Library. That is, there is always (at lea开发者_开发百科st) one MapWidget attached to the DOM.

We're developing a GWT app that makes heavy use of the Google Maps Library. That is, there is always (at lea开发者_开发百科st) one MapWidget attached to the DOM.

Is it somehow possible to mock out the Google Maps API? We're trying to

  1. speed up the loading time of the application in development mode
  2. use development mode in situations without an internet connection to prevent the error java.lang.RuntimeException: The Maps API has not been loaded


Two ways you can avoid the 'The Maps API has not been loaded' error:

1) Using a simple try / catch:

MapWidget map;

try {
      map = new MapWidget();
      doSomething();
}

2) Using the GWT AjaxLoader:

import com.google.gwt.ajaxloader.client.AjaxLoader;

AjaxLoader.loadApi("maps", "2", new Runnable() {
    public void run() {
        doSomething();
    }
}, null);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号