Remove old ol.source.Vector

This commit is contained in:
Tom Payne
2014-01-18 20:16:33 +01:00
parent c74f0ba0e3
commit cdf896c776
3 changed files with 0 additions and 184 deletions

View File

@@ -1 +0,0 @@
@exportClass ol.source.Vector ol.source.VectorOptions

View File

@@ -1,96 +0,0 @@
goog.provide('ol.source.Vector');
goog.require('goog.asserts');
goog.require('goog.net.XhrIo');
goog.require('ol.source.Source');
/**
* @enum {number}
*/
ol.source.VectorLoadState = {
IDLE: 0,
LOADING: 1,
LOADED: 2,
ERROR: 3
};
/**
* @constructor
* @extends {ol.source.Source}
* @param {ol.source.VectorOptions} options Vector source options.
* @todo stability experimental
*/
ol.source.Vector = function(options) {
/**
* @private
* @type {Object|string}
*/
this.data_ = goog.isDef(options.data) ? options.data : null;
/**
* @private
* @type {ol.source.VectorLoadState}
*/
this.loadState_ = ol.source.VectorLoadState.IDLE;
/**
* @private
* @type {ol.parser.Parser}
*/
this.parser_ = goog.isDef(options.parser) ? options.parser : null;
/**
* @private
* @type {string|undefined}
*/
this.url_ = options.url;
goog.base(this, {
attributions: options.attributions,
extent: options.extent,
logo: options.logo,
projection: options.projection
});
};
goog.inherits(ol.source.Vector, ol.source.Source);
/**
* @param {ol.layer.Vector} layer Layer that parses the data.
* @param {ol.Extent} extent Extent that needs to be fetched.
* @param {ol.proj.Projection} projection Projection of the view.
* @param {function()=} opt_callback Callback which is called when features are
* parsed after loading.
* @return {ol.source.VectorLoadState} The current load state.
*/
ol.source.Vector.prototype.prepareFeatures = function(layer, extent, projection,
opt_callback) {
// TODO: Implement strategies. BBOX aware strategies will need the extent.
if (goog.isDef(this.url_) &&
this.loadState_ == ol.source.VectorLoadState.IDLE) {
this.loadState_ = ol.source.VectorLoadState.LOADING;
goog.net.XhrIo.send(this.url_, goog.bind(function(event) {
var xhr = event.target;
if (xhr.isSuccess()) {
// TODO: Get source projection from data if supported by parser.
layer.parseFeatures(xhr.getResponseText(), this.parser_, projection);
this.loadState_ = ol.source.VectorLoadState.LOADED;
if (goog.isDef(opt_callback)) {
opt_callback();
}
} else {
// TODO: Error handling.
this.loadState_ = ol.source.VectorLoadState.ERROR;
}
}, this));
} else if (!goog.isNull(this.data_)) {
layer.parseFeatures(this.data_, this.parser_, projection);
this.data_ = null;
this.loadState_ = ol.source.VectorLoadState.LOADED;
}
return this.loadState_;
};

View File

@@ -1,87 +0,0 @@
goog.provide('ol.test.source.Vector');
describe('ol.source.Vector', function() {
describe('constructor', function() {
it('creates an instance', function() {
var source = new ol.source.Vector({});
expect(source).to.be.a(ol.source.Vector);
expect(source).to.be.a(ol.source.Source);
});
});
describe('#prepareFeatures', function() {
it('loads and parses data from a file', function(done) {
var source = new ol.source.Vector({
url: 'spec/ol/parser/geojson/countries.geojson',
parser: new ol.parser.GeoJSON()
});
var layer = new ol.layer.Vector({
source: source
});
source.prepareFeatures(layer, [-180, -90, 180, 90],
ol.proj.get('EPSG:4326'),
function() {
expect(source.loadState_).to.be(ol.source.VectorLoadState.LOADED);
expect(goog.object.getCount(
layer.featureCache_.getFeaturesObject())).to.be(179);
done();
});
});
it('parses inline data', function() {
var source = new ol.source.Vector({
data: {
'type': 'FeatureCollection',
'features': [{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [0, -6000000]
}
}, {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-6000000, 0]
}
}, {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [0, 6000000]
}
}, {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [6000000, 0]
}
}]
},
parser: new ol.parser.GeoJSON(),
projection: ol.proj.get('EPSG:4326')
});
var layer = new ol.layer.Vector({
source: source
});
source.prepareFeatures(layer, [-180, -90, 180, 90],
ol.proj.get('EPSG:4326'),
function() {
expect(source.loadState_).to.be(ol.source.VectorLoadState.LOADED);
expect(goog.object.getCount(
layer.featureCache_.getFeaturesObject())).to.be(4);
done();
});
});
});
});
goog.require('goog.object');
goog.require('ol.layer.Vector');
goog.require('ol.parser.GeoJSON');
goog.require('ol.proj');
goog.require('ol.source.Source');
goog.require('ol.source.Vector');