1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576 |
- import BoundingRectangle from "../Core/BoundingRectangle.js";
- import Cartesian2 from "../Core/Cartesian2.js";
- import Cartesian3 from "../Core/Cartesian3.js";
- import Color from "../Core/Color.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- import DeveloperError from "../Core/DeveloperError.js";
- import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";
- import NearFarScalar from "../Core/NearFarScalar.js";
- import Billboard from "./Billboard.js";
- import HeightReference from "./HeightReference.js";
- import HorizontalOrigin from "./HorizontalOrigin.js";
- import LabelStyle from "./LabelStyle.js";
- import SDFSettings from "./SDFSettings.js";
- import VerticalOrigin from "./VerticalOrigin.js";
- var fontInfoCache = {};
- var fontInfoCacheLength = 0;
- var fontInfoCacheMaxSize = 256;
- var defaultBackgroundColor = new Color(0.165, 0.165, 0.165, 0.8);
- var defaultBackgroundPadding = new Cartesian2(7, 5);
- var textTypes = Object.freeze({
- LTR: 0,
- RTL: 1,
- WEAK: 2,
- BRACKETS: 3,
- });
- function rebindAllGlyphs(label) {
- if (!label._rebindAllGlyphs && !label._repositionAllGlyphs) {
-
- label._labelCollection._labelsToUpdate.push(label);
- }
- label._rebindAllGlyphs = true;
- }
- function repositionAllGlyphs(label) {
- if (!label._rebindAllGlyphs && !label._repositionAllGlyphs) {
-
- label._labelCollection._labelsToUpdate.push(label);
- }
- label._repositionAllGlyphs = true;
- }
- function getCSSValue(element, property) {
- return document.defaultView
- .getComputedStyle(element, null)
- .getPropertyValue(property);
- }
- function parseFont(label) {
- var fontInfo = fontInfoCache[label._font];
- if (!defined(fontInfo)) {
- var div = document.createElement("div");
- div.style.position = "absolute";
- div.style.opacity = 0;
- div.style.font = label._font;
- document.body.appendChild(div);
- fontInfo = {
- family: getCSSValue(div, "font-family"),
- size: getCSSValue(div, "font-size").replace("px", ""),
- style: getCSSValue(div, "font-style"),
- weight: getCSSValue(div, "font-weight"),
- };
- document.body.removeChild(div);
- if (fontInfoCacheLength < fontInfoCacheMaxSize) {
- fontInfoCache[label._font] = fontInfo;
- fontInfoCacheLength++;
- }
- }
- label._fontFamily = fontInfo.family;
- label._fontSize = fontInfo.size;
- label._fontStyle = fontInfo.style;
- label._fontWeight = fontInfo.weight;
- }
- function Label(options, labelCollection) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
-
- if (
- defined(options.disableDepthTestDistance) &&
- options.disableDepthTestDistance < 0.0
- ) {
- throw new DeveloperError(
- "disableDepthTestDistance must be greater than 0.0."
- );
- }
-
- var translucencyByDistance = options.translucencyByDistance;
- var pixelOffsetScaleByDistance = options.pixelOffsetScaleByDistance;
- var scaleByDistance = options.scaleByDistance;
- var distanceDisplayCondition = options.distanceDisplayCondition;
- if (defined(translucencyByDistance)) {
-
- if (translucencyByDistance.far <= translucencyByDistance.near) {
- throw new DeveloperError(
- "translucencyByDistance.far must be greater than translucencyByDistance.near."
- );
- }
-
- translucencyByDistance = NearFarScalar.clone(translucencyByDistance);
- }
- if (defined(pixelOffsetScaleByDistance)) {
-
- if (pixelOffsetScaleByDistance.far <= pixelOffsetScaleByDistance.near) {
- throw new DeveloperError(
- "pixelOffsetScaleByDistance.far must be greater than pixelOffsetScaleByDistance.near."
- );
- }
-
- pixelOffsetScaleByDistance = NearFarScalar.clone(
- pixelOffsetScaleByDistance
- );
- }
- if (defined(scaleByDistance)) {
-
- if (scaleByDistance.far <= scaleByDistance.near) {
- throw new DeveloperError(
- "scaleByDistance.far must be greater than scaleByDistance.near."
- );
- }
-
- scaleByDistance = NearFarScalar.clone(scaleByDistance);
- }
- if (defined(distanceDisplayCondition)) {
-
- if (distanceDisplayCondition.far <= distanceDisplayCondition.near) {
- throw new DeveloperError(
- "distanceDisplayCondition.far must be greater than distanceDisplayCondition.near."
- );
- }
-
- distanceDisplayCondition = DistanceDisplayCondition.clone(
- distanceDisplayCondition
- );
- }
- this._renderedText = undefined;
- this._text = undefined;
- this._show = defaultValue(options.show, true);
- this._font = defaultValue(options.font, "30px sans-serif");
- this._fillColor = Color.clone(defaultValue(options.fillColor, Color.WHITE));
- this._outlineColor = Color.clone(
- defaultValue(options.outlineColor, Color.BLACK)
- );
- this._outlineWidth = defaultValue(options.outlineWidth, 1.0);
- this._showBackground = defaultValue(options.showBackground, false);
- this._backgroundColor = Color.clone(
- defaultValue(options.backgroundColor, defaultBackgroundColor)
- );
- this._backgroundPadding = Cartesian2.clone(
- defaultValue(options.backgroundPadding, defaultBackgroundPadding)
- );
- this._style = defaultValue(options.style, LabelStyle.FILL);
- this._verticalOrigin = defaultValue(
- options.verticalOrigin,
- VerticalOrigin.BASELINE
- );
- this._horizontalOrigin = defaultValue(
- options.horizontalOrigin,
- HorizontalOrigin.LEFT
- );
- this._pixelOffset = Cartesian2.clone(
- defaultValue(options.pixelOffset, Cartesian2.ZERO)
- );
- this._eyeOffset = Cartesian3.clone(
- defaultValue(options.eyeOffset, Cartesian3.ZERO)
- );
- this._position = Cartesian3.clone(
- defaultValue(options.position, Cartesian3.ZERO)
- );
- this._scale = defaultValue(options.scale, 1.0);
- this._id = options.id;
- this._translucencyByDistance = translucencyByDistance;
- this._pixelOffsetScaleByDistance = pixelOffsetScaleByDistance;
- this._scaleByDistance = scaleByDistance;
- this._heightReference = defaultValue(
- options.heightReference,
- HeightReference.NONE
- );
- this._distanceDisplayCondition = distanceDisplayCondition;
- this._disableDepthTestDistance = options.disableDepthTestDistance;
- this._labelCollection = labelCollection;
- this._glyphs = [];
- this._backgroundBillboard = undefined;
- this._batchIndex = undefined;
- this._rebindAllGlyphs = true;
- this._repositionAllGlyphs = true;
- this._actualClampedPosition = undefined;
- this._removeCallbackFunc = undefined;
- this._mode = undefined;
- this._clusterShow = true;
- this.text = defaultValue(options.text, "");
- this._relativeSize = 1.0;
- parseFont(this);
- this._updateClamping();
- }
- Object.defineProperties(Label.prototype, {
-
- show: {
- get: function () {
- return this._show;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._show !== value) {
- this._show = value;
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var billboard = glyphs[i].billboard;
- if (defined(billboard)) {
- billboard.show = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.show = value;
- }
- }
- },
- },
-
- position: {
- get: function () {
- return this._position;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var position = this._position;
- if (!Cartesian3.equals(position, value)) {
- Cartesian3.clone(value, position);
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var billboard = glyphs[i].billboard;
- if (defined(billboard)) {
- billboard.position = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.position = value;
- }
- this._updateClamping();
- }
- },
- },
-
- heightReference: {
- get: function () {
- return this._heightReference;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (value !== this._heightReference) {
- this._heightReference = value;
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var billboard = glyphs[i].billboard;
- if (defined(billboard)) {
- billboard.heightReference = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.heightReference = value;
- }
- repositionAllGlyphs(this);
- this._updateClamping();
- }
- },
- },
-
- text: {
- get: function () {
- return this._text;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._text !== value) {
- this._text = value;
- this._renderedText = Label.enableRightToLeftDetection
- ? reverseRtl(value)
- : value;
- rebindAllGlyphs(this);
- }
- },
- },
-
- font: {
- get: function () {
- return this._font;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._font !== value) {
- this._font = value;
- rebindAllGlyphs(this);
- parseFont(this);
- }
- },
- },
-
- fillColor: {
- get: function () {
- return this._fillColor;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var fillColor = this._fillColor;
- if (!Color.equals(fillColor, value)) {
- Color.clone(value, fillColor);
- rebindAllGlyphs(this);
- }
- },
- },
-
- outlineColor: {
- get: function () {
- return this._outlineColor;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var outlineColor = this._outlineColor;
- if (!Color.equals(outlineColor, value)) {
- Color.clone(value, outlineColor);
- rebindAllGlyphs(this);
- }
- },
- },
-
- outlineWidth: {
- get: function () {
- return this._outlineWidth;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._outlineWidth !== value) {
- this._outlineWidth = value;
- rebindAllGlyphs(this);
- }
- },
- },
-
- showBackground: {
- get: function () {
- return this._showBackground;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._showBackground !== value) {
- this._showBackground = value;
- rebindAllGlyphs(this);
- }
- },
- },
-
- backgroundColor: {
- get: function () {
- return this._backgroundColor;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var backgroundColor = this._backgroundColor;
- if (!Color.equals(backgroundColor, value)) {
- Color.clone(value, backgroundColor);
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.color = backgroundColor;
- }
- }
- },
- },
-
- backgroundPadding: {
- get: function () {
- return this._backgroundPadding;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var backgroundPadding = this._backgroundPadding;
- if (!Cartesian2.equals(backgroundPadding, value)) {
- Cartesian2.clone(value, backgroundPadding);
- repositionAllGlyphs(this);
- }
- },
- },
-
- style: {
- get: function () {
- return this._style;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._style !== value) {
- this._style = value;
- rebindAllGlyphs(this);
- }
- },
- },
-
- pixelOffset: {
- get: function () {
- return this._pixelOffset;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var pixelOffset = this._pixelOffset;
- if (!Cartesian2.equals(pixelOffset, value)) {
- Cartesian2.clone(value, pixelOffset);
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.pixelOffset = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.pixelOffset = value;
- }
- }
- },
- },
-
- translucencyByDistance: {
- get: function () {
- return this._translucencyByDistance;
- },
- set: function (value) {
-
- if (defined(value) && value.far <= value.near) {
- throw new DeveloperError(
- "far distance must be greater than near distance."
- );
- }
-
- var translucencyByDistance = this._translucencyByDistance;
- if (!NearFarScalar.equals(translucencyByDistance, value)) {
- this._translucencyByDistance = NearFarScalar.clone(
- value,
- translucencyByDistance
- );
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.translucencyByDistance = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.translucencyByDistance = value;
- }
- }
- },
- },
-
- pixelOffsetScaleByDistance: {
- get: function () {
- return this._pixelOffsetScaleByDistance;
- },
- set: function (value) {
-
- if (defined(value) && value.far <= value.near) {
- throw new DeveloperError(
- "far distance must be greater than near distance."
- );
- }
-
- var pixelOffsetScaleByDistance = this._pixelOffsetScaleByDistance;
- if (!NearFarScalar.equals(pixelOffsetScaleByDistance, value)) {
- this._pixelOffsetScaleByDistance = NearFarScalar.clone(
- value,
- pixelOffsetScaleByDistance
- );
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.pixelOffsetScaleByDistance = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.pixelOffsetScaleByDistance = value;
- }
- }
- },
- },
-
- scaleByDistance: {
- get: function () {
- return this._scaleByDistance;
- },
- set: function (value) {
-
- if (defined(value) && value.far <= value.near) {
- throw new DeveloperError(
- "far distance must be greater than near distance."
- );
- }
-
- var scaleByDistance = this._scaleByDistance;
- if (!NearFarScalar.equals(scaleByDistance, value)) {
- this._scaleByDistance = NearFarScalar.clone(value, scaleByDistance);
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.scaleByDistance = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.scaleByDistance = value;
- }
- }
- },
- },
-
- eyeOffset: {
- get: function () {
- return this._eyeOffset;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- var eyeOffset = this._eyeOffset;
- if (!Cartesian3.equals(eyeOffset, value)) {
- Cartesian3.clone(value, eyeOffset);
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.eyeOffset = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.eyeOffset = value;
- }
- }
- },
- },
-
- horizontalOrigin: {
- get: function () {
- return this._horizontalOrigin;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._horizontalOrigin !== value) {
- this._horizontalOrigin = value;
- repositionAllGlyphs(this);
- }
- },
- },
-
- verticalOrigin: {
- get: function () {
- return this._verticalOrigin;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._verticalOrigin !== value) {
- this._verticalOrigin = value;
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.verticalOrigin = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.verticalOrigin = value;
- }
- repositionAllGlyphs(this);
- }
- },
- },
-
- scale: {
- get: function () {
- return this._scale;
- },
- set: function (value) {
-
- if (!defined(value)) {
- throw new DeveloperError("value is required.");
- }
-
- if (this._scale !== value) {
- this._scale = value;
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.scale = value * this._relativeSize;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.scale = value * this._relativeSize;
- }
- repositionAllGlyphs(this);
- }
- },
- },
-
- totalScale: {
- get: function () {
- return this._scale * this._relativeSize;
- },
- },
-
- distanceDisplayCondition: {
- get: function () {
- return this._distanceDisplayCondition;
- },
- set: function (value) {
-
- if (defined(value) && value.far <= value.near) {
- throw new DeveloperError("far must be greater than near");
- }
-
- if (
- !DistanceDisplayCondition.equals(value, this._distanceDisplayCondition)
- ) {
- this._distanceDisplayCondition = DistanceDisplayCondition.clone(
- value,
- this._distanceDisplayCondition
- );
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.distanceDisplayCondition = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.distanceDisplayCondition = value;
- }
- }
- },
- },
-
- disableDepthTestDistance: {
- get: function () {
- return this._disableDepthTestDistance;
- },
- set: function (value) {
- if (this._disableDepthTestDistance !== value) {
-
- if (defined(value) && value < 0.0) {
- throw new DeveloperError(
- "disableDepthTestDistance must be greater than 0.0."
- );
- }
-
- this._disableDepthTestDistance = value;
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.disableDepthTestDistance = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.disableDepthTestDistance = value;
- }
- }
- },
- },
-
- id: {
- get: function () {
- return this._id;
- },
- set: function (value) {
- if (this._id !== value) {
- this._id = value;
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.id = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.id = value;
- }
- }
- },
- },
-
- pickId: {
- get: function () {
- if (this._glyphs.length === 0 || !defined(this._glyphs[0].billboard)) {
- return undefined;
- }
- return this._glyphs[0].billboard.pickId;
- },
- },
-
- _clampedPosition: {
- get: function () {
- return this._actualClampedPosition;
- },
- set: function (value) {
- this._actualClampedPosition = Cartesian3.clone(
- value,
- this._actualClampedPosition
- );
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
-
-
- glyph.billboard._clampedPosition = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard._clampedPosition = value;
- }
- },
- },
-
- clusterShow: {
- get: function () {
- return this._clusterShow;
- },
- set: function (value) {
- if (this._clusterShow !== value) {
- this._clusterShow = value;
- var glyphs = this._glyphs;
- for (var i = 0, len = glyphs.length; i < len; i++) {
- var glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.clusterShow = value;
- }
- }
- var backgroundBillboard = this._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- backgroundBillboard.clusterShow = value;
- }
- }
- },
- },
- });
- Label.prototype._updateClamping = function () {
- Billboard._updateClamping(this._labelCollection, this);
- };
- Label.prototype.computeScreenSpacePosition = function (scene, result) {
-
- if (!defined(scene)) {
- throw new DeveloperError("scene is required.");
- }
-
- if (!defined(result)) {
- result = new Cartesian2();
- }
- var labelCollection = this._labelCollection;
- var modelMatrix = labelCollection.modelMatrix;
- var actualPosition = defined(this._actualClampedPosition)
- ? this._actualClampedPosition
- : this._position;
- var windowCoordinates = Billboard._computeScreenSpacePosition(
- modelMatrix,
- actualPosition,
- this._eyeOffset,
- this._pixelOffset,
- scene,
- result
- );
- return windowCoordinates;
- };
- Label.getScreenSpaceBoundingBox = function (
- label,
- screenSpacePosition,
- result
- ) {
- var x = 0;
- var y = 0;
- var width = 0;
- var height = 0;
- var scale = label.totalScale;
- var backgroundBillboard = label._backgroundBillboard;
- if (defined(backgroundBillboard)) {
- x = screenSpacePosition.x + backgroundBillboard._translate.x;
- y = screenSpacePosition.y - backgroundBillboard._translate.y;
- width = backgroundBillboard.width * scale;
- height = backgroundBillboard.height * scale;
- if (
- label.verticalOrigin === VerticalOrigin.BOTTOM ||
- label.verticalOrigin === VerticalOrigin.BASELINE
- ) {
- y -= height;
- } else if (label.verticalOrigin === VerticalOrigin.CENTER) {
- y -= height * 0.5;
- }
- } else {
- x = Number.POSITIVE_INFINITY;
- y = Number.POSITIVE_INFINITY;
- var maxX = 0;
- var maxY = 0;
- var glyphs = label._glyphs;
- var length = glyphs.length;
- for (var i = 0; i < length; ++i) {
- var glyph = glyphs[i];
- var billboard = glyph.billboard;
- if (!defined(billboard)) {
- continue;
- }
- var glyphX = screenSpacePosition.x + billboard._translate.x;
- var glyphY = screenSpacePosition.y - billboard._translate.y;
- var glyphWidth = glyph.dimensions.width * scale;
- var glyphHeight = glyph.dimensions.height * scale;
- if (
- label.verticalOrigin === VerticalOrigin.BOTTOM ||
- label.verticalOrigin === VerticalOrigin.BASELINE
- ) {
- glyphY -= glyphHeight;
- } else if (label.verticalOrigin === VerticalOrigin.CENTER) {
- glyphY -= glyphHeight * 0.5;
- }
- if (label._verticalOrigin === VerticalOrigin.TOP) {
- glyphY += SDFSettings.PADDING * scale;
- } else if (
- label._verticalOrigin === VerticalOrigin.BOTTOM ||
- label._verticalOrigin === VerticalOrigin.BASELINE
- ) {
- glyphY -= SDFSettings.PADDING * scale;
- }
- x = Math.min(x, glyphX);
- y = Math.min(y, glyphY);
- maxX = Math.max(maxX, glyphX + glyphWidth);
- maxY = Math.max(maxY, glyphY + glyphHeight);
- }
- width = maxX - x;
- height = maxY - y;
- }
- if (!defined(result)) {
- result = new BoundingRectangle();
- }
- result.x = x;
- result.y = y;
- result.width = width;
- result.height = height;
- return result;
- };
- Label.prototype.equals = function (other) {
- return (
- this === other ||
- (defined(other) &&
- this._show === other._show &&
- this._scale === other._scale &&
- this._outlineWidth === other._outlineWidth &&
- this._showBackground === other._showBackground &&
- this._style === other._style &&
- this._verticalOrigin === other._verticalOrigin &&
- this._horizontalOrigin === other._horizontalOrigin &&
- this._heightReference === other._heightReference &&
- this._renderedText === other._renderedText &&
- this._font === other._font &&
- Cartesian3.equals(this._position, other._position) &&
- Color.equals(this._fillColor, other._fillColor) &&
- Color.equals(this._outlineColor, other._outlineColor) &&
- Color.equals(this._backgroundColor, other._backgroundColor) &&
- Cartesian2.equals(this._backgroundPadding, other._backgroundPadding) &&
- Cartesian2.equals(this._pixelOffset, other._pixelOffset) &&
- Cartesian3.equals(this._eyeOffset, other._eyeOffset) &&
- NearFarScalar.equals(
- this._translucencyByDistance,
- other._translucencyByDistance
- ) &&
- NearFarScalar.equals(
- this._pixelOffsetScaleByDistance,
- other._pixelOffsetScaleByDistance
- ) &&
- NearFarScalar.equals(this._scaleByDistance, other._scaleByDistance) &&
- DistanceDisplayCondition.equals(
- this._distanceDisplayCondition,
- other._distanceDisplayCondition
- ) &&
- this._disableDepthTestDistance === other._disableDepthTestDistance &&
- this._id === other._id)
- );
- };
- Label.prototype.isDestroyed = function () {
- return false;
- };
- Label.enableRightToLeftDetection = false;
- function convertTextToTypes(text, rtlChars) {
- var ltrChars = /[a-zA-Z0-9]/;
- var bracketsChars = /[()[\]{}<>]/;
- var parsedText = [];
- var word = "";
- var lastType = textTypes.LTR;
- var currentType = "";
- var textLength = text.length;
- for (var textIndex = 0; textIndex < textLength; ++textIndex) {
- var character = text.charAt(textIndex);
- if (rtlChars.test(character)) {
- currentType = textTypes.RTL;
- } else if (ltrChars.test(character)) {
- currentType = textTypes.LTR;
- } else if (bracketsChars.test(character)) {
- currentType = textTypes.BRACKETS;
- } else {
- currentType = textTypes.WEAK;
- }
- if (textIndex === 0) {
- lastType = currentType;
- }
- if (lastType === currentType && currentType !== textTypes.BRACKETS) {
- word += character;
- } else {
- if (word !== "") {
- parsedText.push({ Type: lastType, Word: word });
- }
- lastType = currentType;
- word = character;
- }
- }
- parsedText.push({ Type: currentType, Word: word });
- return parsedText;
- }
- function reverseWord(word) {
- return word.split("").reverse().join("");
- }
- function spliceWord(result, pointer, word) {
- return result.slice(0, pointer) + word + result.slice(pointer);
- }
- function reverseBrackets(bracket) {
- switch (bracket) {
- case "(":
- return ")";
- case ")":
- return "(";
- case "[":
- return "]";
- case "]":
- return "[";
- case "{":
- return "}";
- case "}":
- return "{";
- case "<":
- return ">";
- case ">":
- return "<";
- }
- }
- var hebrew = "\u05D0-\u05EA";
- var arabic = "\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF";
- var rtlChars = new RegExp("[" + hebrew + arabic + "]");
- function reverseRtl(value) {
- var texts = value.split("\n");
- var result = "";
- for (var i = 0; i < texts.length; i++) {
- var text = texts[i];
-
- var rtlDir = rtlChars.test(text.charAt(0));
- var parsedText = convertTextToTypes(text, rtlChars);
- var splicePointer = 0;
- var line = "";
- for (var wordIndex = 0; wordIndex < parsedText.length; ++wordIndex) {
- var subText = parsedText[wordIndex];
- var reverse =
- subText.Type === textTypes.BRACKETS
- ? reverseBrackets(subText.Word)
- : reverseWord(subText.Word);
- if (rtlDir) {
- if (subText.Type === textTypes.RTL) {
- line = reverse + line;
- splicePointer = 0;
- } else if (subText.Type === textTypes.LTR) {
- line = spliceWord(line, splicePointer, subText.Word);
- splicePointer += subText.Word.length;
- } else if (
- subText.Type === textTypes.WEAK ||
- subText.Type === textTypes.BRACKETS
- ) {
-
- if (
- subText.Type === textTypes.WEAK &&
- parsedText[wordIndex - 1].Type === textTypes.BRACKETS
- ) {
- line = reverse + line;
- }
-
- else if (parsedText[wordIndex - 1].Type === textTypes.RTL) {
- line = reverse + line;
- splicePointer = 0;
- }
-
- else if (parsedText.length > wordIndex + 1) {
-
- if (parsedText[wordIndex + 1].Type === textTypes.RTL) {
- line = reverse + line;
- splicePointer = 0;
- } else {
- line = spliceWord(line, splicePointer, subText.Word);
- splicePointer += subText.Word.length;
- }
- }
-
- else {
- line = spliceWord(line, 0, reverse);
- }
- }
- }
-
- else if (subText.Type === textTypes.RTL) {
- line = spliceWord(line, splicePointer, reverse);
- }
-
- else if (subText.Type === textTypes.LTR) {
- line += subText.Word;
- splicePointer = line.length;
- }
-
- else if (
- subText.Type === textTypes.WEAK ||
- subText.Type === textTypes.BRACKETS
- ) {
-
- if (wordIndex > 0) {
-
- if (parsedText[wordIndex - 1].Type === textTypes.RTL) {
-
- if (parsedText.length > wordIndex + 1) {
-
- if (parsedText[wordIndex + 1].Type === textTypes.RTL) {
- line = spliceWord(line, splicePointer, reverse);
- } else {
- line += subText.Word;
- splicePointer = line.length;
- }
- } else {
- line += subText.Word;
- }
- } else {
- line += subText.Word;
- splicePointer = line.length;
- }
- } else {
- line += subText.Word;
- splicePointer = line.length;
- }
- }
- }
- result += line;
- if (i < texts.length - 1) {
- result += "\n";
- }
- }
- return result;
- }
- export default Label;
|