0
私はol3とタイルのバックアップルートを追加しようとしています。 "http"で始まるソースURLの場合、errorloadイベントをテストしたいと思います。 「はい」の場合:このタイルをカスタムタイルに置き換えます。 「いいえ」の場合 :私はバックアップのタイルがあることがわかります、それとOL3バックアップURLを追加
layerTile.getSource().setUrl('file:///local/{z}/{x}/{y}.jpg');
var errorTilePath='https://image.noelshack.com/fichiers/2017/14/1491403614-errortile.png';
var serverBackup='http://otile1.mqcdn.com/tiles/1.0.0/map/';
layerTile.getSource().setTileLoadFunction((function() {
var tileLoadFn = layerTile.getSource().getTileLoadFunction();
return function(tile, src) {
var image = tile.getImage();
image.onload = function() {console.log('Tile ok : ' + src); };
image.onerror = function() {
console.log('Tile error : ' + src);
console.log(tile);
if (src.substr(0,4)!='http') {
var tmp=src.split('/').reverse();
var serverBackupPath=serverBackup+tmp[2]+'/'+tmp[1]+'/'+tmp[0].split('.')[0]+'.png';
console.log("Second url : " + serverBackupPath)
src=serverBackupPath;
tile.getImage().src=src;
var image = tile.getImage();
image.onload = function() {console.log('Tile backup ok : ' + src);};
image.onerror = function() {console.log('Tile backup error : ' + src); src=errorTilePath; tile.getImage().src=src; tileLoadFn(tile, src);}
} else {
console.log('Custom tile : ');
src=errorTilePath;
tile.getImage().src=src;
}
tileLoadFn(tile, src);
};
tileLoadFn(tile, src);
};
})());
:
を別のもので、このタイルのソースURLを変更して再試行してください私はそのようなものを使用する必要があると思いますマップ上には表示されません。
確かに、私は何かを誤解しました。
誰かが私を助けることができる場合は、事前に感謝します。
私は予想通りの結果を出しましたが、パフォーマンスについてはわかりません。 – Slayes