DiscardEmptyTileImagePolicy.js 1.7 KB

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