gpt4 book ai didi

javascript - Openlayers 2 + HERE 切片缓存

转载 作者:行者123 更新时间:2023-12-03 00:13:18 28 4
gpt4 key购买 nike

我需要在 Windows 计算机上创建离线 map 演示,唯一的选择是使用图 block 缓存,我使用的是 Openlayers 2,当我初始化 OSM 层时,一切都会按预期工作:

map = new OpenLayers.Map({
layers: [
new OpenLayers.Layer.OSM("OpenStreetMap (CORS)", null, {
eventListeners: {
tileloaded: updateStatus,
loadend: detect
}})
]
}

调用“检测”方法并检查是否可以为图 block 调用函数 getCanvasContext() 并且一切正常!当我使用 XYZ 图层将 OSM 替换为 HERE map 时,它停止工作:

var urlTpl = 'https://1.{base}.maps.cit.api.here.com' + '/{type}/2.1/maptile/newest/{scheme}/${z}/${x}/${y}/256/png' + '?app_id=?????&app_code=??????';

var hereLayer = {
base: 'base',
type: 'maptile',
scheme: 'normal.day',
app_id: platform['app_id'],
app_code: platform['app_code']
};

map = new OpenLayers.Map({
layers: [
new OpenLayers.Layer.XYZ("HERE", [createUrl(urlTpl, hereLayer)], {
eventListeners: {
tileloaded: updateStatus,
loadend: detect
}
})
]
}

在此示例中,确实调用了检测方法,但这次函数 getCanvasContext() 抛出异常:

code: 18
message: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
name: SecurityError

我能做什么?

最佳答案

摘自https://gis.stackexchange.com/questions/71715/enabling-cors-in-openlayers中的答案:您需要在 layers 选项中包含 tileOptions 设置才能启用 CORS:

map = new OpenLayers.Map({
layers: [
new OpenLayers.Layer.XYZ("HERE", [createUrl(urlTpl, hereLayer)], {
tileOptions: {crossOriginKeyword: 'anonymous'},
eventListeners: {
tileloaded: updateStatus,
loadend: detect
}
})
]
}

关于javascript - Openlayers 2 + HERE 切片缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54626831/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com