0

带有 Yandex 地图定义的 JS 文件:

public class Ymap {  
  public static final native Object getMap() /*-{
    var myMap;

    function init() {
        // Creating an instance of the map and binding it to the container with the specified ID
        // ("map").
        myMap = new ymaps.Map('map', {
            center : [ 55.010251, 82.958437 ], // Новосибирск
            zoom : 9
        }, {
            searchControlProvider : 'yandex#search'
        });

    }
    YMaps.load(init);

    return myMap; 
 }-*/; 
}

然后我在另一个文件中调用这个 js 代码以将地图放置在 smartgwt 布局中。

  Canvas canvas = new Canvas();
  canvas.addChild((Canvas)Ymap.getMap());

  layoutRight.addMember(canvas);

但是在浏览器中我收到参考错误:Ymaps is not defined

4

1 回答 1

0

Yandex 地图 API 无法加载到一个文件中,并在我的项目中用于另一个文件。因此我不得不创建一个 html 文件。在它的标题中,我加载了 api,并在脚本中使用 api 编写了 js 代码。我使用 GET 请求发送的 java 文件中的所有必要参数。html 文件的结果通过 setContentsUrl 方法放置在我的 smartgwt 的 HTMLPane 中。

于 2016-12-15T06:02:03.563 回答