Private source methods

This commit is contained in:
Tim Schaub
2013-11-15 13:37:06 -07:00
parent 2000b0af78
commit 01a0b9ff8d
2 changed files with 10 additions and 8 deletions

View File

@@ -141,7 +141,7 @@ ol.source.Vector.prototype.getFeatures = function(opt_filter) {
*/ */
ol.source.Vector.prototype.getFeaturesObjectForExtent = function(extent, ol.source.Vector.prototype.getFeaturesObjectForExtent = function(extent,
projection, opt_callback) { projection, opt_callback) {
var state = this.prepareFeatures(extent, projection, opt_callback); var state = this.prepareFeatures_(extent, projection, opt_callback);
var lookup = null; var lookup = null;
if (state !== ol.source.VectorLoadState.LOADING) { if (state !== ol.source.VectorLoadState.LOADING) {
lookup = this.featureCache_.getFeaturesObjectForExtent(extent); lookup = this.featureCache_.getFeaturesObjectForExtent(extent);
@@ -214,8 +214,9 @@ ol.source.Vector.prototype.groupFeaturesBySymbolizerLiteral =
* @param {Object|Element|Document|string} data Feature data. * @param {Object|Element|Document|string} data Feature data.
* @param {ol.proj.Projection} projection This sucks. The layer should be a * @param {ol.proj.Projection} projection This sucks. The layer should be a
* view in one projection. * view in one projection.
* @private
*/ */
ol.source.Vector.prototype.parseFeatures = function(data, projection) { ol.source.Vector.prototype.parseFeatures_ = function(data, projection) {
var addFeatures = function(data) { var addFeatures = function(data) {
var features = data.features; var features = data.features;
@@ -319,8 +320,9 @@ ol.source.Vector.prototype.clear = function() {
* @param {function()=} opt_callback Callback which is called when features are * @param {function()=} opt_callback Callback which is called when features are
* parsed after loading. * parsed after loading.
* @return {ol.source.VectorLoadState} The current load state. * @return {ol.source.VectorLoadState} The current load state.
* @private
*/ */
ol.source.Vector.prototype.prepareFeatures = function(extent, projection, ol.source.Vector.prototype.prepareFeatures_ = function(extent, projection,
opt_callback) { opt_callback) {
// TODO: Implement strategies. BBOX aware strategies will need the extent. // TODO: Implement strategies. BBOX aware strategies will need the extent.
if (goog.isDef(this.url_) && if (goog.isDef(this.url_) &&
@@ -330,7 +332,7 @@ ol.source.Vector.prototype.prepareFeatures = function(extent, projection,
var xhr = event.target; var xhr = event.target;
if (xhr.isSuccess()) { if (xhr.isSuccess()) {
// TODO: Get source projection from data if supported by parser. // TODO: Get source projection from data if supported by parser.
this.parseFeatures(xhr.getResponseText(), projection); this.parseFeatures_(xhr.getResponseText(), projection);
this.loadState_ = ol.source.VectorLoadState.LOADED; this.loadState_ = ol.source.VectorLoadState.LOADED;
if (goog.isDef(opt_callback)) { if (goog.isDef(opt_callback)) {
opt_callback(); opt_callback();
@@ -341,7 +343,7 @@ ol.source.Vector.prototype.prepareFeatures = function(extent, projection,
} }
}, this)); }, this));
} else if (!goog.isNull(this.data_)) { } else if (!goog.isNull(this.data_)) {
this.parseFeatures(this.data_, projection); this.parseFeatures_(this.data_, projection);
this.data_ = null; this.data_ = null;
this.loadState_ = ol.source.VectorLoadState.LOADED; this.loadState_ = ol.source.VectorLoadState.LOADED;
} }

View File

@@ -121,13 +121,13 @@ describe('ol.source.Vector', function() {
}); });
describe('#prepareFeatures', function() { describe('#prepareFeatures_', function() {
it('loads and parses data from a file', function(done) { it('loads and parses data from a file', function(done) {
var source = new ol.source.Vector({ var source = new ol.source.Vector({
url: 'spec/ol/parser/geojson/countries.geojson', url: 'spec/ol/parser/geojson/countries.geojson',
parser: new ol.parser.GeoJSON() parser: new ol.parser.GeoJSON()
}); });
source.prepareFeatures([-180, -90, 180, 90], source.prepareFeatures_([-180, -90, 180, 90],
ol.proj.get('EPSG:4326'), ol.proj.get('EPSG:4326'),
function() { function() {
expect(source.loadState_).to.be(ol.source.VectorLoadState.LOADED); expect(source.loadState_).to.be(ol.source.VectorLoadState.LOADED);
@@ -170,7 +170,7 @@ describe('ol.source.Vector', function() {
parser: new ol.parser.GeoJSON(), parser: new ol.parser.GeoJSON(),
projection: ol.proj.get('EPSG:4326') projection: ol.proj.get('EPSG:4326')
}); });
source.prepareFeatures([-180, -90, 180, 90], source.prepareFeatures_([-180, -90, 180, 90],
ol.proj.get('EPSG:4326'), ol.proj.get('EPSG:4326'),
function() { function() {
expect(source.loadState_).to.be(ol.source.VectorLoadState.LOADED); expect(source.loadState_).to.be(ol.source.VectorLoadState.LOADED);