123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991 |
- import BoundingRectangle from "../Core/BoundingRectangle.js";
- import Cartesian2 from "../Core/Cartesian2.js";
- import Color from "../Core/Color.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- import destroyObject from "../Core/destroyObject.js";
- import DeveloperError from "../Core/DeveloperError.js";
- import Matrix4 from "../Core/Matrix4.js";
- import writeTextToCanvas from "../Core/writeTextToCanvas.js";
- import bitmapSDF from "../ThirdParty/bitmap-sdf.js";
- import BillboardCollection from "./BillboardCollection.js";
- import BlendOption from "./BlendOption.js";
- import HeightReference from "./HeightReference.js";
- import HorizontalOrigin from "./HorizontalOrigin.js";
- import Label from "./Label.js";
- import LabelStyle from "./LabelStyle.js";
- import SDFSettings from "./SDFSettings.js";
- import TextureAtlas from "./TextureAtlas.js";
- import VerticalOrigin from "./VerticalOrigin.js";
- import GraphemeSplitter from "../ThirdParty/graphemesplitter.js";
- function Glyph() {
- this.textureInfo = undefined;
- this.dimensions = undefined;
- this.billboard = undefined;
- }
- function GlyphTextureInfo(labelCollection, index, dimensions) {
- this.labelCollection = labelCollection;
- this.index = index;
- this.dimensions = dimensions;
- }
- var defaultLineSpacingPercent = 1.2;
- var whitePixelCanvasId = "ID_WHITE_PIXEL";
- var whitePixelSize = new Cartesian2(4, 4);
- var whitePixelBoundingRegion = new BoundingRectangle(1, 1, 1, 1);
- function addWhitePixelCanvas(textureAtlas, labelCollection) {
- var canvas = document.createElement("canvas");
- canvas.width = whitePixelSize.x;
- canvas.height = whitePixelSize.y;
- var context2D = canvas.getContext("2d");
- context2D.fillStyle = "#fff";
- context2D.fillRect(0, 0, canvas.width, canvas.height);
- textureAtlas.addImage(whitePixelCanvasId, canvas).then(function (index) {
- labelCollection._whitePixelIndex = index;
- });
- }
- var writeTextToCanvasParameters = {};
- function createGlyphCanvas(
- character,
- font,
- fillColor,
- outlineColor,
- outlineWidth,
- style,
- verticalOrigin
- ) {
- writeTextToCanvasParameters.font = font;
- writeTextToCanvasParameters.fillColor = fillColor;
- writeTextToCanvasParameters.strokeColor = outlineColor;
- writeTextToCanvasParameters.strokeWidth = outlineWidth;
-
- writeTextToCanvasParameters.padding = SDFSettings.PADDING;
- if (verticalOrigin === VerticalOrigin.CENTER) {
- writeTextToCanvasParameters.textBaseline = "middle";
- } else if (verticalOrigin === VerticalOrigin.TOP) {
- writeTextToCanvasParameters.textBaseline = "top";
- } else {
-
- writeTextToCanvasParameters.textBaseline = "bottom";
- }
- writeTextToCanvasParameters.fill =
- style === LabelStyle.FILL || style === LabelStyle.FILL_AND_OUTLINE;
- writeTextToCanvasParameters.stroke =
- style === LabelStyle.OUTLINE || style === LabelStyle.FILL_AND_OUTLINE;
- writeTextToCanvasParameters.backgroundColor = Color.BLACK;
- return writeTextToCanvas(character, writeTextToCanvasParameters);
- }
- function unbindGlyph(labelCollection, glyph) {
- glyph.textureInfo = undefined;
- glyph.dimensions = undefined;
- var billboard = glyph.billboard;
- if (defined(billboard)) {
- billboard.show = false;
- billboard.image = undefined;
- if (defined(billboard._removeCallbackFunc)) {
- billboard._removeCallbackFunc();
- billboard._removeCallbackFunc = undefined;
- }
- labelCollection._spareBillboards.push(billboard);
- glyph.billboard = undefined;
- }
- }
- function addGlyphToTextureAtlas(textureAtlas, id, canvas, glyphTextureInfo) {
- textureAtlas.addImage(id, canvas).then(function (index) {
- glyphTextureInfo.index = index;
- });
- }
- var splitter = new GraphemeSplitter();
- function rebindAllGlyphs(labelCollection, label) {
- var text = label._renderedText;
- var graphemes = splitter.splitGraphemes(text);
- var textLength = graphemes.length;
- var glyphs = label._glyphs;
- var glyphsLength = glyphs.length;
- var glyph;
- var glyphIndex;
- var textIndex;
-
- label._relativeSize = label._fontSize / SDFSettings.FONT_SIZE;
-
- if (textLength < glyphsLength) {
- for (glyphIndex = textLength; glyphIndex < glyphsLength; ++glyphIndex) {
- unbindGlyph(labelCollection, glyphs[glyphIndex]);
- }
- }
-
- glyphs.length = textLength;
- var showBackground =
- label._showBackground && text.split("\n").join("").length > 0;
- var backgroundBillboard = label._backgroundBillboard;
- var backgroundBillboardCollection =
- labelCollection._backgroundBillboardCollection;
- if (!showBackground) {
- if (defined(backgroundBillboard)) {
- backgroundBillboardCollection.remove(backgroundBillboard);
- label._backgroundBillboard = backgroundBillboard = undefined;
- }
- } else {
- if (!defined(backgroundBillboard)) {
- backgroundBillboard = backgroundBillboardCollection.add({
- collection: labelCollection,
- image: whitePixelCanvasId,
- imageSubRegion: whitePixelBoundingRegion,
- });
- label._backgroundBillboard = backgroundBillboard;
- }
- backgroundBillboard.color = label._backgroundColor;
- backgroundBillboard.show = label._show;
- backgroundBillboard.position = label._position;
- backgroundBillboard.eyeOffset = label._eyeOffset;
- backgroundBillboard.pixelOffset = label._pixelOffset;
- backgroundBillboard.horizontalOrigin = HorizontalOrigin.LEFT;
- backgroundBillboard.verticalOrigin = label._verticalOrigin;
- backgroundBillboard.heightReference = label._heightReference;
- backgroundBillboard.scale = label.totalScale;
- backgroundBillboard.pickPrimitive = label;
- backgroundBillboard.id = label._id;
- backgroundBillboard.translucencyByDistance = label._translucencyByDistance;
- backgroundBillboard.pixelOffsetScaleByDistance =
- label._pixelOffsetScaleByDistance;
- backgroundBillboard.scaleByDistance = label._scaleByDistance;
- backgroundBillboard.distanceDisplayCondition =
- label._distanceDisplayCondition;
- backgroundBillboard.disableDepthTestDistance =
- label._disableDepthTestDistance;
- }
- var glyphTextureCache = labelCollection._glyphTextureCache;
-
-
- for (textIndex = 0; textIndex < textLength; ++textIndex) {
- var character = graphemes[textIndex];
- var verticalOrigin = label._verticalOrigin;
- var id = JSON.stringify([
- character,
- label._fontFamily,
- label._fontStyle,
- label._fontWeight,
- +verticalOrigin,
- ]);
- var glyphTextureInfo = glyphTextureCache[id];
- if (!defined(glyphTextureInfo)) {
- var glyphFont =
- label._fontStyle +
- " " +
- label._fontWeight +
- " " +
- SDFSettings.FONT_SIZE +
- "px " +
- label._fontFamily;
- var canvas = createGlyphCanvas(
- character,
- glyphFont,
- Color.WHITE,
- Color.WHITE,
- 0.0,
- LabelStyle.FILL,
- verticalOrigin
- );
- glyphTextureInfo = new GlyphTextureInfo(
- labelCollection,
- -1,
- canvas.dimensions
- );
- glyphTextureCache[id] = glyphTextureInfo;
- if (canvas.width > 0 && canvas.height > 0) {
- var sdfValues = bitmapSDF(canvas, {
- cutoff: SDFSettings.CUTOFF,
- radius: SDFSettings.RADIUS,
- });
- var ctx = canvas.getContext("2d");
- var canvasWidth = canvas.width;
- var canvasHeight = canvas.height;
- var imgData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
- for (var i = 0; i < canvasWidth; i++) {
- for (var j = 0; j < canvasHeight; j++) {
- var baseIndex = j * canvasWidth + i;
- var alpha = sdfValues[baseIndex] * 255;
- var imageIndex = baseIndex * 4;
- imgData.data[imageIndex + 0] = alpha;
- imgData.data[imageIndex + 1] = alpha;
- imgData.data[imageIndex + 2] = alpha;
- imgData.data[imageIndex + 3] = alpha;
- }
- }
- ctx.putImageData(imgData, 0, 0);
- if (character !== " ") {
- addGlyphToTextureAtlas(
- labelCollection._textureAtlas,
- id,
- canvas,
- glyphTextureInfo
- );
- }
- }
- }
- glyph = glyphs[textIndex];
- if (defined(glyph)) {
-
- if (glyphTextureInfo.index === -1) {
-
-
- unbindGlyph(labelCollection, glyph);
- } else if (defined(glyph.textureInfo)) {
-
-
- glyph.textureInfo = undefined;
- }
- } else {
-
- glyph = new Glyph();
- glyphs[textIndex] = glyph;
- }
- glyph.textureInfo = glyphTextureInfo;
- glyph.dimensions = glyphTextureInfo.dimensions;
-
- if (glyphTextureInfo.index !== -1) {
- var billboard = glyph.billboard;
- var spareBillboards = labelCollection._spareBillboards;
- if (!defined(billboard)) {
- if (spareBillboards.length > 0) {
- billboard = spareBillboards.pop();
- } else {
- billboard = labelCollection._billboardCollection.add({
- collection: labelCollection,
- });
- billboard._labelDimensions = new Cartesian2();
- billboard._labelTranslate = new Cartesian2();
- }
- glyph.billboard = billboard;
- }
- billboard.show = label._show;
- billboard.position = label._position;
- billboard.eyeOffset = label._eyeOffset;
- billboard.pixelOffset = label._pixelOffset;
- billboard.horizontalOrigin = HorizontalOrigin.LEFT;
- billboard.verticalOrigin = label._verticalOrigin;
- billboard.heightReference = label._heightReference;
- billboard.scale = label.totalScale;
- billboard.pickPrimitive = label;
- billboard.id = label._id;
- billboard.image = id;
- billboard.translucencyByDistance = label._translucencyByDistance;
- billboard.pixelOffsetScaleByDistance = label._pixelOffsetScaleByDistance;
- billboard.scaleByDistance = label._scaleByDistance;
- billboard.distanceDisplayCondition = label._distanceDisplayCondition;
- billboard.disableDepthTestDistance = label._disableDepthTestDistance;
- billboard._batchIndex = label._batchIndex;
- billboard.outlineColor = label.outlineColor;
- if (label.style === LabelStyle.FILL_AND_OUTLINE) {
- billboard.color = label._fillColor;
- billboard.outlineWidth = label.outlineWidth;
- } else if (label.style === LabelStyle.FILL) {
- billboard.color = label._fillColor;
- billboard.outlineWidth = 0.0;
- } else if (label.style === LabelStyle.OUTLINE) {
- billboard.color = Color.TRANSPARENT;
- billboard.outlineWidth = label.outlineWidth;
- }
- }
- }
-
-
- label._repositionAllGlyphs = true;
- }
- function calculateWidthOffset(lineWidth, horizontalOrigin, backgroundPadding) {
- if (horizontalOrigin === HorizontalOrigin.CENTER) {
- return -lineWidth / 2;
- } else if (horizontalOrigin === HorizontalOrigin.RIGHT) {
- return -(lineWidth + backgroundPadding.x);
- }
- return backgroundPadding.x;
- }
- var glyphPixelOffset = new Cartesian2();
- var scratchBackgroundPadding = new Cartesian2();
- function repositionAllGlyphs(label) {
- var glyphs = label._glyphs;
- var text = label._renderedText;
- var glyph;
- var dimensions;
- var lastLineWidth = 0;
- var maxLineWidth = 0;
- var lineWidths = [];
- var maxGlyphDescent = Number.NEGATIVE_INFINITY;
- var maxGlyphY = 0;
- var numberOfLines = 1;
- var glyphIndex;
- var glyphLength = glyphs.length;
- var backgroundBillboard = label._backgroundBillboard;
- var backgroundPadding = Cartesian2.clone(
- defined(backgroundBillboard) ? label._backgroundPadding : Cartesian2.ZERO,
- scratchBackgroundPadding
- );
-
- backgroundPadding.x /= label._relativeSize;
- backgroundPadding.y /= label._relativeSize;
- for (glyphIndex = 0; glyphIndex < glyphLength; ++glyphIndex) {
- if (text.charAt(glyphIndex) === "\n") {
- lineWidths.push(lastLineWidth);
- ++numberOfLines;
- lastLineWidth = 0;
- } else {
- glyph = glyphs[glyphIndex];
- dimensions = glyph.dimensions;
- maxGlyphY = Math.max(maxGlyphY, dimensions.height - dimensions.descent);
- maxGlyphDescent = Math.max(maxGlyphDescent, dimensions.descent);
-
- lastLineWidth += dimensions.width - dimensions.bounds.minx;
- if (glyphIndex < glyphLength - 1) {
- lastLineWidth += glyphs[glyphIndex + 1].dimensions.bounds.minx;
- }
- maxLineWidth = Math.max(maxLineWidth, lastLineWidth);
- }
- }
- lineWidths.push(lastLineWidth);
- var maxLineHeight = maxGlyphY + maxGlyphDescent;
- var scale = label.totalScale;
- var horizontalOrigin = label._horizontalOrigin;
- var verticalOrigin = label._verticalOrigin;
- var lineIndex = 0;
- var lineWidth = lineWidths[lineIndex];
- var widthOffset = calculateWidthOffset(
- lineWidth,
- horizontalOrigin,
- backgroundPadding
- );
- var lineSpacing = defaultLineSpacingPercent * maxLineHeight;
- var otherLinesHeight = lineSpacing * (numberOfLines - 1);
- var totalLineWidth = maxLineWidth;
- var totalLineHeight = maxLineHeight + otherLinesHeight;
- if (defined(backgroundBillboard)) {
- totalLineWidth += backgroundPadding.x * 2;
- totalLineHeight += backgroundPadding.y * 2;
- backgroundBillboard._labelHorizontalOrigin = horizontalOrigin;
- }
- glyphPixelOffset.x = widthOffset * scale;
- glyphPixelOffset.y = 0;
- var firstCharOfLine = true;
- var lineOffsetY = 0;
- for (glyphIndex = 0; glyphIndex < glyphLength; ++glyphIndex) {
- if (text.charAt(glyphIndex) === "\n") {
- ++lineIndex;
- lineOffsetY += lineSpacing;
- lineWidth = lineWidths[lineIndex];
- widthOffset = calculateWidthOffset(
- lineWidth,
- horizontalOrigin,
- backgroundPadding
- );
- glyphPixelOffset.x = widthOffset * scale;
- firstCharOfLine = true;
- } else {
- glyph = glyphs[glyphIndex];
- dimensions = glyph.dimensions;
- if (verticalOrigin === VerticalOrigin.TOP) {
- glyphPixelOffset.y =
- dimensions.height - maxGlyphY - backgroundPadding.y;
- glyphPixelOffset.y += SDFSettings.PADDING;
- } else if (verticalOrigin === VerticalOrigin.CENTER) {
- glyphPixelOffset.y =
- (otherLinesHeight + dimensions.height - maxGlyphY) / 2;
- } else if (verticalOrigin === VerticalOrigin.BASELINE) {
- glyphPixelOffset.y = otherLinesHeight;
- glyphPixelOffset.y -= SDFSettings.PADDING;
- } else {
-
- glyphPixelOffset.y =
- otherLinesHeight + maxGlyphDescent + backgroundPadding.y;
- glyphPixelOffset.y -= SDFSettings.PADDING;
- }
- glyphPixelOffset.y =
- (glyphPixelOffset.y - dimensions.descent - lineOffsetY) * scale;
-
- if (firstCharOfLine) {
- glyphPixelOffset.x -= SDFSettings.PADDING * scale;
- firstCharOfLine = false;
- }
- if (defined(glyph.billboard)) {
- glyph.billboard._setTranslate(glyphPixelOffset);
- glyph.billboard._labelDimensions.x = totalLineWidth;
- glyph.billboard._labelDimensions.y = totalLineHeight;
- glyph.billboard._labelHorizontalOrigin = horizontalOrigin;
- }
-
-
-
- if (glyphIndex < glyphLength - 1) {
- var nextGlyph = glyphs[glyphIndex + 1];
- glyphPixelOffset.x +=
- (dimensions.width -
- dimensions.bounds.minx +
- nextGlyph.dimensions.bounds.minx) *
- scale;
- }
- }
- }
- if (defined(backgroundBillboard) && text.split("\n").join("").length > 0) {
- if (horizontalOrigin === HorizontalOrigin.CENTER) {
- widthOffset = -maxLineWidth / 2 - backgroundPadding.x;
- } else if (horizontalOrigin === HorizontalOrigin.RIGHT) {
- widthOffset = -(maxLineWidth + backgroundPadding.x * 2);
- } else {
- widthOffset = 0;
- }
- glyphPixelOffset.x = widthOffset * scale;
- if (verticalOrigin === VerticalOrigin.TOP) {
- glyphPixelOffset.y = maxLineHeight - maxGlyphY - maxGlyphDescent;
- } else if (verticalOrigin === VerticalOrigin.CENTER) {
- glyphPixelOffset.y = (maxLineHeight - maxGlyphY) / 2 - maxGlyphDescent;
- } else if (verticalOrigin === VerticalOrigin.BASELINE) {
- glyphPixelOffset.y = -backgroundPadding.y - maxGlyphDescent;
- } else {
-
- glyphPixelOffset.y = 0;
- }
- glyphPixelOffset.y = glyphPixelOffset.y * scale;
- backgroundBillboard.width = totalLineWidth;
- backgroundBillboard.height = totalLineHeight;
- backgroundBillboard._setTranslate(glyphPixelOffset);
- backgroundBillboard._labelTranslate = Cartesian2.clone(
- glyphPixelOffset,
- backgroundBillboard._labelTranslate
- );
- }
- if (label.heightReference === HeightReference.CLAMP_TO_GROUND) {
- for (glyphIndex = 0; glyphIndex < glyphLength; ++glyphIndex) {
- glyph = glyphs[glyphIndex];
- var billboard = glyph.billboard;
- if (defined(billboard)) {
- billboard._labelTranslate = Cartesian2.clone(
- glyphPixelOffset,
- billboard._labelTranslate
- );
- }
- }
- }
- }
- function destroyLabel(labelCollection, label) {
- var glyphs = label._glyphs;
- for (var i = 0, len = glyphs.length; i < len; ++i) {
- unbindGlyph(labelCollection, glyphs[i]);
- }
- if (defined(label._backgroundBillboard)) {
- labelCollection._backgroundBillboardCollection.remove(
- label._backgroundBillboard
- );
- label._backgroundBillboard = undefined;
- }
- label._labelCollection = undefined;
- if (defined(label._removeCallbackFunc)) {
- label._removeCallbackFunc();
- }
- destroyObject(label);
- }
- function LabelCollection(options) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
- this._scene = options.scene;
- this._batchTable = options.batchTable;
- this._textureAtlas = undefined;
- this._backgroundTextureAtlas = undefined;
- this._whitePixelIndex = undefined;
- this._backgroundBillboardCollection = new BillboardCollection({
- scene: this._scene,
- });
- this._backgroundBillboardCollection.destroyTextureAtlas = false;
- this._billboardCollection = new BillboardCollection({
- scene: this._scene,
- batchTable: this._batchTable,
- });
- this._billboardCollection.destroyTextureAtlas = false;
- this._billboardCollection._sdf = true;
- this._spareBillboards = [];
- this._glyphTextureCache = {};
- this._labels = [];
- this._labelsToUpdate = [];
- this._totalGlyphCount = 0;
- this._highlightColor = Color.clone(Color.WHITE);
-
- this.modelMatrix = Matrix4.clone(
- defaultValue(options.modelMatrix, Matrix4.IDENTITY)
- );
-
- this.debugShowBoundingVolume = defaultValue(
- options.debugShowBoundingVolume,
- false
- );
-
- this.blendOption = defaultValue(
- options.blendOption,
- BlendOption.OPAQUE_AND_TRANSLUCENT
- );
- }
- Object.defineProperties(LabelCollection.prototype, {
-
- length: {
- get: function () {
- return this._labels.length;
- },
- },
- });
- LabelCollection.prototype.add = function (options) {
- var label = new Label(options, this);
- this._labels.push(label);
- this._labelsToUpdate.push(label);
- return label;
- };
- LabelCollection.prototype.remove = function (label) {
- if (defined(label) && label._labelCollection === this) {
- var index = this._labels.indexOf(label);
- if (index !== -1) {
- this._labels.splice(index, 1);
- destroyLabel(this, label);
- return true;
- }
- }
- return false;
- };
- LabelCollection.prototype.removeAll = function () {
- var labels = this._labels;
- for (var i = 0, len = labels.length; i < len; ++i) {
- destroyLabel(this, labels[i]);
- }
- labels.length = 0;
- };
- LabelCollection.prototype.contains = function (label) {
- return defined(label) && label._labelCollection === this;
- };
- LabelCollection.prototype.get = function (index) {
-
- if (!defined(index)) {
- throw new DeveloperError("index is required.");
- }
-
- return this._labels[index];
- };
- LabelCollection.prototype.update = function (frameState) {
- var billboardCollection = this._billboardCollection;
- var backgroundBillboardCollection = this._backgroundBillboardCollection;
- billboardCollection.modelMatrix = this.modelMatrix;
- billboardCollection.debugShowBoundingVolume = this.debugShowBoundingVolume;
- backgroundBillboardCollection.modelMatrix = this.modelMatrix;
- backgroundBillboardCollection.debugShowBoundingVolume = this.debugShowBoundingVolume;
- var context = frameState.context;
- if (!defined(this._textureAtlas)) {
- this._textureAtlas = new TextureAtlas({
- context: context,
- });
- billboardCollection.textureAtlas = this._textureAtlas;
- }
- if (!defined(this._backgroundTextureAtlas)) {
- this._backgroundTextureAtlas = new TextureAtlas({
- context: context,
- initialSize: whitePixelSize,
- });
- backgroundBillboardCollection.textureAtlas = this._backgroundTextureAtlas;
- addWhitePixelCanvas(this._backgroundTextureAtlas, this);
- }
- var len = this._labelsToUpdate.length;
- for (var i = 0; i < len; ++i) {
- var label = this._labelsToUpdate[i];
- if (label.isDestroyed()) {
- continue;
- }
- var preUpdateGlyphCount = label._glyphs.length;
- if (label._rebindAllGlyphs) {
- rebindAllGlyphs(this, label);
- label._rebindAllGlyphs = false;
- }
- if (label._repositionAllGlyphs) {
- repositionAllGlyphs(label);
- label._repositionAllGlyphs = false;
- }
- var glyphCountDifference = label._glyphs.length - preUpdateGlyphCount;
- this._totalGlyphCount += glyphCountDifference;
- }
- var blendOption =
- backgroundBillboardCollection.length > 0
- ? BlendOption.TRANSLUCENT
- : this.blendOption;
- billboardCollection.blendOption = blendOption;
- backgroundBillboardCollection.blendOption = blendOption;
- billboardCollection._highlightColor = this._highlightColor;
- backgroundBillboardCollection._highlightColor = this._highlightColor;
- this._labelsToUpdate.length = 0;
- backgroundBillboardCollection.update(frameState);
- billboardCollection.update(frameState);
- };
- LabelCollection.prototype.isDestroyed = function () {
- return false;
- };
- LabelCollection.prototype.destroy = function () {
- this.removeAll();
- this._billboardCollection = this._billboardCollection.destroy();
- this._textureAtlas = this._textureAtlas && this._textureAtlas.destroy();
- this._backgroundBillboardCollection = this._backgroundBillboardCollection.destroy();
- this._backgroundTextureAtlas =
- this._backgroundTextureAtlas && this._backgroundTextureAtlas.destroy();
- return destroyObject(this);
- };
- export default LabelCollection;
|