【问题标题】:SDK for Bing Maps必应地图 SDK
【发布时间】:2019-11-22 16:00:20
【问题描述】:

我目前正在创建一个 SDK 以使用 Bing 地图。当我运行 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, 13.4225),
    mapTypeId: Microsoft.Maps.MapTypeId.aerial,
    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();

});
});

【问题讨论】:

  • 没人知道吗?

标签: sdk requirejs bing-maps sap-lumira


【解决方案1】:

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

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

【讨论】:

  • 感谢您的回答。我更改了如下代码。现在,调用了函数“getMap”,但出现错误:Microsoft is not defined ReferenceError: Microsoft is not defined at GetMap.
  • 在您的 init 函数之后,您可以调用 GetMap。在加载地图脚本之前将其删除。 GetMap 将在脚本加载时由 Bing Maps API 调用。
【解决方案2】:

​与此同时,我已经解决了我的问题,如下所示。

文件contribution.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 地图显示出来了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    相关资源
    最近更新 更多