2016-11-23 67 views
0

JS與Yandex的地圖定義文件:引用錯誤Ymaps沒有定義

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在另一個文件中的代碼放置在地圖佈局S​​martGWT的。

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

    layoutRight.addMember(canvas); 

但在瀏覽器中我收到引用錯誤:Ymaps沒有定義

回答

0

Yandex圖API不能在一個文件中加載,並在我的項目在其他使用。所以我不得不創建一個html文件。在它的標題中,我加載了api,並在腳本中使用api編寫了js代碼。我用GET請求發送的所有必要參數。而HTML文件的結果放在我的HTMLPane的smartGwt和它的setContentsUrl方法中。