This commit is contained in:
zh
2025-09-05 18:42:50 +08:00
parent 29629b9d43
commit ae48dbd700
14 changed files with 1753 additions and 4875 deletions

View File

@ -13,12 +13,11 @@ import {
} from '../../../Global/cluster/cluster'
class LabelObject extends Base {
#updateBillboardImageTimeout
#canvas = document.createElement('canvas')
#canvas2 = document.createElement('canvas')
constructor(sdk, options = {}, model) {
super(sdk, options)
this.model = model
this._canvas = document.createElement('canvas')
this._canvas2 = document.createElement('canvas')
this.options.near = options.near || options.near === 0 ? options.near : 2000
this.options.far = options.far || options.far === 0 ? options.far : 100000
this.options.scaleByDistance = options.scaleByDistance || false
@ -69,7 +68,7 @@ class LabelObject extends Base {
let id = this.options.id + '-label'
let oldEntity = this.sdk.viewer.entities.getById(id)
if(oldEntity) {
if (oldEntity) {
this.sdk.viewer.entities.remove(oldEntity)
}
this.entity = this.sdk.viewer.entities.add({
@ -492,8 +491,8 @@ class LabelObject extends Base {
// }
getcanvas() {
const ctx = this.#canvas.getContext('2d')
ctx.clearRect(0, 0, this.#canvas.width, this.#canvas.height);
const ctx = this._canvas.getContext('2d')
ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
ctx.font = this.options.fontSize + 'px ' + this.font
let texts = this.options.text.split('\n')
let canvasWidth = 0
@ -511,8 +510,8 @@ class LabelObject extends Base {
if (canvasWidth < this.options.lineWidth) {
canvasWidth = this.options.lineWidth
}
this.#canvas.width = canvasWidth
this.#canvas.height = this.options.pixelOffset + canvasHeight
this._canvas.width = canvasWidth
this._canvas.height = this.options.pixelOffset + canvasHeight
const linearGradient = ctx.createLinearGradient(
0,
0,
@ -559,14 +558,14 @@ class LabelObject extends Base {
ctx.stroke()
ctx.closePath()
const ctx2 = this.#canvas2.getContext('2d')
this.#canvas2.width = this.#canvas.width + 10
this.#canvas2.height = this.#canvas.height + 10
ctx2.drawImage(this.#canvas, 5, 5);
const ctx2 = this._canvas2.getContext('2d')
this._canvas2.width = this._canvas.width + 10
this._canvas2.height = this._canvas.height + 10
ctx2.drawImage(this._canvas, 5, 5);
// const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
// ctx.putImageData(imageData, 40, 40);
return this.#canvas2.toDataURL("image/png")
return this._canvas2.toDataURL("image/png")
}
remove() {