Add AsyncStringFeatureParser and use plain
XMLHttpRequest in the KML example Since the content-type on github.io is application/octet-stream we need to implement an Async string based parser interface in the KML parser. Also use plain XmlHttpRequest in the example instead of jQuery Ajax since the vector-features example also uses that.
This commit is contained in:
@@ -350,10 +350,15 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
|
||||
};
|
||||
|
||||
if (goog.isString(data)) {
|
||||
goog.asserts.assert(goog.isFunction(parser.readFeaturesFromString),
|
||||
'Expected a parser with readFeaturesFromString method.');
|
||||
features = parser.readFeaturesFromString(data, {callback: callback});
|
||||
addFeatures.call(this, features);
|
||||
if (goog.isFunction(parser.readFeaturesFromStringAsync)) {
|
||||
parser.readFeaturesFromStringAsync(data, goog.bind(addFeatures, this),
|
||||
{callback: callback});
|
||||
} else {
|
||||
goog.asserts.assert(goog.isFunction(parser.readFeaturesFromString),
|
||||
'Expected a parser with readFeaturesFromString method.');
|
||||
features = parser.readFeaturesFromString(data, {callback: callback});
|
||||
addFeatures.call(this, features);
|
||||
}
|
||||
} else if (goog.isObject(data)) {
|
||||
if (goog.isFunction(parser.readFeaturesFromObjectAsync)) {
|
||||
parser.readFeaturesFromObjectAsync(data, goog.bind(addFeatures, this),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
goog.provide('ol.parser.AsyncObjectFeatureParser');
|
||||
goog.provide('ol.parser.AsyncStringFeatureParser');
|
||||
goog.provide('ol.parser.DomFeatureParser');
|
||||
goog.provide('ol.parser.ObjectFeatureParser');
|
||||
goog.provide('ol.parser.ReadFeaturesOptions');
|
||||
@@ -56,6 +57,23 @@ ol.parser.StringFeatureParser.prototype.readFeaturesFromString =
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
ol.parser.AsyncStringFeatureParser = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} data String data.
|
||||
* @param {function(Array.<ol.Feature>)} callback Callback which is called
|
||||
* after parsing.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
*/
|
||||
ol.parser.AsyncStringFeatureParser.prototype.readFeaturesFromStringAsync =
|
||||
goog.abstractMethod;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@ goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.geom.SharedVertices');
|
||||
goog.require('ol.parser.AsyncObjectFeatureParser');
|
||||
goog.require('ol.parser.AsyncStringFeatureParser');
|
||||
goog.require('ol.parser.DomFeatureParser');
|
||||
goog.require('ol.parser.ReadFeaturesOptions');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
@@ -47,6 +48,7 @@ ol.parser.KMLOptions;
|
||||
* @implements {ol.parser.DomFeatureParser}
|
||||
* @implements {ol.parser.StringFeatureParser}
|
||||
* @implements {ol.parser.AsyncObjectFeatureParser}
|
||||
* @implements {ol.parser.AsyncStringFeatureParser}
|
||||
* @param {ol.parser.KMLOptions=} opt_options Optional configuration object.
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
@@ -818,6 +820,19 @@ ol.parser.KML.prototype.readFeaturesFromObjectAsync =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str KML document.
|
||||
* @param {function(Array.<ol.Feature>)} callback Callback which is called
|
||||
* after parsing.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
*/
|
||||
ol.parser.KML.prototype.readFeaturesFromStringAsync =
|
||||
function(str, callback, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
this.read(str, callback);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a KML document provided as a string.
|
||||
* @param {string} str KML document.
|
||||
|
||||
Reference in New Issue
Block a user