123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703 |
- define([
- '../Core/Cartesian2',
- '../Core/Cartesian3',
- '../Core/Color',
- '../Core/defaultValue',
- '../Core/defined',
- '../Core/defineProperties',
- '../Core/DeveloperError',
- '../Core/NearFarScalar',
- './Billboard',
- './HorizontalOrigin',
- './LabelStyle',
- './VerticalOrigin'
- ], function(
- Cartesian2,
- Cartesian3,
- Color,
- defaultValue,
- defined,
- defineProperties,
- DeveloperError,
- NearFarScalar,
- Billboard,
- HorizontalOrigin,
- LabelStyle,
- VerticalOrigin) {
- "use strict";
- 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;
- }
-
- var Label = function(options, labelCollection) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
-
- if (defined(options.translucencyByDistance) && options.translucencyByDistance.far <= options.translucencyByDistance.near) {
- throw new DeveloperError('translucencyByDistance.far must be greater than translucencyByDistance.near.');
- }
- if (defined(options.pixelOffsetScaleByDistance) && options.pixelOffsetScaleByDistance.far <= options.pixelOffsetScaleByDistance.near) {
- throw new DeveloperError('pixelOffsetScaleByDistance.far must be greater than pixelOffsetScaleByDistance.near.');
- }
-
- this._text = defaultValue(options.text, '');
- 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._style = defaultValue(options.style, LabelStyle.FILL);
- this._verticalOrigin = defaultValue(options.verticalOrigin, VerticalOrigin.BOTTOM);
- 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 = options.translucencyByDistance;
- this._pixelOffsetScaleByDistance = options.pixelOffsetScaleByDistance;
- this._labelCollection = labelCollection;
- this._glyphs = [];
- this._rebindAllGlyphs = true;
- this._repositionAllGlyphs = true;
- };
- 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 glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.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 glyph = glyphs[i];
- if (defined(glyph.billboard)) {
- glyph.billboard.position = value;
- }
- }
- }
- }
- },
-
- 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;
- 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);
- }
- }
- },
-
- 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);
- }
- }
- },
-
- 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;
- }
- }
- }
- }
- },
-
- 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;
- }
- }
- }
- }
- },
-
- 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;
- }
- }
- }
- }
- },
-
- 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;
- }
- }
- }
- }
- },
-
- 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;
- }
- }
- 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;
- }
- }
- repositionAllGlyphs(this);
- }
- }
- },
-
- 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;
- }
- }
- }
- }
- }
- });
-
- Label.prototype.computeScreenSpacePosition = function(scene) {
-
- if (!defined(scene)) {
- throw new DeveloperError('context is required.');
- }
-
- var labelCollection = this._labelCollection;
- var modelMatrix = labelCollection.modelMatrix;
- var actualPosition = Billboard._computeActualPosition(this._position, scene.frameState, modelMatrix);
- var windowCoordinates = Billboard._computeScreenSpacePosition(modelMatrix, actualPosition, this._eyeOffset, this._pixelOffset, scene);
- windowCoordinates.y = scene.canvas.clientHeight - windowCoordinates.y;
- return windowCoordinates;
- };
-
- Label.prototype.equals = function(other) {
- return this === other ||
- defined(other) &&
- this._show === other._show &&
- this._scale === other._scale &&
- this._style === other._style &&
- this._verticalOrigin === other._verticalOrigin &&
- this._horizontalOrigin === other._horizontalOrigin &&
- this._text === other._text &&
- this._font === other._font &&
- Cartesian3.equals(this._position, other._position) &&
- Color.equals(this._fillColor, other._fillColor) &&
- Color.equals(this._outlineColor, other._outlineColor) &&
- Cartesian2.equals(this._pixelOffset, other._pixelOffset) &&
- Cartesian3.equals(this._eyeOffset, other._eyeOffset) &&
- NearFarScalar.equals(this._translucencyByDistance, other._translucencyByDistance) &&
- NearFarScalar.equals(this._pixelOffsetScaleByDistance, other._pixelOffsetScaleByDistance) &&
- this._id === other._id;
- };
-
- Label.prototype.isDestroyed = function() {
- return false;
- };
- return Label;
- });
|