必应地图的SDK

我当前正在创建一个使用Bing Maps的SDK。当我运行SDK时,bing地图没有显示。

文件“ component.js”包含以下内容:

define(["sap/designstudio/sdk/component","d3"],function(Component,d3,unusedDummy) {
Component.subclass("com.xxx.bingmaps.BingMaps",function() {

 this.init = function() {

    var url = 'http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=[MY_BING_KEY]'; 

        const script = document.createElement("script");
        script.type = 'text/javascript';
        script.src = url; 
        script.async = true;
        script.defer = true;
        document.head.appendChild(script);

        function GetMap() {
            this.map = new microsoft.Maps.Map('#myMap',{
              center: new microsoft.Maps.Location(52.527222,13.4225),mapTypeId: microsoft.Maps.MapTypeId.aerial,zoom: 10
          });

        };
    };

   });
});

在文件“ contribution.xml”中,以下代码将其调用

<requireJs modes="commons m">res/js/component</requireJs>

有人暗示错误在哪里吗?

亲切的问候, 蒂莫

这是我的新代码:

define(["d3","sap/designstudio/sdk/component"],function(d3,Component) {  

function GetMap() {
    var map = new microsoft.Maps.Map('#BingMaps',{         
    center: new microsoft.Maps.Location(52.527222,zoom: 10
    });
};   

Component.subclass("com.xxx.bingmaps.BingMaps",function() {

    this.init = function() {

        var url = 'https://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=[MY_KEY]'; 

        const script = document.createElement("script");
        script.type = 'text/javascript';
        script.src = url; 
        script.async = true;
        script.defer = true; 
        document.head.appendChild(script);

    };
      GetMap();

});
});
XIAOYING178 回答:必应地图的SDK

GetMap函数位于init函数内部,而不是全局函数。这样,在加载地图脚本URL时,将无法找到/访问GetMap函数。几个选项:

  • 将GetMap函数设为全局。
  • 同步加载脚本URL并调用代码以内联加载地图。
,

同时,我已经解决了如下问题。

文件tribution.xml:

<jsInclude>http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=[MY_KEY]</jsInclude>     
<jsInclude>res/js/component.js</jsInclude>

文件component.js:

sap.designstudio.sdk.Component.subclass("com.xxx.bingmaps.BingMaps",function() {

this.init = function() {
    var mapOptions = { center: new Microsoft.Maps.Location(LAT,LONG),mapTypeId: Microsoft.Maps.MapTypeId.aerial,zoom: 15 };
    this.map = new Microsoft.Maps.Map(this.$()[0],mapOptions);             
    };
});

现在,将显示bing地图。

本文链接:https://www.f2er.com/3144574.html

大家都在问