Friday, July 18, 2014

Replace Missing Tiles in OpenLayers 2.13

Say you want to have a custom replacement tile instead of annoying pink tile. Here's a quick and dirty way to do that:

var layer = new OpenLayers.Layer.XYZ("Layer", "tiles/${z}/${x}/${y}.png", {
     tileOptions : {
          onImageError : function() {
               this.setImgSrc('img/noTile.png');
          },
     }
});
Basically what we do here is tell OpenLayers that for each tile (tileOptions) that fails to load (onImageError) to set new url (setImgSrc(url)) which points to our noTile.png tile in the img directory.

No comments:

Post a Comment