Search code examples
javascriptjavasmartgwtyandex-maps

Reference error Ymaps is not defined


JS file with Yandex Map definition:

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; 
 }-*/; 
}

And then I call this js code in another file to place map in smartgwt layout.

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

  layoutRight.addMember(canvas);

But in a browser I am getting Reference error: Ymaps is not defined


Solution

  • Yandex map API can't be loaded in one file, and used in another in my project. Therefore i had to create an html file. In header of it I loaded api and in script wrote js code using api. All necessary parameters from java file I send with GET request. And the result of html file is placed inside my HTMLPane of smartgwt with its setContentsUrl method.