引用错误Ymaps未定义

时间:2016-11-23 08:44:41

标签: javascript java smartgwt yandex-maps

使用Yandex Map定义的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未定义

1 个答案:

答案 0 :(得分:0)

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