Popup.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="divlabel-container" id="stateShow" v-show="isShow">
  3. <div class="animate-maker-border">
  4. <div class="animate-marker__text" id="popup_content" v-html="desc"></div>
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. isShow: false,
  13. desc: "",
  14. first: true,
  15. gisPosition: null
  16. };
  17. },
  18. // props: {
  19. // // entity: {
  20. // // type: Object
  21. // // },
  22. // // data: {
  23. // // type: Object
  24. // // }
  25. // },
  26. methods: {
  27. openPopup(entity, data) {
  28. // console.log(new Date().getTime());
  29. let that = this;
  30. //经纬度转为世界坐标
  31. this.gisPosition = entity;
  32. // if (entity.position) {
  33. // // gisPosition = entity.position.getValue();
  34. // gisPosition = entity;
  35. // } else {
  36. // // let point1 = d(entity.polyline.positions._value[0]);
  37. // // let point2 = d(entity.polyline.positions._value[1]);
  38. // // gisPosition = SkyScenery.Cartesian3.fromDegrees(
  39. // // (point1.lng + point2.lng) / 2,
  40. // // (point1.lat + point2.lat) / 2,
  41. // // 0
  42. // // );
  43. // function d(cartesian3) {
  44. // var cartographic =
  45. // viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian3);
  46. // var lat = SkyScenery.Math.toDegrees(cartographic.latitude);
  47. // var lng = SkyScenery.Math.toDegrees(cartographic.longitude);
  48. // return {
  49. // lng: lng,
  50. // lat: lat,
  51. // };
  52. // }
  53. // }
  54. if (that.gisPosition == null) throw new Error("popup location is error");
  55. // document.getElementById("stateShow").style.display = "block"; //弹出信息框
  56. // document.getElementById("popup_title").innerHTML = data.name;
  57. // document.getElementById("popup_content").innerHTML = data.html || "";
  58. this.isShow = true;
  59. let html = "";
  60. let properties = entity.data
  61. for (const key in properties) {
  62. if (Object.prototype.hasOwnProperty.call(properties, key)) {
  63. html += `<div>${key}: ${properties[key]}</div>`;
  64. }
  65. }
  66. this.desc = html;
  67. if (this.first) {
  68. //实时更新位置
  69. viewer.scene.postRender.addEventListener(() => {
  70. if (!that.isShow) return;
  71. // console.log(new Date().getTime());
  72. //转化为屏幕坐标
  73. var windowPosition = SkyScenery.SceneTransforms.wgs84ToWindowCoordinates(
  74. viewer.scene,
  75. that.gisPosition
  76. );
  77. if (windowPosition == undefined) {
  78. document.getElementById("stateShow").style.display = "none";
  79. return;
  80. }
  81. document.getElementById("stateShow").style.left =
  82. windowPosition.x - 150 + "px";
  83. document.getElementById("stateShow").style.top =
  84. windowPosition.y - 260 + "px";
  85. document.getElementById("stateShow").style.display = "block";
  86. //解决滚动不隐藏问题
  87. const camerPosition = viewer.camera.position;
  88. let height = viewer.scene.globe.ellipsoid.cartesianToCartographic(
  89. camerPosition
  90. ).height;
  91. height += viewer.scene.globe.ellipsoid.maximumRadius;
  92. if (
  93. !(
  94. SkyScenery.Cartesian3.distance(camerPosition, that.gisPosition) >
  95. height
  96. ) &&
  97. viewer.camera.positionCartographic.height < 50000000
  98. ) {
  99. // document.getElementById("stateShow").style.display = "block";
  100. that.isShow = true;
  101. } else {
  102. // document.getElementById("stateShow").style.display = "none";
  103. that.isShow = false;
  104. }
  105. });
  106. this.first = false;
  107. }
  108. },
  109. closePopup() {
  110. this.isShow = false;
  111. this.desc = "";
  112. this.gisPosition = null;
  113. this.$store.state.showEntity = null;
  114. // document.getElementById("popup_content").innerHTML = "";
  115. }
  116. },
  117. computed: {
  118. entity() {
  119. return this.$store.state.showEntity;
  120. }
  121. },
  122. watch: {
  123. entity(newVal, oldVal) {
  124. if (newVal == null) {
  125. this.closePopup();
  126. } else {
  127. this.openPopup(newVal);
  128. }
  129. }
  130. }
  131. };
  132. </script>
  133. <style lang="less" scoped>
  134. #stateShow {
  135. position: absolute;
  136. z-index: 1;
  137. background: #ffffff;
  138. left: -1000px;
  139. top: -1000px;
  140. .animate-maker-border,
  141. .animate-maker-border::before,
  142. .animate-maker-border::after {
  143. position: absolute;
  144. top: 0;
  145. bottom: 0;
  146. left: 0;
  147. right: 0;
  148. }
  149. .animate-maker-border {
  150. width: 300px;
  151. height: 200px;
  152. margin: 0;
  153. color: #69ca62;
  154. box-shadow: inset 0 0 0 1px rgba(105, 202, 98, 0.5);
  155. padding: 5px;
  156. box-sizing: border-box;
  157. // background: rgba(0, 173, 181, 0.32);
  158. background: #343c2fb3;
  159. }
  160. .animate-maker-border::before,
  161. .animate-maker-border::after {
  162. content: "";
  163. z-index: 10;
  164. margin: -5%;
  165. box-shadow: inset 0 0 0 2px;
  166. animation: clipMe 8s linear infinite;
  167. }
  168. .animate-maker-border::before {
  169. animation-delay: -4s;
  170. }
  171. @keyframes clipMe {
  172. 0%,
  173. 100% {
  174. clip-path: inset(0 0 98% 0);
  175. }
  176. 25% {
  177. clip-path: inset(0 98% 0 0);
  178. }
  179. 50% {
  180. clip-path: inset(98% 0 0 0);
  181. }
  182. 75% {
  183. clip-path: inset(0 0 0 98%);
  184. }
  185. }
  186. .animate-marker__text {
  187. color: #fff;
  188. font-size: 14px;
  189. // display: flex;
  190. width: 100%;
  191. height: 100%;
  192. justify-content: center;
  193. font-weight: bolder;
  194. user-select: none;
  195. cursor: pointer;
  196. overflow: hidden;
  197. overflow-y: auto;
  198. padding: 0px 20px;
  199. box-sizing: border-box;
  200. :deep(div) {
  201. line-height: 30px;
  202. }
  203. }
  204. }
  205. </style>