更新时间:2023-01-01 18:36:35
当加载Google时,您可以侦听'loaderror'事件地图图块失败。以下是常规WMS图层的示例(完整示例,位于 http://jsfiddle.net/D3Eha/2/)
You can listen for 'loaderror' event, that will be thrown, when loading of Google Map tile fails. Here is example with regular WMS layer (full example in http://jsfiddle.net/D3Eha/2/)
var wmsLayer, workingOffline = false;
wmsLayer = new OpenLayers.Layer.WMS("OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0?",
{layers: 'basic'},
{
attribution: 'Provided by OSGeo',
tileOptions: {
eventListeners: {
'loaderror': function(evt) {
if (workingOffline == false) {
console.log('Tile load error, switching to offline map');
workingOffline = true;
}
}
}
}
}
);
当计算机再次联机时,检测是非常棘手的。例如,当你离线时,启动定期计时器从Internet加载一些图像。如果成功,您将重新上线。
It's trickier to detect, when computer is online again. For example, when you go offline, start periodical timer to load some image from Internet. If it succeeds, you are back online.