overlapHide.js 992 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.OverlapHide = void 0;
  4. const bounds_1 = require("../utils/bounds");
  5. const style_1 = require("../utils/style");
  6. /**
  7. * Hide the label when overlap.
  8. */
  9. const OverlapHide = (options) => {
  10. const { priority } = options;
  11. return (labels, coordinate) => {
  12. const displayLabels = [];
  13. // When overlap, will hide the next label.
  14. if (priority)
  15. labels.sort(priority);
  16. labels.forEach((l) => {
  17. (0, style_1.show)(l);
  18. const b1 = l.getLocalBounds();
  19. const overlaping = displayLabels.some((dl) => (0, bounds_1.isOverlap)((0, bounds_1.parseAABB)(b1), (0, bounds_1.parseAABB)(dl.getLocalBounds())));
  20. if (overlaping)
  21. (0, style_1.hide)(l);
  22. else
  23. displayLabels.push(l);
  24. });
  25. return labels;
  26. };
  27. };
  28. exports.OverlapHide = OverlapHide;
  29. //# sourceMappingURL=overlapHide.js.map