簡體   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