Get rid of disliked vector classes
This commit is contained in:
@@ -1,127 +0,0 @@
|
||||
// FIXME consider delaying feature reading so projection can be provided by
|
||||
// consumer (e.g. the view)
|
||||
|
||||
goog.provide('ol.source.FormatVector');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.net.EventType');
|
||||
goog.require('goog.net.XhrIo');
|
||||
goog.require('goog.net.XhrIo.ResponseType');
|
||||
goog.require('goog.userAgent');
|
||||
goog.require('ol.format.FormatType');
|
||||
goog.require('ol.has');
|
||||
goog.require('ol.source.State');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.xml');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract base class; normally only used for creating subclasses and not
|
||||
* instantiated in apps.
|
||||
* Base class for vector sources in one of the supported formats.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.Vector}
|
||||
* @param {olx.source.FormatVectorOptions} options Options.
|
||||
*/
|
||||
ol.source.FormatVector = function(options) {
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
logo: options.logo,
|
||||
projection: options.projection
|
||||
});
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.format.Feature}
|
||||
*/
|
||||
this.format = options.format;
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.FormatVector, ol.source.Vector);
|
||||
|
||||
|
||||
/**
|
||||
* @param {goog.Uri|string} url URL.
|
||||
* @param {function(this: T, Array.<ol.Feature>)} success Success Callback.
|
||||
* @param {function(this: T)} error Error callback.
|
||||
* @param {T} thisArg Value to use as `this` when executing `success` or
|
||||
* `error`.
|
||||
* @template T
|
||||
*/
|
||||
ol.source.FormatVector.prototype.loadFeaturesFromURL =
|
||||
function(url, success, error, thisArg) {
|
||||
var xhrIo = new goog.net.XhrIo();
|
||||
var type = this.format.getType();
|
||||
var responseType;
|
||||
// FIXME maybe use ResponseType.DOCUMENT?
|
||||
if (type == ol.format.FormatType.BINARY &&
|
||||
ol.has.ARRAY_BUFFER) {
|
||||
responseType = goog.net.XhrIo.ResponseType.ARRAY_BUFFER;
|
||||
} else {
|
||||
responseType = goog.net.XhrIo.ResponseType.TEXT;
|
||||
}
|
||||
xhrIo.setResponseType(responseType);
|
||||
goog.events.listen(xhrIo, goog.net.EventType.COMPLETE,
|
||||
/**
|
||||
* @param {Event} event Event.
|
||||
* @private
|
||||
* @this {ol.source.FormatVector}
|
||||
*/
|
||||
function(event) {
|
||||
var xhrIo = event.target;
|
||||
goog.asserts.assertInstanceof(xhrIo, goog.net.XhrIo,
|
||||
'event.target/xhrIo is an instance of goog.net.XhrIo');
|
||||
if (xhrIo.isSuccess()) {
|
||||
var type = this.format.getType();
|
||||
/** @type {ArrayBuffer|Document|Node|Object|string|undefined} */
|
||||
var source;
|
||||
if (type == ol.format.FormatType.BINARY &&
|
||||
ol.has.ARRAY_BUFFER) {
|
||||
source = xhrIo.getResponse();
|
||||
goog.asserts.assertInstanceof(source, ArrayBuffer,
|
||||
'source is an instance of ArrayBuffer');
|
||||
} else if (type == ol.format.FormatType.JSON) {
|
||||
source = xhrIo.getResponseText();
|
||||
} else if (type == ol.format.FormatType.TEXT) {
|
||||
source = xhrIo.getResponseText();
|
||||
} else if (type == ol.format.FormatType.XML) {
|
||||
if (!goog.userAgent.IE) {
|
||||
source = xhrIo.getResponseXml();
|
||||
}
|
||||
if (!goog.isDefAndNotNull(source)) {
|
||||
source = ol.xml.parse(xhrIo.getResponseText());
|
||||
}
|
||||
} else {
|
||||
goog.asserts.fail('unexpected format type');
|
||||
}
|
||||
if (goog.isDefAndNotNull(source)) {
|
||||
success.call(thisArg, this.readFeatures(source));
|
||||
} else {
|
||||
this.setState(ol.source.State.ERROR);
|
||||
goog.asserts.fail('undefined or null source');
|
||||
}
|
||||
} else {
|
||||
error.call(thisArg);
|
||||
}
|
||||
goog.dispose(xhrIo);
|
||||
}, false, this);
|
||||
xhrIo.send(url);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @return {Array.<ol.Feature>} Features.
|
||||
* @api
|
||||
*/
|
||||
ol.source.FormatVector.prototype.readFeatures = function(source) {
|
||||
var format = this.format;
|
||||
var projection = this.getProjection();
|
||||
return format.readFeatures(source, {featureProjection: projection});
|
||||
};
|
||||
@@ -1,37 +0,0 @@
|
||||
goog.provide('ol.source.GeoJSON');
|
||||
|
||||
goog.require('ol.format.GeoJSON');
|
||||
goog.require('ol.source.StaticVector');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Static vector source in GeoJSON format
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.StaticVector}
|
||||
* @fires ol.source.VectorEvent
|
||||
* @param {olx.source.GeoJSONOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.source.GeoJSON = function(opt_options) {
|
||||
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
extent: options.extent,
|
||||
format: new ol.format.GeoJSON({
|
||||
defaultDataProjection: options.defaultProjection
|
||||
}),
|
||||
logo: options.logo,
|
||||
object: options.object,
|
||||
projection: options.projection,
|
||||
text: options.text,
|
||||
url: options.url,
|
||||
urls: options.urls
|
||||
});
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.GeoJSON, ol.source.StaticVector);
|
||||
@@ -1,36 +0,0 @@
|
||||
goog.provide('ol.source.GPX');
|
||||
|
||||
goog.require('ol.format.GPX');
|
||||
goog.require('ol.source.StaticVector');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Static vector source in GPX format
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.StaticVector}
|
||||
* @fires ol.source.VectorEvent
|
||||
* @param {olx.source.GPXOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.source.GPX = function(opt_options) {
|
||||
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
doc: options.doc,
|
||||
extent: options.extent,
|
||||
format: new ol.format.GPX(),
|
||||
logo: options.logo,
|
||||
node: options.node,
|
||||
projection: options.projection,
|
||||
text: options.text,
|
||||
url: options.url,
|
||||
urls: options.urls
|
||||
});
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.GPX, ol.source.StaticVector);
|
||||
@@ -1,33 +0,0 @@
|
||||
goog.provide('ol.source.IGC');
|
||||
|
||||
goog.require('ol.format.IGC');
|
||||
goog.require('ol.source.StaticVector');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Static vector source in IGC format
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.StaticVector}
|
||||
* @fires ol.source.VectorEvent
|
||||
* @param {olx.source.IGCOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.source.IGC = function(opt_options) {
|
||||
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
|
||||
goog.base(this, {
|
||||
format: new ol.format.IGC({
|
||||
altitudeMode: options.altitudeMode
|
||||
}),
|
||||
projection: options.projection,
|
||||
text: options.text,
|
||||
url: options.url,
|
||||
urls: options.urls
|
||||
});
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.IGC, ol.source.StaticVector);
|
||||
@@ -1,38 +0,0 @@
|
||||
goog.provide('ol.source.KML');
|
||||
|
||||
goog.require('ol.format.KML');
|
||||
goog.require('ol.source.StaticVector');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Static vector source in KML format
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.StaticVector}
|
||||
* @fires ol.source.VectorEvent
|
||||
* @param {olx.source.KMLOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.source.KML = function(opt_options) {
|
||||
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
doc: options.doc,
|
||||
format: new ol.format.KML({
|
||||
extractStyles: options.extractStyles,
|
||||
defaultStyle: options.defaultStyle
|
||||
}),
|
||||
logo: options.logo,
|
||||
node: options.node,
|
||||
projection: options.projection,
|
||||
text: options.text,
|
||||
url: options.url,
|
||||
urls: options.urls
|
||||
});
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.KML, ol.source.StaticVector);
|
||||
@@ -1,35 +0,0 @@
|
||||
goog.provide('ol.source.OSMXML');
|
||||
|
||||
goog.require('ol.format.OSMXML');
|
||||
goog.require('ol.source.StaticVector');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Static vector source in OSMXML format
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.StaticVector}
|
||||
* @fires ol.source.VectorEvent
|
||||
* @param {olx.source.OSMXMLOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.source.OSMXML = function(opt_options) {
|
||||
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
doc: options.doc,
|
||||
format: new ol.format.OSMXML(),
|
||||
logo: options.logo,
|
||||
node: options.node,
|
||||
projection: options.projection,
|
||||
text: options.text,
|
||||
url: options.url,
|
||||
urls: options.urls
|
||||
});
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.OSMXML, ol.source.StaticVector);
|
||||
@@ -1,126 +0,0 @@
|
||||
// FIXME cache expiration
|
||||
|
||||
goog.provide('ol.source.ServerVector');
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.loadingstrategy');
|
||||
goog.require('ol.source.FormatVector');
|
||||
goog.require('ol.structs.RBush');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A vector source in one of the supported formats, using a custom function to
|
||||
* read in the data from a remote server.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.FormatVector}
|
||||
* @param {olx.source.ServerVectorOptions} options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.source.ServerVector = function(options) {
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
format: options.format,
|
||||
logo: options.logo,
|
||||
projection: options.projection
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.structs.RBush.<{extent: ol.Extent}>}
|
||||
*/
|
||||
this.loadedExtents_ = new ol.structs.RBush();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function(this: ol.source.ServerVector, ol.Extent, number,
|
||||
* ol.proj.Projection)}
|
||||
*/
|
||||
this.loader_ = options.loader;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function(ol.Extent, number): Array.<ol.Extent>}
|
||||
*/
|
||||
this.strategy_ = goog.isDef(options.strategy) ?
|
||||
options.strategy : ol.loadingstrategy.bbox;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<number|string, boolean>}
|
||||
*/
|
||||
this.loadedFeatures_ = {};
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.ServerVector, ol.source.FormatVector);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.ServerVector.prototype.addFeaturesInternal = function(features) {
|
||||
/** @type {Array.<ol.Feature>} */
|
||||
var notLoadedFeatures = [];
|
||||
var i, ii;
|
||||
for (i = 0, ii = features.length; i < ii; ++i) {
|
||||
var feature = features[i];
|
||||
var featureId = feature.getId();
|
||||
if (!goog.isDef(featureId)) {
|
||||
notLoadedFeatures.push(feature);
|
||||
} else if (!(featureId in this.loadedFeatures_)) {
|
||||
notLoadedFeatures.push(feature);
|
||||
this.loadedFeatures_[featureId] = true;
|
||||
}
|
||||
}
|
||||
goog.base(this, 'addFeaturesInternal', notLoadedFeatures);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api stable
|
||||
*/
|
||||
ol.source.ServerVector.prototype.clear = function(opt_fast) {
|
||||
goog.object.clear(this.loadedFeatures_);
|
||||
this.loadedExtents_.clear();
|
||||
goog.base(this, 'clear', opt_fast);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.ServerVector.prototype.loadFeatures =
|
||||
function(extent, resolution, projection) {
|
||||
var loadedExtents = this.loadedExtents_;
|
||||
var extentsToLoad = this.strategy_(extent, resolution);
|
||||
var i, ii;
|
||||
for (i = 0, ii = extentsToLoad.length; i < ii; ++i) {
|
||||
var extentToLoad = extentsToLoad[i];
|
||||
var alreadyLoaded = loadedExtents.forEachInExtent(extentToLoad,
|
||||
/**
|
||||
* @param {{extent: ol.Extent}} object Object.
|
||||
* @return {boolean} Contains.
|
||||
*/
|
||||
function(object) {
|
||||
return ol.extent.containsExtent(object.extent, extentToLoad);
|
||||
});
|
||||
if (!alreadyLoaded) {
|
||||
this.loader_.call(this, extentToLoad, resolution, projection);
|
||||
loadedExtents.insert(extentToLoad, {extent: extentToLoad.slice()});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @function
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @return {Array.<ol.Feature>} Features.
|
||||
* @api
|
||||
*/
|
||||
ol.source.ServerVector.prototype.readFeatures;
|
||||
@@ -1,83 +0,0 @@
|
||||
goog.provide('ol.source.StaticVector');
|
||||
|
||||
goog.require('ol.source.FormatVector');
|
||||
goog.require('ol.source.State');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A vector source that uses one of the supported formats to read the data from
|
||||
* a file or other static source.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.FormatVector}
|
||||
* @fires ol.source.VectorEvent
|
||||
* @param {olx.source.StaticVectorOptions} options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.source.StaticVector = function(options) {
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
format: options.format,
|
||||
logo: options.logo,
|
||||
projection: options.projection
|
||||
});
|
||||
|
||||
if (goog.isDef(options.arrayBuffer)) {
|
||||
this.addFeaturesInternal(this.readFeatures(options.arrayBuffer));
|
||||
}
|
||||
|
||||
if (goog.isDef(options.doc)) {
|
||||
this.addFeaturesInternal(this.readFeatures(options.doc));
|
||||
}
|
||||
|
||||
if (goog.isDef(options.node)) {
|
||||
this.addFeaturesInternal(this.readFeatures(options.node));
|
||||
}
|
||||
|
||||
if (goog.isDef(options.object)) {
|
||||
this.addFeaturesInternal(this.readFeatures(options.object));
|
||||
}
|
||||
|
||||
if (goog.isDef(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.onFeaturesLoadedSuccess_, this.onFeaturesLoadedError_, 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.onFeaturesLoadedSuccess_, this.onFeaturesLoadedError_, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.StaticVector, ol.source.FormatVector);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.source.StaticVector.prototype.onFeaturesLoadedError_ = function() {
|
||||
this.setState(ol.source.State.ERROR);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.Feature>} features Features.
|
||||
* @private
|
||||
*/
|
||||
ol.source.StaticVector.prototype.onFeaturesLoadedSuccess_ = function(features) {
|
||||
this.addFeaturesInternal(features);
|
||||
this.setState(ol.source.State.READY);
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
goog.provide('ol.source.TopoJSON');
|
||||
|
||||
goog.require('ol.format.TopoJSON');
|
||||
goog.require('ol.source.StaticVector');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Static vector source in TopoJSON format
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.StaticVector}
|
||||
* @fires ol.source.VectorEvent
|
||||
* @param {olx.source.TopoJSONOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.source.TopoJSON = function(opt_options) {
|
||||
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
extent: options.extent,
|
||||
format: new ol.format.TopoJSON({
|
||||
defaultDataProjection: options.defaultProjection
|
||||
}),
|
||||
logo: options.logo,
|
||||
object: options.object,
|
||||
projection: options.projection,
|
||||
text: options.text,
|
||||
url: options.url
|
||||
});
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.TopoJSON, ol.source.StaticVector);
|
||||
Reference in New Issue
Block a user