Separate out feature reading and feature adding

This commit is contained in:
Tom Payne
2014-03-25 16:51:26 +01:00
parent a31ad69ec4
commit 4a484a7ad3
3 changed files with 73 additions and 60 deletions

View File

@@ -23,35 +23,51 @@ ol.source.StaticVector = function(options) {
});
if (goog.isDef(options.arrayBuffer)) {
this.readFeatures(options.arrayBuffer);
this.addFeaturesInternal(this.readFeatures(options.arrayBuffer));
}
if (goog.isDef(options.doc)) {
this.readFeatures(options.doc);
this.addFeaturesInternal(this.readFeatures(options.doc));
}
if (goog.isDef(options.node)) {
this.readFeatures(options.node);
this.addFeaturesInternal(this.readFeatures(options.node));
}
if (goog.isDef(options.object)) {
this.readFeatures(options.object);
this.addFeaturesInternal(this.readFeatures(options.object));
}
if (goog.isDef(options.text)) {
this.readFeatures(options.text);
this.addFeaturesInternal(this.readFeatures(options.text));
}
if (goog.isDef(options.url) || goog.isDef(options.urls)) {
this.setState(ol.source.State.LOADING);
if (goog.isDef(options.url)) {
this.loadFeaturesFromURL(options.url);
this.loadFeaturesFromURL(options.url,
/**
* @param {Array.<ol.Feature>} features Features.
* @this {ol.source.StaticVector}
*/
function(features) {
this.addFeaturesInternal(features);
this.setState(ol.source.State.READY);
}, this);
}
if (goog.isDef(options.urls)) {
var urls = options.urls;
var i, ii;
for (i = 0, ii = urls.length; i < ii; ++i) {
this.loadFeaturesFromURL(urls[i]);
this.loadFeaturesFromURL(urls[i],
/**
* @param {Array.<ol.Feature>} features Features.
* @this {ol.source.StaticVector}
*/
function(features) {
this.addFeaturesInternal(features);
this.setState(ol.source.State.READY);
}, this);
}
}
}