diff --git a/src/style_manager/model/Layer.js b/src/style_manager/model/Layer.js index 5c6b206a9..26b2abee7 100644 --- a/src/style_manager/model/Layer.js +++ b/src/style_manager/model/Layer.js @@ -1,16 +1,44 @@ -import Backbone from 'backbone'; -import Properties from './Properties'; +import { Model } from 'common'; import { camelCase } from 'utils/mixins'; +import Properties from './Properties'; + +export default class Layer extends Model { + defaults() { + return { + index: '', + value: '', + values: {}, + active: false, + preview: false, + properties: [], + }; + } + + /** + * Get layer index. + * @returns {Number} + */ + getIndex() { + const coll = this.collection; + return coll ? coll.indexOf(this) : -1; + } -export default Backbone.Model.extend({ - defaults: { - index: '', - value: '', - values: {}, - active: false, - preview: false, - properties: [], - }, + /** + * Get layer values. + * @param {Object} [opts={}] Options + * @param {Boolean} [opts.camelCase] Return property names in camelCase. + * @returns {Object} + */ + getValues(opts = {}) { + const values = this.get('values'); + + return opts.camelCase + ? Object.keys(values).reduce((res, key) => { + res[camelCase(key)] = values[key]; + return res; + }, {}) + : values; + } initialize() { const prp = this.get('properties'); @@ -32,44 +60,23 @@ export default Backbone.Model.extend({ this.set('value', val.trim()); } - }, - - getValues(opts = {}) { - const values = this.get('values'); - - return opts.camelCase - ? Object.keys(values).reduce((res, key) => { - res[camelCase(key)] = values[key]; - return res; - }, {}) - : values; - }, + } upValues(props = {}) { return this.set('values', { ...this.getValues(), ...props, }); - }, - - getIndex() { - const coll = this.collection; - return coll ? coll.indexOf(this) : -1; - }, + } onPropAdd(prop) { const coll = this.collection; prop.parent = coll && coll.property; - }, + } - /** - * Get property at some index - * @param {Number} index - * @return {Object} - */ getPropertyAt(index) { return this.get('properties').at(index); - }, + } getPropertyValue(property) { let result = ''; @@ -79,11 +86,11 @@ export default Backbone.Model.extend({ } }); return result; - }, + } getFullValue() { let result = []; this.get('properties').each(prop => result.push(prop.getFullValue())); return result.join(' ').trim(); - }, -}); + } +} diff --git a/src/style_manager/model/PropertyStack.js b/src/style_manager/model/PropertyStack.js index 19c543b8e..bb19f1ac9 100644 --- a/src/style_manager/model/PropertyStack.js +++ b/src/style_manager/model/PropertyStack.js @@ -129,7 +129,7 @@ export default class PropertyStack extends PropertyComposite { } /** - * Get layer label. + * Get the layer label. The label can be customized with the `layerLabel` property. * @param {[Layer]} layer * @returns {String} * @example