【发布时间】:2020-08-03 12:59:10
【问题描述】:
我目前正在尝试将图钉添加到 Dynamics 365 表单中的 Bing 地图。
虽然基于计算机和移动 Web 的版本运行顺利,但我遇到了适用于手机的 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 函数在 loadMap 等待时设置 window.top.mainAddress 值。一旦设置了值,地图就被创建了,```createMarker```函数也被创建了,代表当前线索的黄色图钉被添加到地图中。
这部分适用于 Dynamics 的 Web 版本(在移动设备和笔记本电脑上)和适用于手机的 Dynamics 365 应用程序。
之后,secondaryMarkers 函数以其他 5 条线索的坐标调用createMarker 函数。
我的问题是此功能对每个环境都执行alert(true),但蓝色图钉不会出现在适用于手机的 Dynamics 365 应用程序中,而它们在网络版本中可见(无论是在笔记本电脑上还是在手机上) )。
知道我在这里做错了什么吗?
这个问题是否来自我的代码来自 Dynamics 应用程序?
如果是前者,如何将图钉添加到必应地图?
【问题讨论】:
标签: javascript dynamics-crm bing-maps