DiscardEmptyTileImagePolicy.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import defined from '../Core/defined.js';
  2. import defineProperties from '../Core/defineProperties.js';
  3. /**
  4. * A policy for discarding tile images that contain no data (and so aren't actually images).
  5. * This policy discards {@link DiscardEmptyTileImagePolicy.EMPTY_IMAGE}, which is
  6. * expected to be used in place of any empty tile images by the image loading code.
  7. *
  8. * @alias DiscardEmptyTileImagePolicy
  9. * @constructor
  10. *
  11. * @see DiscardMissingTileImagePolicy
  12. */
  13. function DiscardEmptyTileImagePolicy(options) {
  14. }
  15. /**
  16. * Determines if the discard policy is ready to process images.
  17. * @returns {Boolean} True if the discard policy is ready to process images; otherwise, false.
  18. */
  19. DiscardEmptyTileImagePolicy.prototype.isReady = function() {
  20. return true;
  21. };
  22. /**
  23. * Given a tile image, decide whether to discard that image.
  24. *
  25. * @param {Image} image An image to test.
  26. * @returns {Boolean} True if the image should be discarded; otherwise, false.
  27. */
  28. DiscardEmptyTileImagePolicy.prototype.shouldDiscardImage = function(image) {
  29. return DiscardEmptyTileImagePolicy.EMPTY_IMAGE === image;
  30. };
  31. var emptyImage;
  32. defineProperties(DiscardEmptyTileImagePolicy, {
  33. /**
  34. * Default value for representing an empty image.
  35. * @type {Image}
  36. * @readonly
  37. * @memberof DiscardEmptyTileImagePolicy
  38. */
  39. EMPTY_IMAGE: {
  40. get: function() {
  41. if (!defined(emptyImage)) {
  42. emptyImage = new Image();
  43. // load a blank data URI with a 1x1 transparent pixel.
  44. emptyImage.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
  45. }
  46. return emptyImage;
  47. }
  48. }
  49. });
  50. export default DiscardEmptyTileImagePolicy;