Jquery getscript之后Javascript API无法正常工作

Jquery getscript之后Javascript API无法正常工作,javascript,jquery,sharepoint,getscript,here-api,Javascript,Jquery,Sharepoint,Getscript,Here Api,我正在试验javascript映射API。我开始创建一个小网页,调用API来显示地图并添加一个标准标记。工作得很好。现在我想在SharePoint中使用它,对列表使用JSLink。因此,我在SharePoint上提供了JQuery,并编写了如下内容: $.getScript("http://js.cit.api.here.com/se/2.5.3/jsl.js?with=maps", function () { nokia.Settings.set("app_id", "MY APP ID");

我正在试验javascript映射API。我开始创建一个小网页,调用API来显示地图并添加一个标准标记。工作得很好。现在我想在SharePoint中使用它,对列表使用JSLink。因此,我在SharePoint上提供了JQuery,并编写了如下内容:

$.getScript("http://js.cit.api.here.com/se/2.5.3/jsl.js?with=maps", function () {
nokia.Settings.set("app_id", "MY APP ID");
nokia.Settings.set("app_code", "MY APP CODE");
// Use staging environment (remove the line for production environment)
nokia.Settings.set("serviceMode", "cit");

var mapContainer = document.getElementById("mapContainer");

var map = new nokia.maps.map.Display(mapContainer, {
    // initial center and zoom level of the map - Around U2U.
    center: [50.886944, 4.263056],
    zoomLevel: 10
});
});

nokia.maps.map返回此处未定义的值。在一个普通的代码块中使用它,并带有一个用于引用api的脚本标记,效果很好。发生了什么事???

异步加载Maps API比这稍微复杂一些,因为尽管您已将引导程序库脚本添加到页面中,但在尝试启动身份验证之前,您还没有等到Maps模块本身加载完毕

1)首先,您需要像在代码中那样将
添加到标题中。请注意,URL具有附加的
blank=true
参数,因此仅加载引导

function asyncLoadMapsLibrary() {
  $.getScript('http://js.cit.api.here.com/se/2.5.4/jsl.js?blank=true', 
     hereMapLoaderCallback);
}
2)然后在引导回调上,您可以决定使用
nokia异步加载和初始化哪些功能。features.load()
-
onApiFeaturesLoaded()
是来自回调的回调

function hereMapLoaderCallback() {
  var fmatrix = nokia.Features.getFeaturesFromMatrix(['maps']),

  // This callback is run if the feature load was successful.
    onApiFeaturesLoaded = function () {
      authenticate(HereMapsConstants.AppIdAndToken);
      var map = createMap(
        document.getElementById('mapContainer'));
      map.addListener('displayready', function () {
        afterHereMapLoad(map);
      }, false);
    },
    // This callback is run if an error occurs during the feature loading
    onApiFeaturesError = function (error) {
      alert('Whoops! ' + error);
    };
  nokia.Features.load(
    fmatrix,
    onApiFeaturesLoaded,  // an callback when everything was successfully loaded
    onApiFeaturesError,   // an error callback
    null,    // Indicates that the current document applies
    false  //Indicates that loading should be asynchronous
  );
}
3)此时,您可以使用
app\u id
app\u code
进行身份验证。请注意,此特定示例使用的是CIT环境。如果您正在使用实时环境,请删除行
set('serviceMode','cit')
,并修改步骤1中引用的
标记

function authenticate(settings) {
  // Add your own appId and token here
  // sign in and register on http://developer.here.com
  // and obtain your own developer's API key
  nokia.Settings.set('app_id', 'YOUR_APPID');
  nokia.Settings.set('app_code', 'YOUR_TOKEN');

  // Use staging environment (remove the line for production environment)
  nokia.Settings.set('serviceMode', 'cit');
  // The language of the map can be changed here.
  nokia.Settings.set('defaultLanguage', settings.language);
}
4)现在您可以创建地图了

function createMap(domElement) {
  var map = new nokia.maps.map.Display(domElement, {
    center: [50.886944, 4.263056],
    zoomLevel: 10, // Bigger numbers are closer in
    components: [ // We use these components to make the map interactive
      new nokia.maps.map.component.ZoomBar(),
      new nokia.maps.map.component.Behavior()
    ]
  });

  return map;
}
5)最后且仅在地图准备好显示后,在第三次回调中添加必要的内容

map.addListener('displayready', function () {
  // Callback code goes here, add markers etc.
}

可以找到一个工作示例

似乎与SharePoint无关,因为在getscript使nokia.maps.map未定义后,我在ASP.NET->调用api时遇到了同样的问题。