overlapHide.js 802 B

12345678910111213141516171819202122232425
  1. import { isOverlap, parseAABB } from '../utils/bounds';
  2. import { hide, show } from '../utils/style';
  3. /**
  4. * Hide the label when overlap.
  5. */
  6. export const OverlapHide = (options) => {
  7. const { priority } = options;
  8. return (labels, coordinate) => {
  9. const displayLabels = [];
  10. // When overlap, will hide the next label.
  11. if (priority)
  12. labels.sort(priority);
  13. labels.forEach((l) => {
  14. show(l);
  15. const b1 = l.getLocalBounds();
  16. const overlaping = displayLabels.some((dl) => isOverlap(parseAABB(b1), parseAABB(dl.getLocalBounds())));
  17. if (overlaping)
  18. hide(l);
  19. else
  20. displayLabels.push(l);
  21. });
  22. return labels;
  23. };
  24. };
  25. //# sourceMappingURL=overlapHide.js.map