Microsoft.Maps.Pushpin 未出现在 phone 的 Dynamics 365 应用中

Microsoft.Maps.Pushpin not appearing in Dynamics 365 app for phone

我目前正在尝试将图钉添加到 Dynamics 365 表单中的 Bing 地图。

虽然基于计算机和移动网络的版本运行顺利,但我在 phone.

的 Dynamics 365 应用程序中遇到了问题

我检查了 HTML 网络资源和我正在使用的表单上的移动选项,所以我的问题不是来自于此。

这是我的 HTML 文件:

<body onload="loadMap();">
  <div id="myMap"></div>
  <script type="text/javascript">
    function loadMap() {
      if (window.top.mainAddress== null) {
        setTimeout(loadMap, 300);
        return;
      }
      
      Microsoft.Maps.loadModule('Microsoft.Maps.Search', () => {
        let map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
          mapTypeId: Microsoft.Maps.MapTypeId.aerial,
          zoom: 3
        });

        window.top.createMarker = (lat, lon, url) => {
          try {
            let marker = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon), {
              color: "blue"
            });
            Microsoft.Maps.Events.addHandler(marker, 'click', () => {
              window.open(url);
            });
            map.entities.push(marker);
            return true;
          }
          catch (exception) {
            return exception;
          }
        }

        let searchManager = new Microsoft.Maps.Search.SearchManager(map);
        let requestOptions = {
          bounds: map.getBounds(),
          where: window.top.mainAddress,
          callback: answer => {
            map.setView({ bounds: answer.results[0].bestView });
            map.entities.push(new Microsoft.Maps.Pushpin(answer.results[0].location, { color: "yellow" }));
          }
        };
        searchManager.geocode(requestOptions);
      });
    }
  </script>
  <script type="text/javascript" src="https://www.bing.com/api/maps/mapcontrol?key=XXX" async="" defer=""></script>
</body>

还有我的 JS 文件,在加载表单时调用了两个函数:

function getMainAddress(executionContext) {
  let formContext = executionContext.getFormContext();
  window.top.mainAddress = [
    formContext.getAttribute("address1_line1").getValue(),
    formContext.getAttribute("address1_postalCode").getValue(),
    formContext.getAttribute("address1_city").getValue(),
  ].filter(Boolean).join(' ');
}

function secondaryMarkers(executionContext) {
  if (window.top.createMarker == null) {
    setTimeout(() => secondaryMarkers(executionContext), 500);
    return;
  }

  Xrm.WebApi.retrieveMultipleRecords("lead", "?$select=address1_latitude,address1_longitude&$top=5").then((result) => {
    result.entities.forEach((lead) => {
      alert(window.top.createMarker(lead.address1_latitude, lead.address1_longitude, `https://XXX.crm.dynamics.com/main.aspx?pagetype=entityrecord&etn=lead&id=${lead.leadid}`));
    });
  }).catch((exception) => {
    alert(exception);
  });
}

这就是它应该如何工作的(显然不是最佳方式,但现在我只想让它先正常工作):getMainAddress 函数设置 window.top.mainAddress 值,同时loadMap 正在等待。设置值后,将创建地图,````createMarker``` 函数也是如此,代表当前潜在客户的黄色图钉将添加到地图中。

这部分实际上适用于网络版动态(在移动设备和笔记本电脑上)和 phone 的 Dynamics 365 应用程序。

之后,secondaryMarkers 函数调用 createMarker 函数,其中包含 5 个其他导联的坐标。

我的问题是此功能对每个环境都有效 alert(true),但是蓝色图钉不会出现在 phone 的 Dynamics 365 应用程序中,而它们在网络版本中可见(Be它在笔记本电脑或 phone).

知道我做错了什么吗?

这个问题是否来自我的代码来自 Dynamics 应用程序?

如果是前者,如何将图钉添加到 bing 地图?

因此,在 运行 不同测试之后,似乎只有 map.entities 集合中推送的第一个元素在 phone 的 Dynamics 365 应用程序中呈现。

我最终使用了一个 Microsoft.Maps.EntityCollection,我在其中推了图钉,它起作用了。