繁体   English   中英

Openlayers 2 + HERE切片缓存

[英]Openlayers 2 + HERE tiles caching

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

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

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

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
            }
        })
    ]
}

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

码:18
消息:无法在“ HTMLCanvasElement”上执行“ toDataURL”:可能无法导出污染的画布。
名称: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
        }
    })
    ]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM