【发布时间】:2019-12-12 11:16:23
【问题描述】:
我需要在我的 Web 应用程序中使用具有图像下载功能的 Bing 地图。 我需要在 bing 地图上绘图,用户可以下载相同的地图。 如果我在地图上绘制一些东西,它工作正常,但在尝试缩放区域时无法获得预期的结果。 在 bing 地图上缩放和绘制后,下载的图像不显示街道。它只显示绘制的部分。
这是我的期望和输出:
预期:
输出:
这是我引用的完整示例链接,
下面是我正在尝试生成图像的示例代码:
var map, imageGenerator;
function getMapForReport() {
map = new Microsoft.Maps.Map(document.getElementById('myReportMap'), {
credentials: '@System.Configuration.ConfigurationManager.AppSettings["BingMapCredentials"].ToString()',
center: new Microsoft.Maps.Location(38.881397, -94.819130),
zoom: 4,
mapTypeId: Microsoft.Maps.MapTypeId.road,
showMapTypeSelector: false,
showLocateMeButton: false,
showZoomButtons: false,
showCopyright: false,
showScalebar: false,
disableScrollWheelZoom: true,
disableZooming: true,
enableCORS: true
});
document.getElementById('zoomIn').onclick = function () {
var z = map.getZoom() + 1;
map.setView({ zoom: z });
zoomLevel = z;
}
document.getElementById('zoomOut').onclick = function () {
var z = map.getZoom() - 1;
map.setView({ zoom: z });
zoomLevel = z;
}
Microsoft.Maps.registerModule('MapImageGeneratorModule', '/Scripts/MapImageGeneratorModule.js');
}
function generateImage(){
Microsoft.Maps.loadModule('MapImageGeneratorModule', function () {
imageGenerator = new MapImageGenerator(map);
});
imageGenerator.getImage(function (mapImg) {
setTimeout(function () {
var img = mapImg.src;
$.post('@Url.Action("HailSwathPayment", "Payment")', { stripeToken: "", stripeEmail: "", reportId: reportId, amount: amount, mapImg: img }, function (data) {
var url = '@Url.Action("Index", "PurchaseList")';
window.location.href = url;
});
}, 0);
}, function (e) {
alert(e);
});
}
我在按钮点击事件上调用 generateImage 函数,并将下载的图像(base64)保存到数据库。
var img = mapImg.src; 未获取预期输出,我通过将 base64 转换为图像进行了检查。 我已经尝试了所有方法并对问题进行了研究,但没有运气!
任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: javascript jquery maps bing-maps bing-api