Add Property enum to ol.layer.Base

This commit is contained in:
Tim Schaub
2016-12-04 14:41:32 -07:00
parent 66dc2582ef
commit 57e3e7273e
2 changed files with 34 additions and 36 deletions

View File

@@ -1,5 +1,4 @@
goog.provide('ol.layer.Base');
goog.provide('ol.layer.LayerProperty');
goog.require('ol');
goog.require('ol.Object');
@@ -7,20 +6,6 @@ goog.require('ol.math');
goog.require('ol.obj');
/**
* @enum {string}
*/
ol.layer.LayerProperty = {
OPACITY: 'opacity',
VISIBLE: 'visible',
EXTENT: 'extent',
Z_INDEX: 'zIndex',
MAX_RESOLUTION: 'maxResolution',
MIN_RESOLUTION: 'minResolution',
SOURCE: 'source'
};
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
@@ -42,15 +27,15 @@ ol.layer.Base = function(options) {
* @type {Object.<string, *>}
*/
var properties = ol.obj.assign({}, options);
properties[ol.layer.LayerProperty.OPACITY] =
properties[ol.layer.Base.Property.OPACITY] =
options.opacity !== undefined ? options.opacity : 1;
properties[ol.layer.LayerProperty.VISIBLE] =
properties[ol.layer.Base.Property.VISIBLE] =
options.visible !== undefined ? options.visible : true;
properties[ol.layer.LayerProperty.Z_INDEX] =
properties[ol.layer.Base.Property.Z_INDEX] =
options.zIndex !== undefined ? options.zIndex : 0;
properties[ol.layer.LayerProperty.MAX_RESOLUTION] =
properties[ol.layer.Base.Property.MAX_RESOLUTION] =
options.maxResolution !== undefined ? options.maxResolution : Infinity;
properties[ol.layer.LayerProperty.MIN_RESOLUTION] =
properties[ol.layer.Base.Property.MIN_RESOLUTION] =
options.minResolution !== undefined ? options.minResolution : 0;
this.setProperties(properties);
@@ -111,7 +96,7 @@ ol.layer.Base.prototype.getLayerStatesArray = function(opt_states) {};
*/
ol.layer.Base.prototype.getExtent = function() {
return /** @type {ol.Extent|undefined} */ (
this.get(ol.layer.LayerProperty.EXTENT));
this.get(ol.layer.Base.Property.EXTENT));
};
@@ -123,7 +108,7 @@ ol.layer.Base.prototype.getExtent = function() {
*/
ol.layer.Base.prototype.getMaxResolution = function() {
return /** @type {number} */ (
this.get(ol.layer.LayerProperty.MAX_RESOLUTION));
this.get(ol.layer.Base.Property.MAX_RESOLUTION));
};
@@ -135,7 +120,7 @@ ol.layer.Base.prototype.getMaxResolution = function() {
*/
ol.layer.Base.prototype.getMinResolution = function() {
return /** @type {number} */ (
this.get(ol.layer.LayerProperty.MIN_RESOLUTION));
this.get(ol.layer.Base.Property.MIN_RESOLUTION));
};
@@ -146,7 +131,7 @@ ol.layer.Base.prototype.getMinResolution = function() {
* @api stable
*/
ol.layer.Base.prototype.getOpacity = function() {
return /** @type {number} */ (this.get(ol.layer.LayerProperty.OPACITY));
return /** @type {number} */ (this.get(ol.layer.Base.Property.OPACITY));
};
@@ -164,7 +149,7 @@ ol.layer.Base.prototype.getSourceState = function() {};
* @api stable
*/
ol.layer.Base.prototype.getVisible = function() {
return /** @type {boolean} */ (this.get(ol.layer.LayerProperty.VISIBLE));
return /** @type {boolean} */ (this.get(ol.layer.Base.Property.VISIBLE));
};
@@ -176,7 +161,7 @@ ol.layer.Base.prototype.getVisible = function() {
* @api
*/
ol.layer.Base.prototype.getZIndex = function() {
return /** @type {number} */ (this.get(ol.layer.LayerProperty.Z_INDEX));
return /** @type {number} */ (this.get(ol.layer.Base.Property.Z_INDEX));
};
@@ -188,7 +173,7 @@ ol.layer.Base.prototype.getZIndex = function() {
* @api stable
*/
ol.layer.Base.prototype.setExtent = function(extent) {
this.set(ol.layer.LayerProperty.EXTENT, extent);
this.set(ol.layer.Base.Property.EXTENT, extent);
};
@@ -199,7 +184,7 @@ ol.layer.Base.prototype.setExtent = function(extent) {
* @api stable
*/
ol.layer.Base.prototype.setMaxResolution = function(maxResolution) {
this.set(ol.layer.LayerProperty.MAX_RESOLUTION, maxResolution);
this.set(ol.layer.Base.Property.MAX_RESOLUTION, maxResolution);
};
@@ -210,7 +195,7 @@ ol.layer.Base.prototype.setMaxResolution = function(maxResolution) {
* @api stable
*/
ol.layer.Base.prototype.setMinResolution = function(minResolution) {
this.set(ol.layer.LayerProperty.MIN_RESOLUTION, minResolution);
this.set(ol.layer.Base.Property.MIN_RESOLUTION, minResolution);
};
@@ -221,7 +206,7 @@ ol.layer.Base.prototype.setMinResolution = function(minResolution) {
* @api stable
*/
ol.layer.Base.prototype.setOpacity = function(opacity) {
this.set(ol.layer.LayerProperty.OPACITY, opacity);
this.set(ol.layer.Base.Property.OPACITY, opacity);
};
@@ -232,7 +217,7 @@ ol.layer.Base.prototype.setOpacity = function(opacity) {
* @api stable
*/
ol.layer.Base.prototype.setVisible = function(visible) {
this.set(ol.layer.LayerProperty.VISIBLE, visible);
this.set(ol.layer.Base.Property.VISIBLE, visible);
};
@@ -244,5 +229,19 @@ ol.layer.Base.prototype.setVisible = function(visible) {
* @api
*/
ol.layer.Base.prototype.setZIndex = function(zindex) {
this.set(ol.layer.LayerProperty.Z_INDEX, zindex);
this.set(ol.layer.Base.Property.Z_INDEX, zindex);
};
/**
* @enum {string}
*/
ol.layer.Base.Property = {
OPACITY: 'opacity',
VISIBLE: 'visible',
EXTENT: 'extent',
Z_INDEX: 'zIndex',
MAX_RESOLUTION: 'maxResolution',
MIN_RESOLUTION: 'minResolution',
SOURCE: 'source'
};

View File

@@ -5,7 +5,6 @@ goog.require('ol.events.EventType');
goog.require('ol');
goog.require('ol.Object');
goog.require('ol.layer.Base');
goog.require('ol.layer.LayerProperty');
goog.require('ol.obj');
goog.require('ol.render.Event');
goog.require('ol.source.State');
@@ -62,7 +61,7 @@ ol.layer.Layer = function(options) {
}
ol.events.listen(this,
ol.Object.getChangeEventType(ol.layer.LayerProperty.SOURCE),
ol.Object.getChangeEventType(ol.layer.Base.Property.SOURCE),
this.handleSourcePropertyChange_, this);
var source = options.source ? options.source : null;
@@ -112,7 +111,7 @@ ol.layer.Layer.prototype.getLayerStatesArray = function(opt_states) {
* @api stable
*/
ol.layer.Layer.prototype.getSource = function() {
var source = this.get(ol.layer.LayerProperty.SOURCE);
var source = this.get(ol.layer.Base.Property.SOURCE);
return /** @type {ol.source.Source} */ (source) || null;
};
@@ -198,5 +197,5 @@ ol.layer.Layer.prototype.setMap = function(map) {
* @api stable
*/
ol.layer.Layer.prototype.setSource = function(source) {
this.set(ol.layer.LayerProperty.SOURCE, source);
this.set(ol.layer.Base.Property.SOURCE, source);
};