diff --git a/src/formats/kml/styles/Styles.js b/src/formats/kml/styles/Styles.js new file mode 100644 index 00000000..d5d3ed49 --- /dev/null +++ b/src/formats/kml/styles/Styles.js @@ -0,0 +1,28 @@ +define([], function(){ + /** + * This class retrieves the resulting styles as an object containing all finally applied styles. + * @param element {KmlObject} Resolve styling for this object. + * @constructor + */ + var Styles = function(element) { + + }; + + Object.defineProperties(Styles.prototype, { + color: { + get: function() { + + } + }, + + colorMode: { + + } + }); + + Styles.prototype.styles = function() { + + }; + + return Styles; +}); \ No newline at end of file diff --git a/src/formats/kml/styles/StylesAttributes.js b/src/formats/kml/styles/StylesAttributes.js new file mode 100644 index 00000000..896c1524 --- /dev/null +++ b/src/formats/kml/styles/StylesAttributes.js @@ -0,0 +1,64 @@ +/** + * Created by jbalhar on 14. 3. 2016. + */ +define([ + '../../../util/Promise' +], function( + Promise +){ + /** + * This class should work for StyleAttributes. Therefore when it resolves it returns already prepared Attributes. + * It is used during the rendering phase but the rendering phase is synchronous while the styles retrieval is at + * least often asynchronous. This object must provide flag to see whether it was already resolved. + * @param styles {Styles} Style representation for current element. Based on this representation ths class resolves + * the attributes. + * @constructor + */ + var StyleAttributes = function(styles) { + this._isResolved = false; + this._styles = styles; + }; + + Object.defineProperties(StyleAttributes.prototype, { + isResolved: { + get: function() { + return this._isResolved; + } + } + }); + + /** + * It returns promise of style to be delivered. Promise will be resolved with object containing following object. + * { + * normal: { + * text: TextAttributes, + * shape: ShapeAttributes, + * annotation: AnnotationAttributes, + * placemark: PlacemarkAttributes + * }, + * highlighted: { + * text: TextAttributes, + * shape: ShapeAttributes, + * annotation: AnnotationAttributes, + * placemark: PlacemarkAttributes + * } + * } + * Would this suffice? Am I capable of understanding enough of the attributes? + * @returns {Promise} + */ + StyleAttributes.prototype.styles = function() { + var self = this; + self._styles. + return new Promise(function(resolve, reject) { + var promiseOfStyles = self._styles.resolve(); + promiseOfStyles.then(function(styles){ + self._isResolved = true; + resolve(); + }); + }); + }; + + // We must add cached StyleAttributes, which stores the computed value. We can then + + return StyleAttributes; +}); \ No newline at end of file diff --git a/src/formats/kml/util/Style.js b/src/formats/kml/util/Style.js index b7b566b5..330d4fab 100644 --- a/src/formats/kml/util/Style.js +++ b/src/formats/kml/util/Style.js @@ -1,14 +1,185 @@ -/* - * Copyright (C) 2014 United States Government as represented by the Administrator of the - * National Aeronautics and Space Administration. All Rights Reserved. - */ -define([], function(){ +define([ + '../../../util/Color', + '../../../util/Font', + '../../../util/Offset', + '../../../shapes/PlacemarkAttributes', + '../../../shapes/ShapeAttributes', + '../../../shapes/TextAttributes' +], function( + Color, + Font, + Offset, + PlacemarkAttributes, + ShapeAttributes, + TextAttributes +) { /** - * This class represents style for current element. It understands what is current state and if necessary traverse - * hierarchy to retrieve the correct style. + * This object is used to apply all the styles applicable to current element. It remains stable unless NetworkLink + * or Region * @constructor */ - var Style = function(element) { - - } + var Style = function() { + this._balloonStyle = null; + this._iconStyle = null; + this._labelStyle = null; + this._lineStyle = null; + this._listStyle = null; + this._polyStyle = null; + }; + + Object.defineProperties(Style.prototype, { + balloonStyle: { + get: function() { + return this._balloonStyle; + } + }, + + iconStyle: { + get: function() { + return this._iconStyle; + } + }, + + labelStyle: { + get: function() { + return this._labelStyle; + } + }, + + lineStyle: { + get: function() { + return this._lineStyle; + } + }, + + listStyle: { + get: function() { + return this._listStyle; + } + }, + + polyStyle: { + get: function() { + return this._polyStyle; + } + } + }); + + /** + * It applies the KmlStyle element to current status of the attributes; + * @param styleElement {KmlStyle} + */ + Style.prototype.apply = function(styleElement) { + if(styleElement.kmlBalloonStyle) { + this.applyBalloonStyle(styleElement.kmlBalloonStyle); + } + if(styleElement.kmlIconStyle) { + this.applyIconStyle(styleElement.kmlIconStyle); + } + if(styleElement.kmlLabelStyle) { + this.applyLabelStyle(styleElement.kmlLabelStyle); + } + if(styleElement.kmlLineStyle) { + this.applyLineStyle(styleElement.kmlLineStyle); + } + if(styleElement.kmlListStyle) { + this.applyListStyle(styleElement.kmlListStyle); + } + if(styleElement.kmlPolyStyle) { + this.applyPolyStyle(styleElement.kmlPolyStyle); + } + }; + + Style.prototype.applyBalloonStyle = function(style) { + // TODO: To be implemented later. + }; + + Style.prototype.applyIconStyle = function(style){ + // TODO: To be implemented later. + }; + + Style.prototype.applyLabelStyle = function(style) { + // So far it seems, that it doesn't do anything. + }; + + /** + * So far it seems that we support only these attributes. color, outerColor and width. + * @param style {KmlLineStyle} Style applied to the shape attributes. + */ + Style.prototype.applyLineStyle = function(style) { + this._shapeAttributes.interiorColor = style.kmlColor; + this._shapeAttributes.outlineColor = style.kmlOuterColor; + this._shapeAttributes.outlineWidth = style.kmlWidth; + }; + + Style.prototype.applyListStyle = function(style) { + // TODO: To be implemented later. + }; + + Style.prototype.applyPolyStyle = function(polyStyle) { + + }; + + /** + * Prepare default values for the placemark Attributes. + * @param attributes + * @returns {Object} + */ + Style.prototype.placemarkAttributes = function(attributes) { + attributes = attributes || {}; + // These are all documented with their property accessors below. + attributes._imageColor = attributes._imageColor || new Color(1, 1, 1, 1); + attributes._imageOffset = attributes._imageOffset|| + new Offset(WorldWind.OFFSET_FRACTION, 0.5, WorldWind.OFFSET_FRACTION, 0.5); + attributes._imageScale = attributes._imageScale || 1; + attributes._imageSource = attributes._imageSource || null; + attributes._depthTest = attributes._depthTest || true; + attributes._drawLeaderLine = attributes._drawLeaderLine || false; + + return attributes; + }; + + /** + * Prepare default values for text attributes + * @param attributes + * @returns {Object} + */ + Style.prototype.textAttributes = function(attributes) { + attributes = attributes || {}; + attributes._color = attributes._color || new Color(1, 1, 1, 1); + attributes._font = attributes._font || new Font(14); + attributes._offset = attributes._offset || new Offset(WorldWind.OFFSET_FRACTION, 0.5, WorldWind.OFFSET_FRACTION, 0.0); + attributes._scale = attributes._scale || 1; + attributes._depthTest = attributes._depthTest || false; + + return attributes; + }; + + /** + * Prepare default values for shape attributes + * @param attributes + * @returns {*|{}} + */ + Style.prototype.shapeAttributes = function(attributes) { + attributes = attributes || {}; + // All these are documented with their property accessors below. + attributes._drawInterior = attributes._drawInterior || true; + attributes._drawOutline = attributes._drawOutline || true; + attributes._enableLighting = attributes._enableLighting || false; + attributes._interiorColor = attributes._interiorColor || Color.WHITE; + attributes._outlineColor = attributes._outlineColor || Color.RED; + attributes._outlineWidth = attributes._outlineWidth || 1.0; + attributes._outlineStippleFactor = attributes._outlineStippleFactor || 0; + attributes._outlineStipplePattern = attributes._outlineStipplePattern || 0xF0F0; + attributes._imageSource = attributes._imageSource || null; + attributes._depthTest = attributes._depthTest || true; + attributes._drawVerticals = attributes._drawVerticals || false; + attributes._applyLighting = attributes._applyLighting || false; + + return attributes; + }; + + + + return Style; }); \ No newline at end of file diff --git a/src/formats/kml/util/Styles.js b/src/formats/kml/util/Styles.js new file mode 100644 index 00000000..8ef49822 --- /dev/null +++ b/src/formats/kml/util/Styles.js @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 United States Government as represented by the Administrator of the + * National Aeronautics and Space Administration. All Rights Reserved. + */ +define([ + '../../../util/Promise' +], function (Promise) { + /** + * This class represents style for current element. It understands what is current state and if necessary traverse + * hierarchy to retrieve the correct style. + * @constructor + */ + var Style = function (element) { + this._element = element; + }; + + Style.prototype.highlighted = function () { + return new Promise(function(resolve, reject) { + // There will be collection of styles in the hierarchy. The user of this will decide, whether he is + // interested in all the types of styles. + }); + }; + + Style.prototype.normal = function () { + + }; + + // Find a style regardless of where it belongs. + // Take an element and look for style. If there is style take it as a basis. The nearer ones have precedence. + // Therefore we need to start with the file itself and then go down through the hierarchy. + function traverseElementForStyle() { + var relevantElements = collectParents(); + relevantElements.forEach(function(element){ + + }); + // If you run into something, then you need to apply it to the BaseStyle. The issue + } + + function collectParents() { + var parent = this._element.parent; + var parents = []; + while(parent != null) { + parents.push(parent); + parent = parent.parent; + } + return parents.reverse(); + } + + function styleForElement(element) { + if(element.kmlStyleSelector || element.kmlStyleUrl) { + // Resolve Style + } + } + + return Style; +}); \ No newline at end of file diff --git a/test/formats/kml/util/Style.test.js b/test/formats/kml/util/Style.test.js new file mode 100644 index 00000000..f5f5097d --- /dev/null +++ b/test/formats/kml/util/Style.test.js @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2014 United States Government as represented by the Administrator of the + * National Aeronautics and Space Administration. All Rights Reserved. + */ +require({ + baseUrl: '/test/' +}, [ + 'test/CatchTest', + 'src/formats/kml/KmlDocument', + 'src/formats/kml/util/NodeTransformers', + 'src/util/XmlDocument' +], function (CatchTest, + KmlDocument, + NodeTransformers, + XmlDocument) { + "use strict"; + + + + TestCase("Style#withIdSimpleLevel", { + testRetrievingStyle: function() { + + } + }); +}); \ No newline at end of file diff --git a/test/formats/kml/util/Styles.test.js b/test/formats/kml/util/Styles.test.js new file mode 100644 index 00000000..b0477439 --- /dev/null +++ b/test/formats/kml/util/Styles.test.js @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2014 United States Government as represented by the Administrator of the + * National Aeronautics and Space Administration. All Rights Reserved. + */ +require({ + baseUrl: '/test/' +}, [ + 'test/CatchTest', + 'src/formats/kml/KmlDocument', + 'src/formats/kml/util/NodeTransformers', + 'src/util/XmlDocument' +], function (CatchTest, + KmlDocument, + NodeTransformers, + XmlDocument) { + "use strict"; + var styleWithIdDocument = '' + + '' + + '' + + ' ' + + ' ' + + ' #yellowLineGreenPoly' + + ' ' + + '' + + ''; + var document = new XmlDocument(styleWithIdDocument).dom(); + var kmlDocument = new KmlDocument({objectNode: document.getElementById("1")}); + + TestCase("Style#withIdSimpleLevel", { + testRetrievingStyle: function() { + + } + }); +}); \ No newline at end of file