clickable labels
This commit is contained in:
parent
890c86e654
commit
bf1b43cf4c
3 changed files with 21 additions and 7 deletions
|
@ -27,9 +27,6 @@
|
||||||
border: 1px solid #DDD;
|
border: 1px solid #DDD;
|
||||||
border-radius: .5em;
|
border-radius: .5em;
|
||||||
}
|
}
|
||||||
#info > button.highlighted {
|
|
||||||
border-color: yellow;
|
|
||||||
}
|
|
||||||
label {
|
label {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -38,10 +35,13 @@
|
||||||
margin-left: .5em;
|
margin-left: .5em;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: white;
|
color: white;
|
||||||
pointer-events: none;
|
|
||||||
transform: translate(0, 0);
|
transform: translate(0, 0);
|
||||||
background: #0008;
|
background: #0008;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
label.highlighted {
|
||||||
|
color: yellow;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
14
src/main.ts
14
src/main.ts
|
@ -78,6 +78,20 @@ function init() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for (let child of stars.children) {
|
||||||
|
;(child as Star).labelEl.addEventListener('click', (event) => {
|
||||||
|
event.stopPropagation()
|
||||||
|
|
||||||
|
for (let star of stars.children) {
|
||||||
|
;(star as Star).highlighted = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const star = child as Star
|
||||||
|
star.highlighted = true
|
||||||
|
infoEl.innerText = JSON.stringify(star.starData)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
renderer.setAnimationLoop(() => {
|
renderer.setAnimationLoop(() => {
|
||||||
raycaster.setFromCamera(pointer, camera)
|
raycaster.setFromCamera(pointer, camera)
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ export interface StarData {
|
||||||
export class Star extends Group {
|
export class Star extends Group {
|
||||||
public isStar = true
|
public isStar = true
|
||||||
public starData: StarData
|
public starData: StarData
|
||||||
|
public labelEl = document.createElement('label')
|
||||||
|
|
||||||
private coords = new Vector3()
|
private coords = new Vector3()
|
||||||
|
|
||||||
|
@ -39,8 +40,6 @@ export class Star extends Group {
|
||||||
private whiteColor = new Float32BufferAttribute([255, 255, 255], 3)
|
private whiteColor = new Float32BufferAttribute([255, 255, 255], 3)
|
||||||
private yellowColor = new Float32BufferAttribute([255, 255, 0], 3)
|
private yellowColor = new Float32BufferAttribute([255, 255, 0], 3)
|
||||||
|
|
||||||
private labelEl = document.createElement('label')
|
|
||||||
|
|
||||||
private point: Points<BufferGeometry, PointsMaterial>
|
private point: Points<BufferGeometry, PointsMaterial>
|
||||||
|
|
||||||
constructor(starData: StarData) {
|
constructor(starData: StarData) {
|
||||||
|
@ -81,6 +80,7 @@ export class Star extends Group {
|
||||||
this.pointMaterial.setValues({
|
this.pointMaterial.setValues({
|
||||||
size: isHighlight ? this.highlightedPointSize : this.normalPointSize,
|
size: isHighlight ? this.highlightedPointSize : this.normalPointSize,
|
||||||
})
|
})
|
||||||
|
this.labelEl.classList.toggle('highlighted', isHighlight)
|
||||||
}
|
}
|
||||||
|
|
||||||
public get highlighted() {
|
public get highlighted() {
|
||||||
|
@ -106,7 +106,7 @@ export class Star extends Group {
|
||||||
pos.y = Math.round((0.5 - pos.y / 2) * (height / dpr))
|
pos.y = Math.round((0.5 - pos.y / 2) * (height / dpr))
|
||||||
|
|
||||||
this.labelEl.style.transform = `translate(${pos.x}px, ${pos.y}px)`
|
this.labelEl.style.transform = `translate(${pos.x}px, ${pos.y}px)`
|
||||||
const zIndex = `${10000000 - Math.round(pos.z * 10000000)}`
|
const zIndex = `${10000000 - Math.round(pos.z * 10000000)}` // ridiculous
|
||||||
this.labelEl.style.zIndex = zIndex
|
this.labelEl.style.zIndex = zIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue