ReminderTip.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * 标绘提示弹窗tip
  3. */
  4. const CreateRemindertip = function(arr, position, show) {
  5. let tooltip = document.getElementById("toolTip");
  6. let style, _x, _y, _color;
  7. if (arr && typeof arr === "object") {
  8. style = arr;
  9. }
  10. if (style && style.origin) {
  11. style.origin === "center" && ((_x = 15), (_y = -12));
  12. style.origin === "top" && ((_x = 15), (_y = -44));
  13. style.origin === "bottom" && ((_x = 15), (_y = 20));
  14. } else {
  15. (_x = 15), (_y = 20);
  16. }
  17. if (style && style.color) {
  18. style.color === "white" && (_color = "background: rgba(255, 255, 255, 0.8);color: black;");
  19. style.color === "black" && (_color = "background: rgba(0, 0, 0, 0.65);color: white;");
  20. style.color === "yellow" && (_color = "color: black;background-color: #ffcc33;border: 1px solid white;");
  21. } else {
  22. _color = "background: rgba(0, 0, 0, 0.65);color: white;";
  23. }
  24. if (!tooltip) {
  25. const viewerDom = document.getElementsByClassName("cesium-viewer")[0];
  26. let elementbottom = document.createElement("div");
  27. viewerDom.append(elementbottom);
  28. let html =
  29. '<div id="toolTip" style="display: none;pointer-events: none;position: absolute;z-index: 1000;opacity: 0.8;border-radius: 4px;padding: 4px 8px;white-space: nowrap;font-family:黑体;color:white;font-weight: bolder;font-size: 14px;' + _color + '"></div>';
  30. viewerDom.insertAdjacentHTML("beforeend", html);
  31. tooltip = document.getElementById("toolTip");
  32. }
  33. if (show) {
  34. tooltip.innerHTML = arr;
  35. tooltip.style.left = position.x + _x + "px";
  36. tooltip.style.top = position.y + _y + "px";
  37. tooltip.style.display = "block";
  38. } else {
  39. tooltip.style.display = "none";
  40. }
  41. return {
  42. tooltip: tooltip,
  43. style: style,
  44. showAt: function(position, text) {
  45. this.tooltip.innerHTML = text;
  46. if (this.style && this.style.origin) {
  47. this.style.origin === "center" && ((_x = 15), (_y = -this.tooltip.offsetHeight / 2));
  48. this.style.origin === "top" && ((_x = 15), (_y = -this.tooltip.offsetHeight - 20));
  49. this.style.origin === "bottom" && ((_x = 15), (_y = 20));
  50. } else {
  51. (_x = 15), (_y = -this.tooltip.offsetHeight / 2);
  52. }
  53. this.tooltip.style.left = position.x + _x + "px";
  54. this.tooltip.style.top = position.y + _y + "px";
  55. this.tooltip.style.display = "block";
  56. },
  57. show: function(show) {
  58. if (show) {
  59. this.tooltip.style.display = "block";
  60. } else {
  61. this.tooltip.style.display = "none";
  62. }
  63. },
  64. };
  65. };
  66. export default CreateRemindertip;