Skip to content

Commit 5ca9191

Browse files
committed
feat: ✨ Add and close information box operation
1 parent fb3cd4c commit 5ca9191

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cesium_dev_kit",
3-
"version": "1.0.100",
3+
"version": "1.1.1",
44
"license": "MIT",
55
"scripts": {
66
"dev": "vite",
@@ -39,11 +39,11 @@
3939
"@vue/compiler-sfc": "^3.4.32",
4040
"mitt": "^2.1.0",
4141
"prettier": "^2.2.1",
42+
"sass": "1.77.6",
4243
"typescript": "^5.4.5",
4344
"unplugin-auto-import": "^0.17.6",
4445
"unplugin-vue-components": "^0.27.2",
4546
"vite": "^2.6.10",
46-
"sass": "1.77.6",
4747
"vite-plugin-cesium": "^1.2.9",
4848
"vite-plugin-compression": "^0.2.5",
4949
"vite-plugin-html": "^2.0.7",

src/utils/cesiumPluginsExtends/libs/Plugin.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,19 +771,34 @@ Plugin.prototype = {
771771
this._container = null
772772
this._elements = elements
773773
this._isBackHide = isBackHide
774+
this._parentEleId =elements[0].parentEleId
774775

775776
this.init()
776777
}
777778
Css3Renderer.prototype.init = function () {
778779
var container = document.createElement('div')
779780
container.className = `ys-css3-container`
781+
const _parentEleId = this._parentEleId
780782
// document.body.appendChild(container)
781-
document.getElementById('info-warp').appendChild(container)
783+
document.getElementById(_parentEleId).appendChild(container)
782784
this._container = container
783785

784786
this._elements.forEach(function (e) {
785787
container.insertAdjacentHTML('beforeend', e.element)
786788
})
789+
function getElementsByClass(className, parentElement = document) {
790+
return parentElement.querySelectorAll(`.${className}`);
791+
}
792+
var boxElements = getElementsByClass('close__box__btn');
793+
// 遍历所有元素并绑定点击事件
794+
boxElements.forEach(function(element) {
795+
element.addEventListener('click', function() {
796+
document.getElementById(_parentEleId).removeChild(container)
797+
});
798+
});
799+
800+
801+
787802
var $this = this
788803
this._scene.preRender.addEventListener(function () {
789804
//
@@ -831,7 +846,9 @@ Plugin.prototype = {
831846
})
832847
this._container.removeChild(document.getElementById(id))
833848
}
834-
849+
Css3Renderer.prototype.removeChild = function () {
850+
document.getElementById(this._parentEleId).removeChild(this._container)
851+
}
835852
Css3Renderer.prototype.append = function (object) {
836853
this._elements.push(object)
837854
this._container.insertAdjacentHTML('beforeend', object.element)

src/views/example/infoBox/constructBox.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ export default {
6464
addEntityToScene (viewer) {
6565
let css3Renderer = new Cesium.Scene.Css3Renderer([{
6666
id: 'box4',
67+
parentEleId: 'info-warp',
6768
position: [104.08985268964015, 30.635443158056148, 50.0],
68-
element: `<div class="ys-css3-box ex-box" id="box4">xxx 信息点</div>`,
69+
element: `<div class="ys-css3-box ex-box" id="box4"><div class="close__box__btn">X</div>xxx 信息点</div>`,
6970
offset: [10, 10]
7071
}], true);
7172
}

src/views/example/infoBox/css/utils.css

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
.ysc-dynamic-layer{
2-
/*重要*/
3-
user-select: none; /*禁止选中*/
4-
pointer-events: none; /*鼠标穿透*/
2+
53
/*重要*/
64
position: fixed;
75
top:0;
@@ -10,6 +8,13 @@
108
height:250px;
119
z-index: 99999;
1210
}
11+
.close__box__btn {
12+
position: absolute;
13+
top: 5px;
14+
right: 5px;
15+
cursor: pointer;
16+
color: #fff;
17+
}
1318
.ysc-dynamic-layer .line{
1419
position: absolute;
1520
left:0;
@@ -53,9 +58,7 @@
5358
padding: 8px 20px;
5459
}
5560

56-
.ys-css3-box {
57-
pointer-events: none;
58-
}
61+
5962
#box4{
6063
font-size: 20px;
6164
color: orange;

0 commit comments

Comments
 (0)