Allow source to be set after layer construction
This commit is contained in:
@@ -169,6 +169,9 @@ ol.control.Attribution.prototype.getSourceAttributions = function(frameState) {
|
||||
var hiddenAttributions = {};
|
||||
for (i = 0, ii = layerStatesArray.length; i < ii; i++) {
|
||||
source = layerStatesArray[i].layer.getSource();
|
||||
if (goog.isNull(source)) {
|
||||
continue;
|
||||
}
|
||||
sourceKey = goog.getUid(source).toString();
|
||||
sourceAttributions = source.getAttributions();
|
||||
if (goog.isNull(sourceAttributions)) {
|
||||
|
||||
@@ -15,10 +15,11 @@ goog.require('ol.layer.Layer');
|
||||
* @constructor
|
||||
* @extends {ol.layer.Layer}
|
||||
* @fires ol.render.Event
|
||||
* @param {olx.layer.ImageOptions} options Layer options.
|
||||
* @param {olx.layer.ImageOptions=} opt_options Layer options.
|
||||
* @api stable
|
||||
*/
|
||||
ol.layer.Image = function(options) {
|
||||
ol.layer.Image = function(opt_options) {
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
goog.base(this, /** @type {olx.layer.LayerOptions} */ (options));
|
||||
};
|
||||
goog.inherits(ol.layer.Image, ol.layer.Layer);
|
||||
|
||||
@@ -7,6 +7,7 @@ goog.require('goog.object');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.layer.Base');
|
||||
goog.require('ol.layer.LayerProperty');
|
||||
goog.require('ol.source.State');
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +43,8 @@ ol.layer.Layer = function(options) {
|
||||
ol.Object.getChangeEventType(ol.layer.LayerProperty.SOURCE),
|
||||
this.handleSourcePropertyChange_, false, this);
|
||||
|
||||
this.setSource(options.source);
|
||||
var source = goog.isDef(options.source) ? options.source : null;
|
||||
this.setSource(source);
|
||||
};
|
||||
goog.inherits(ol.layer.Layer, ol.layer.Base);
|
||||
|
||||
@@ -83,7 +85,7 @@ ol.layer.Layer.prototype.getLayerStatesArray = function(opt_states) {
|
||||
|
||||
/**
|
||||
* Get the layer source.
|
||||
* @return {ol.source.Source} Source.
|
||||
* @return {ol.source.Source} The layer source (or `null` if not yet set).
|
||||
* @observable
|
||||
* @api stable
|
||||
*/
|
||||
@@ -102,7 +104,14 @@ goog.exportProperty(
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.layer.Layer.prototype.getSourceState = function() {
|
||||
return this.getSource().getState();
|
||||
var source = this.getSource();
|
||||
var state;
|
||||
if (!goog.isNull(source)) {
|
||||
state = source.getState();
|
||||
} else {
|
||||
state = ol.source.State.UNDEFINED;
|
||||
}
|
||||
return state;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -24,10 +24,11 @@ ol.layer.TileProperty = {
|
||||
* @constructor
|
||||
* @extends {ol.layer.Layer}
|
||||
* @fires ol.render.Event
|
||||
* @param {olx.layer.TileOptions} options Tile layer options.
|
||||
* @param {olx.layer.TileOptions=} opt_options Tile layer options.
|
||||
* @api stable
|
||||
*/
|
||||
ol.layer.Tile = function(options) {
|
||||
ol.layer.Tile = function(opt_options) {
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
goog.base(this, /** @type {olx.layer.LayerOptions} */ (options));
|
||||
};
|
||||
goog.inherits(ol.layer.Tile, ol.layer.Layer);
|
||||
|
||||
@@ -69,6 +69,15 @@ ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtPixel =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.dom.ImageLayer.prototype.clearFrame = function() {
|
||||
goog.dom.removeChildren(this.target);
|
||||
this.image_ = null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -27,6 +27,12 @@ ol.renderer.dom.Layer = function(mapRenderer, layer, target) {
|
||||
goog.inherits(ol.renderer.dom.Layer, ol.renderer.Layer);
|
||||
|
||||
|
||||
/**
|
||||
* Clear rendered elements.
|
||||
*/
|
||||
ol.renderer.dom.Layer.prototype.clearFrame = goog.nullFunction;
|
||||
|
||||
|
||||
/**
|
||||
* @param {olx.FrameState} frameState Frame state.
|
||||
* @param {ol.layer.LayerState} layerState Layer state.
|
||||
|
||||
@@ -244,6 +244,8 @@ ol.renderer.dom.Map.prototype.renderFrame = function(frameState) {
|
||||
if (layerRenderer.prepareFrame(frameState, layerState)) {
|
||||
layerRenderer.composeFrame(frameState, layerState);
|
||||
}
|
||||
} else {
|
||||
layerRenderer.clearFrame();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,15 @@ ol.renderer.dom.TileLayer = function(mapRenderer, tileLayer) {
|
||||
goog.inherits(ol.renderer.dom.TileLayer, ol.renderer.dom.Layer);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.dom.TileLayer.prototype.clearFrame = function() {
|
||||
goog.dom.removeChildren(this.target);
|
||||
this.renderedRevision_ = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -9,11 +9,12 @@ goog.require('ol.proj');
|
||||
|
||||
|
||||
/**
|
||||
* State of the source, one of 'loading', 'ready' or 'error'.
|
||||
* State of the source, one of 'undefined', 'loading', 'ready' or 'error'.
|
||||
* @enum {string}
|
||||
* @api
|
||||
*/
|
||||
ol.source.State = {
|
||||
UNDEFINED: 'undefined',
|
||||
LOADING: 'loading',
|
||||
READY: 'ready',
|
||||
ERROR: 'error'
|
||||
|
||||
Reference in New Issue
Block a user