Browse Source

Refactor Layer

up-style-manager
Artur Arseniev 5 years ago
parent
commit
44de77d2fa
  1. 85
      src/style_manager/model/Layer.js
  2. 2
      src/style_manager/model/PropertyStack.js

85
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();
},
});
}
}

2
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

Loading…
Cancel
Save