Merge pull request #880 from openlayers/parser-projection
Get source projection from parser
This commit is contained in:
@@ -16,7 +16,7 @@ var raster = new ol.layer.TileLayer({
|
||||
|
||||
var vector = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
parser: new ol.parser.ogc.GML_v3({axisOrientation: 'neu'}),
|
||||
parser: new ol.parser.ogc.GML_v3(),
|
||||
url: 'data/gml/topp-states-wfs.xml'
|
||||
}),
|
||||
style: new ol.style.Style({rules: [
|
||||
|
||||
@@ -354,10 +354,19 @@
|
||||
* parse.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.GMLReadOptions
|
||||
* @property {string|undefined} axisOrientation The axis orientation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.GMLWriteOptions
|
||||
* @property {ol.ProjectionLike} srsName The srsName to use when writing.
|
||||
* @property {string|undefined} axisOrientation The axis orientation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.GMLOptions
|
||||
* @property {string|undefined} axisOrientation The axis orientation as
|
||||
* specified in Proj4. The default is 'enu'.
|
||||
* @property {boolean|undefined} curve Write gml:Curve instead of
|
||||
* gml:LineString elements. This also affects the elements in multi-part
|
||||
* geometries. Default is `false´. This only applies to GML version 3.
|
||||
@@ -378,13 +387,13 @@
|
||||
* default is `true´. This only applies to GML version 3.
|
||||
* @property {string|undefined} schemaLocation Optional schemaLocation to use
|
||||
* when writing out the GML, this will override the default provided.
|
||||
* @property {string|undefined} srsName URI for spatial reference system.
|
||||
* This is optional for single part geometries and mandatory for
|
||||
* collections and multis. If set, the srsName attribute will be written
|
||||
* for all geometries. Default is null.
|
||||
* @property {boolean|undefined} surface Write gml:Surface instead of
|
||||
* gml:Polygon elements. This also affects the elements in multi-part
|
||||
* geometries. Default is `false´. This only applies to GML version 3.
|
||||
* @property {ol.parser.GMLReadOptions|undefined} readOptions readOptions to
|
||||
* use for this instance.
|
||||
* @property {ol.parser.GMLWriteOptions|undefined} writeOptions writeOptions
|
||||
* to use for this instance.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -516,9 +525,10 @@
|
||||
* @property {string|undefined} logo Logo.
|
||||
* @property {ol.parser.Parser} parser Parser instance to parse data
|
||||
* provided as `data` or fetched from `url`.
|
||||
* @property {ol.ProjectionLike|undefined} projection Projection. EPSG:4326
|
||||
* is assumed if not defined. TODO: Get projection from the parser instead
|
||||
* of assuming EPSG:4326.
|
||||
* @property {ol.ProjectionLike|undefined} projection Projection. Usually the
|
||||
* projection is provided by the parser, so this only needs to be set if
|
||||
* the parser does not know the SRS (e.g. in some GML flavors), or if the
|
||||
* projection determined by the parser needs to be overridden.
|
||||
* @property {string|undefined} url Server url providing the vector data.
|
||||
*/
|
||||
|
||||
|
||||
@@ -423,8 +423,6 @@ ol.layer.Vector.prototype.groupFeaturesBySymbolizerLiteral =
|
||||
* one projection.
|
||||
*/
|
||||
ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
|
||||
var features;
|
||||
|
||||
var lookup = {};
|
||||
lookup[ol.geom.GeometryType.POINT] = this.pointVertices_;
|
||||
lookup[ol.geom.GeometryType.LINESTRING] = this.lineVertices_;
|
||||
@@ -437,8 +435,12 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
|
||||
return lookup[type];
|
||||
};
|
||||
|
||||
var addFeatures = function(features) {
|
||||
var addFeatures = function(data) {
|
||||
var features = data.features;
|
||||
var sourceProjection = this.getSource().getProjection();
|
||||
if (goog.isNull(sourceProjection)) {
|
||||
sourceProjection = data.metadata.projection;
|
||||
}
|
||||
var transform = ol.proj.getTransform(sourceProjection, projection);
|
||||
|
||||
transform(
|
||||
@@ -459,26 +461,28 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
|
||||
this.addFeatures(features);
|
||||
};
|
||||
|
||||
var options = {callback: callback};
|
||||
var options = {callback: callback}, result;
|
||||
if (goog.isString(data)) {
|
||||
if (goog.isFunction(parser.readFeaturesFromStringAsync)) {
|
||||
parser.readFeaturesFromStringAsync(data, goog.bind(addFeatures, this),
|
||||
options);
|
||||
} else {
|
||||
goog.asserts.assert(goog.isFunction(parser.readFeaturesFromString),
|
||||
'Expected a parser with readFeaturesFromString method.');
|
||||
features = parser.readFeaturesFromString(data, options);
|
||||
addFeatures.call(this, features);
|
||||
goog.asserts.assert(
|
||||
goog.isFunction(parser.readFeaturesFromString),
|
||||
'Expected parser with a readFeaturesFromString method.');
|
||||
result = parser.readFeaturesFromString(data, options);
|
||||
addFeatures.call(this, result);
|
||||
}
|
||||
} else if (goog.isObject(data)) {
|
||||
if (goog.isFunction(parser.readFeaturesFromObjectAsync)) {
|
||||
parser.readFeaturesFromObjectAsync(data, goog.bind(addFeatures, this),
|
||||
options);
|
||||
} else {
|
||||
goog.asserts.assert(goog.isFunction(parser.readFeaturesFromObject),
|
||||
'Expected a parser with a readFeaturesFromObject method.');
|
||||
features = parser.readFeaturesFromObject(data, options);
|
||||
addFeatures.call(this, features);
|
||||
goog.asserts.assert(
|
||||
goog.isFunction(parser.readFeaturesFromObject),
|
||||
'Expected parser with a readFeaturesFromObject method.');
|
||||
result = parser.readFeaturesFromObject(data, options);
|
||||
addFeatures.call(this, result);
|
||||
}
|
||||
} else {
|
||||
// TODO: parse more data types
|
||||
|
||||
@@ -18,7 +18,7 @@ ol.parser.DomFeatureParser = function() {};
|
||||
/**
|
||||
* @param {Element|Document} node Document or element node.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.DomFeatureParser.prototype.readFeaturesFromNode =
|
||||
goog.abstractMethod;
|
||||
@@ -34,7 +34,7 @@ ol.parser.ObjectFeatureParser = function() {};
|
||||
/**
|
||||
* @param {Object} obj Object representing features.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.ObjectFeatureParser.prototype.readFeaturesFromObject =
|
||||
goog.abstractMethod;
|
||||
@@ -50,7 +50,7 @@ ol.parser.StringFeatureParser = function() {};
|
||||
/**
|
||||
* @param {string} data String data.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.StringFeatureParser.prototype.readFeaturesFromString =
|
||||
goog.abstractMethod;
|
||||
@@ -65,8 +65,8 @@ ol.parser.AsyncStringFeatureParser = function() {};
|
||||
|
||||
/**
|
||||
* @param {string} data String data.
|
||||
* @param {function(Array.<ol.Feature>)} callback Callback which is called
|
||||
* after parsing.
|
||||
* @param {function(ol.parser.ReadFeaturesResult)} callback Callback which is
|
||||
* called after parsing.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
*/
|
||||
ol.parser.AsyncStringFeatureParser.prototype.readFeaturesFromStringAsync =
|
||||
@@ -82,8 +82,8 @@ ol.parser.AsyncObjectFeatureParser = function() {};
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object representing features.
|
||||
* @param {function(Array.<ol.Feature>)} callback Callback which is called
|
||||
* after parsing.
|
||||
* @param {function(ol.parser.ReadFeaturesResult)} callback Callback which is
|
||||
* called after parsing.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
*/
|
||||
ol.parser.AsyncObjectFeatureParser.prototype.readFeaturesFromObjectAsync =
|
||||
@@ -96,7 +96,20 @@ ol.parser.AsyncObjectFeatureParser.prototype.readFeaturesFromObjectAsync =
|
||||
ol.parser.ReadFeaturesCallback;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{projection: ol.ProjectionLike}}
|
||||
*/
|
||||
ol.parser.ReadFeaturesMetadata;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{callback: ol.parser.ReadFeaturesCallback}}
|
||||
*/
|
||||
ol.parser.ReadFeaturesOptions;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{features: Array.<ol.Feature>,
|
||||
* metadata: ol.parser.ReadFeaturesMetadata}}
|
||||
*/
|
||||
ol.parser.ReadFeaturesResult;
|
||||
|
||||
@@ -58,12 +58,13 @@ ol.parser.GeoJSON.read = function(str) {
|
||||
* Parse a GeoJSON feature collection.
|
||||
* @param {string} str GeoJSON feature collection.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.readFeaturesFromString =
|
||||
function(str, opt_options) {
|
||||
var json = /** @type {GeoJSONFeatureCollection} */ (JSON.parse(str));
|
||||
return this.parseFeatureCollection_(json, opt_options);
|
||||
return {features: this.parseFeatureCollection_(json, opt_options),
|
||||
metadata: {projection: 'EPSG:4326'}};
|
||||
};
|
||||
|
||||
|
||||
@@ -72,11 +73,12 @@ ol.parser.GeoJSON.prototype.readFeaturesFromString =
|
||||
* @param {GeoJSONFeatureCollection} object GeoJSON feature collection decoded
|
||||
* from JSON.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.readFeaturesFromObject =
|
||||
function(object, opt_options) {
|
||||
return this.parseFeatureCollection_(object, opt_options);
|
||||
return {features: this.parseFeatureCollection_(object, opt_options),
|
||||
metadata: {projection: 'EPSG:4326'}};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ goog.inherits(ol.parser.GPX, ol.parser.XML);
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element|Object} data Data to read.
|
||||
* @return {Object} An object representing the document.
|
||||
* @return {ol.parser.ReadFeaturesResult} An object representing the document.
|
||||
*/
|
||||
ol.parser.GPX.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
@@ -243,7 +243,8 @@ ol.parser.GPX.prototype.read = function(data) {
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {};
|
||||
var obj = /** @type {ol.parser.ReadFeaturesResult} */
|
||||
({metadata: {projection: 'EPSG:4326'}});
|
||||
this.readNode(data, obj);
|
||||
return obj;
|
||||
};
|
||||
@@ -253,12 +254,12 @@ ol.parser.GPX.prototype.read = function(data) {
|
||||
* Parse a GPX document provided as a string.
|
||||
* @param {string} str GPX document.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GPX.prototype.readFeaturesFromString =
|
||||
function(str, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(str).features;
|
||||
return this.read(str);
|
||||
};
|
||||
|
||||
|
||||
@@ -266,24 +267,24 @@ ol.parser.GPX.prototype.readFeaturesFromString =
|
||||
* Parse a GPX document provided as a DOM structure.
|
||||
* @param {Element|Document} node Document or element node.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GPX.prototype.readFeaturesFromNode =
|
||||
function(node, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(node).features;
|
||||
return this.read(node);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object representing features.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GPX.prototype.readFeaturesFromObject =
|
||||
function(obj, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(obj).features;
|
||||
return this.read(obj);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -821,8 +821,8 @@ goog.inherits(ol.parser.KML, ol.parser.XML);
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object representing features.
|
||||
* @param {function(Array.<ol.Feature>)} callback Callback which is called
|
||||
* after parsing.
|
||||
* @param {function(ol.parser.ReadFeaturesResult)} callback Callback which is
|
||||
* called after parsing.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
*/
|
||||
ol.parser.KML.prototype.readFeaturesFromObjectAsync =
|
||||
@@ -833,9 +833,9 @@ ol.parser.KML.prototype.readFeaturesFromObjectAsync =
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str KML document.
|
||||
* @param {function(Array.<ol.Feature>)} callback Callback which is called
|
||||
* after parsing.
|
||||
* @param {string} str String data.
|
||||
* @param {function(ol.parser.ReadFeaturesResult)}
|
||||
* callback Callback which is called after parsing.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
*/
|
||||
ol.parser.KML.prototype.readFeaturesFromStringAsync =
|
||||
@@ -849,12 +849,12 @@ ol.parser.KML.prototype.readFeaturesFromStringAsync =
|
||||
* Parse a KML document provided as a string.
|
||||
* @param {string} str KML document.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.KML.prototype.readFeaturesFromString =
|
||||
function(str, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(str).features;
|
||||
return /** @type {ol.parser.ReadFeaturesResult} */ (this.read(str));
|
||||
};
|
||||
|
||||
|
||||
@@ -862,24 +862,24 @@ ol.parser.KML.prototype.readFeaturesFromString =
|
||||
* Parse a KML document provided as a DOM structure.
|
||||
* @param {Element|Document} node Document or element node.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.KML.prototype.readFeaturesFromNode =
|
||||
function(node, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(node).features;
|
||||
return /** @type {ol.parser.ReadFeaturesResult} */ (this.read(node));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object representing features.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.KML.prototype.readFeaturesFromObject =
|
||||
function(obj, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(obj).features;
|
||||
return /** @type {ol.parser.ReadFeaturesResult} */ (this.read(obj));
|
||||
};
|
||||
|
||||
|
||||
@@ -930,9 +930,11 @@ ol.parser.KML.prototype.parseLinks = function(deferreds, obj, done) {
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element|Object} data Data to read.
|
||||
* @param {Function=} opt_callback Optional callback to call when reading
|
||||
* is done.
|
||||
* @return {Object} An object representing the document.
|
||||
* @param {function(ol.parser.ReadFeaturesResult)=} opt_callback Optional
|
||||
* callback to call when reading is done. If provided, this method will
|
||||
* return undefined.
|
||||
* @return {ol.parser.ReadFeaturesResult|undefined} An object representing the
|
||||
* document if `opt_callback` was not provided.
|
||||
*/
|
||||
ol.parser.KML.prototype.read = function(data, opt_callback) {
|
||||
if (goog.isString(data)) {
|
||||
@@ -941,7 +943,8 @@ ol.parser.KML.prototype.read = function(data, opt_callback) {
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {};
|
||||
var obj = /** @type {ol.parser.ReadFeaturesResult} */
|
||||
({metadata: {projection: 'EPSG:4326'}});
|
||||
this.readNode(data, obj);
|
||||
if (goog.isDef(opt_callback)) {
|
||||
var deferreds = [];
|
||||
@@ -955,7 +958,7 @@ ol.parser.KML.prototype.read = function(data, opt_callback) {
|
||||
var feature = obj.features[i];
|
||||
this.applyStyle_(feature, obj['styles']);
|
||||
}
|
||||
opt_callback.call(null, obj.features);
|
||||
opt_callback.call(null, obj);
|
||||
}, function() {
|
||||
throw new Error('KML: parsing of NetworkLinks failed');
|
||||
}, this);
|
||||
@@ -963,7 +966,6 @@ ol.parser.KML.prototype.read = function(data, opt_callback) {
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.parser.ogc.GML');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Geometry');
|
||||
@@ -14,6 +15,7 @@ goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
goog.require('ol.parser.XML');
|
||||
goog.require('ol.proj');
|
||||
|
||||
|
||||
|
||||
@@ -27,8 +29,6 @@ goog.require('ol.parser.XML');
|
||||
ol.parser.ogc.GML = function(opt_options) {
|
||||
var options = /** @type {ol.parser.GMLOptions} */
|
||||
(goog.isDef(opt_options) ? opt_options : {});
|
||||
this.axisOrientation = goog.isDef(options.axisOrientation) ?
|
||||
options.axisOrientation : 'enu';
|
||||
this.extractAttributes = goog.isDef(options.extractAttributes) ?
|
||||
options.extractAttributes : true;
|
||||
this.surface = goog.isDef(options.surface) ?
|
||||
@@ -39,8 +39,21 @@ ol.parser.ogc.GML = function(opt_options) {
|
||||
options.multiCurve : true;
|
||||
this.multiSurface = goog.isDef(options.multiSurface) ?
|
||||
options.multiSurface : true;
|
||||
this.srsName = goog.isDef(options.srsName) ?
|
||||
options.srsName : null;
|
||||
this.readOptions = options.readOptions;
|
||||
this.writeOptions = options.writeOptions;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.srsName;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.axisOrientation;
|
||||
|
||||
if (goog.isDef(options.schemaLocation)) {
|
||||
this.schemaLocation = options.schemaLocation;
|
||||
}
|
||||
@@ -61,7 +74,18 @@ ol.parser.ogc.GML = function(opt_options) {
|
||||
},
|
||||
'http://www.opengis.net/gml': {
|
||||
'_inherit': function(node, obj, container) {
|
||||
// To be implemented by version specific parsers
|
||||
// Version specific parsers extend this with goog.functions.sequence
|
||||
var srsName;
|
||||
if (!goog.isDef(this.srsName)) {
|
||||
srsName = this.srsName = node.getAttribute('srsName');
|
||||
}
|
||||
if (!goog.isDef(this.axisOrientation)) {
|
||||
if (goog.isDefAndNotNull(srsName)) {
|
||||
this.axisOrientation = ol.proj.get(srsName).getAxisOrientation();
|
||||
} else {
|
||||
this.axisOrientation = 'enu';
|
||||
}
|
||||
}
|
||||
},
|
||||
'name': function(node, obj) {
|
||||
obj.name = this.getChildValue(node);
|
||||
@@ -126,6 +150,8 @@ ol.parser.ogc.GML = function(opt_options) {
|
||||
},
|
||||
'Point': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
var point = {
|
||||
type: ol.geom.GeometryType.POINT,
|
||||
@@ -315,9 +341,9 @@ ol.parser.ogc.GML = function(opt_options) {
|
||||
}
|
||||
this.writers = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'featureMember': function(feature) {
|
||||
'featureMember': function(obj) {
|
||||
var node = this.createElementNS('gml:featureMember');
|
||||
this.writeNode('_typeName', feature, this.featureNS, node);
|
||||
this.writeNode('_typeName', obj, this.featureNS, node);
|
||||
return node;
|
||||
},
|
||||
'MultiPoint': function(geometry) {
|
||||
@@ -455,17 +481,38 @@ goog.inherits(ol.parser.ogc.GML, ol.parser.XML);
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element|Object} data Data to read.
|
||||
* @return {Object} An object representing the document.
|
||||
* @param {ol.parser.GMLReadOptions=} opt_options Read options.
|
||||
* @return {ol.parser.ReadFeaturesResult} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.read = function(data) {
|
||||
ol.parser.ogc.GML.prototype.read = function(data, opt_options) {
|
||||
var srsName;
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) {
|
||||
srsName = opt_options.srsName;
|
||||
} else if (goog.isDef(this.readOptions) &&
|
||||
goog.isDef(this.readOptions.srsName)) {
|
||||
srsName = this.readOptions.srsName;
|
||||
}
|
||||
if (goog.isDef(srsName)) {
|
||||
this.srsName = goog.isString(srsName) ? srsName : srsName.getCode();
|
||||
}
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) {
|
||||
this.axisOrientation = opt_options.axisOrientation;
|
||||
} else if (goog.isDef(this.readOptions) &&
|
||||
goog.isDef(this.readOptions.axisOrientation)) {
|
||||
this.axisOrientation = this.readOptions.axisOrientation;
|
||||
}
|
||||
if (typeof data == 'string') {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {features: []};
|
||||
var obj = /** @type {ol.parser.ReadFeaturesResult} */
|
||||
({features: [], metadata: {}});
|
||||
this.readNode(data, obj, true);
|
||||
obj.metadata.projection = this.srsName;
|
||||
delete this.srsName;
|
||||
delete this.axisOrientation;
|
||||
return obj;
|
||||
};
|
||||
|
||||
@@ -570,10 +617,41 @@ ol.parser.ogc.GML.prototype.createGeometry_ = function(container,
|
||||
* Parse a GML document provided as a string.
|
||||
* @param {string} str GML document.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.readFeaturesFromString =
|
||||
function(str, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(str).features;
|
||||
return this.read(str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Applies the writeOptions passed into the write function.
|
||||
* @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as
|
||||
* GML.
|
||||
* @param {ol.parser.GMLWriteOptions=} opt_options Write options.
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.applyWriteOptions = function(obj, opt_options) {
|
||||
// srsName handling: opt_options -> this.writeOptions -> obj.metadata
|
||||
var srsName;
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) {
|
||||
srsName = opt_options.srsName;
|
||||
} else if (goog.isDef(this.writeOptions) &&
|
||||
goog.isDef(this.writeOptions.srsName)) {
|
||||
srsName = this.writeOptions.srsName;
|
||||
} else if (goog.isDef(obj.metadata)) {
|
||||
srsName = obj.metadata.projection;
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(srsName), 'srsName required for writing GML');
|
||||
this.srsName = goog.isString(srsName) ? srsName : srsName.getCode();
|
||||
// axisOrientation handling: opt_options -> this.writeOptions
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) {
|
||||
this.axisOrientation = opt_options.axisOrientation;
|
||||
} else if (goog.isDef(this.writeOptions) &&
|
||||
goog.isDef(this.writeOptions.axisOrientation)) {
|
||||
this.axisOrientation = this.writeOptions.axisOrientation;
|
||||
} else {
|
||||
this.axisOrientation = ol.proj.get(this.srsName).getAxisOrientation();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,6 +28,8 @@ ol.parser.ogc.GML_v2 = function(opt_options) {
|
||||
},
|
||||
'Box': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.bounds = [coordinates[0][0][0], coordinates[0][1][0],
|
||||
coordinates[0][0][1], coordinates[0][1][1]];
|
||||
@@ -112,14 +114,20 @@ goog.inherits(ol.parser.ogc.GML_v2, ol.parser.ogc.GML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object structure to write out as XML.
|
||||
* @return {string} An string representing the XML document.
|
||||
* @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as
|
||||
* GML.
|
||||
* @param {ol.parser.GMLWriteOptions=} opt_options Write options.
|
||||
* @return {string} A string representing the GML document.
|
||||
*/
|
||||
ol.parser.ogc.GML_v2.prototype.write = function(obj) {
|
||||
ol.parser.ogc.GML_v2.prototype.write = function(obj, opt_options) {
|
||||
this.applyWriteOptions(obj, opt_options);
|
||||
var root = this.writeNode('FeatureCollection', obj.features,
|
||||
'http://www.opengis.net/wfs');
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
return this.serialize(root);
|
||||
var gml = this.serialize(root);
|
||||
delete this.srsName;
|
||||
delete this.axisOrientation;
|
||||
return gml;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
goog.provide('ol.parser.ogc.GML_v3');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.parser.ogc.GML');
|
||||
@@ -61,14 +62,16 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
|
||||
return node;
|
||||
};
|
||||
goog.object.extend(this.readers['http://www.opengis.net/gml'], {
|
||||
'_inherit': function(node, obj, container) {
|
||||
// SRSReferenceGroup attributes
|
||||
var dim = parseInt(node.getAttribute('srsDimension'), 10) ||
|
||||
(container && container.srsDimension);
|
||||
if (dim) {
|
||||
obj.srsDimension = dim;
|
||||
}
|
||||
},
|
||||
'_inherit': goog.functions.sequence(
|
||||
this.readers['http://www.opengis.net/gml']['_inherit'],
|
||||
function(node, obj, container) {
|
||||
// SRSReferenceGroup attributes
|
||||
var dim = parseInt(node.getAttribute('srsDimension'), 10) ||
|
||||
(container && container.srsDimension);
|
||||
if (dim) {
|
||||
obj.srsDimension = dim;
|
||||
}
|
||||
}),
|
||||
'featureMembers': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
@@ -205,6 +208,8 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
|
||||
},
|
||||
'Envelope': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.bounds = [coordinates[0][0][0][0], coordinates[1][0][0][0],
|
||||
coordinates[0][0][0][1], coordinates[1][0][0][1]];
|
||||
@@ -373,7 +378,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
|
||||
this.writeNode('lowerCorner', bounds, null, node);
|
||||
this.writeNode('upperCorner', bounds, null, node);
|
||||
// srsName attribute is required for gml:Envelope
|
||||
if (this.srsName) {
|
||||
if (goog.isDef(this.srsName)) {
|
||||
node.setAttribute('srsName', this.srsName);
|
||||
}
|
||||
return node;
|
||||
@@ -408,13 +413,19 @@ goog.inherits(ol.parser.ogc.GML_v3, ol.parser.ogc.GML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object structure to write out as XML.
|
||||
* @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as
|
||||
* XML.
|
||||
* @param {ol.parser.GMLWriteOptions=} opt_options Write options.
|
||||
* @return {string} An string representing the XML document.
|
||||
*/
|
||||
ol.parser.ogc.GML_v3.prototype.write = function(obj) {
|
||||
ol.parser.ogc.GML_v3.prototype.write = function(obj, opt_options) {
|
||||
this.applyWriteOptions(obj, opt_options);
|
||||
var root = this.writeNode('featureMembers', obj.features);
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
return this.serialize(root);
|
||||
var gml = this.serialize(root);
|
||||
delete this.srsName;
|
||||
delete this.axisOrientation;
|
||||
return gml;
|
||||
};
|
||||
|
||||
@@ -74,7 +74,7 @@ ol.parser.TopoJSON.prototype.concatenateArcs_ = function(indices, arcs) {
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.read = function(str) {
|
||||
var topology = /** @type {TopoJSONTopology} */ (JSON.parse(str));
|
||||
return this.readFeaturesFromObject(topology);
|
||||
return this.readFeaturesFromObject(topology).features;
|
||||
};
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ ol.parser.TopoJSON.prototype.read = function(str) {
|
||||
*
|
||||
* @param {string} str TopoJSON topology string.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readFeaturesFromString =
|
||||
function(str, opt_options) {
|
||||
@@ -91,7 +91,8 @@ ol.parser.TopoJSON.prototype.readFeaturesFromString =
|
||||
if (topology.type !== 'Topology') {
|
||||
throw new Error('Not a "Topology" type object');
|
||||
}
|
||||
return this.readFeaturesFromTopology_(topology, opt_options);
|
||||
return {features: this.readFeaturesFromTopology_(topology, opt_options),
|
||||
metadata: {projection: 'EPSG:4326'}};
|
||||
};
|
||||
|
||||
|
||||
@@ -100,14 +101,15 @@ ol.parser.TopoJSON.prototype.readFeaturesFromString =
|
||||
*
|
||||
* @param {TopoJSONTopology} topology TopoJSON topology object.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readFeaturesFromObject =
|
||||
function(topology, opt_options) {
|
||||
if (topology.type !== 'Topology') {
|
||||
throw new Error('Not a "Topology" type object');
|
||||
}
|
||||
return this.readFeaturesFromTopology_(topology, opt_options);
|
||||
return {features: this.readFeaturesFromTopology_(topology, opt_options),
|
||||
metadata: {projection: 'EPSG:4326'}};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,9 @@ ol.proj.EPSG4326.PROJECTIONS = [
|
||||
new ol.proj.EPSG4326('EPSG:4326', 'neu'),
|
||||
new ol.proj.EPSG4326('urn:ogc:def:crs:EPSG:6.6:4326', 'neu'),
|
||||
new ol.proj.EPSG4326('urn:ogc:def:crs:OGC:1.3:CRS84'),
|
||||
new ol.proj.EPSG4326('urn:ogc:def:crs:OGC:2:84')
|
||||
new ol.proj.EPSG4326('urn:ogc:def:crs:OGC:2:84'),
|
||||
new ol.proj.EPSG4326('http://www.opengis.net/gml/srs/epsg.xml#4326', 'neu'),
|
||||
new ol.proj.EPSG4326('urn:x-ogc:def:crs:EPSG:4326', 'neu')
|
||||
];
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ goog.provide('ol.source.Vector');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.net.XhrIo');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.Source');
|
||||
|
||||
|
||||
@@ -53,8 +52,7 @@ ol.source.Vector = function(options) {
|
||||
attributions: options.attributions,
|
||||
extent: options.extent,
|
||||
logo: options.logo,
|
||||
projection: goog.isDef(options.projection) ?
|
||||
options.projection : ol.proj.get('EPSG:4326')
|
||||
projection: options.projection
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.source.Vector, ol.source.Source);
|
||||
|
||||
@@ -237,7 +237,8 @@ describe('ol.parser.GeoJSON', function() {
|
||||
return lookup[type];
|
||||
};
|
||||
|
||||
var result = parser.readFeaturesFromString(text, {callback: callback});
|
||||
var result = parser.readFeaturesFromString(text,
|
||||
{callback: callback}).features;
|
||||
expect(result.length).to.be(179);
|
||||
|
||||
expect(pointVertices.coordinates.length).to.be(0);
|
||||
|
||||
@@ -52,8 +52,8 @@ describe('ol.parser.kml', function() {
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({maxDepth: 1});
|
||||
// we need to supply a callback to get visited NetworkLinks
|
||||
p.read(xml, function(features) {
|
||||
expect(features.length).to.eql(3);
|
||||
p.read(xml, function(obj) {
|
||||
expect(obj.features.length).to.eql(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -63,8 +63,8 @@ describe('ol.parser.kml', function() {
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({maxDepth: 2});
|
||||
// we need to supply a callback to get visited NetworkLinks
|
||||
p.read(xml, function(features) {
|
||||
expect(features.length).to.eql(2);
|
||||
p.read(xml, function(obj) {
|
||||
expect(obj.features.length).to.eql(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -74,9 +74,9 @@ describe('ol.parser.kml', function() {
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({maxDepth: 1});
|
||||
// we need to supply a callback to get visited NetworkLinks
|
||||
p.read(xml, function(features) {
|
||||
p.read(xml, function(obj) {
|
||||
// since maxDepth is 1, we will not get to the second feature
|
||||
expect(features.length).to.eql(1);
|
||||
expect(obj.features.length).to.eql(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,12 +18,13 @@ describe('ol.parser.gml_v2', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/point-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
parser.applyWriteOptions(obj);
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('point');
|
||||
expect(obj.geometry.coordinates).to.eql([1, 2]);
|
||||
done();
|
||||
@@ -46,12 +47,13 @@ describe('ol.parser.gml_v2', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multipoint-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipoint');
|
||||
expect(obj.geometry.parts.length).to.eql(3);
|
||||
expect(obj.geometry.parts[0].type).to.eql('point');
|
||||
@@ -75,12 +77,13 @@ describe('ol.parser.gml_v2', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/linestring-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linestring');
|
||||
expect(obj.geometry.coordinates.length).to.eql(2);
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
@@ -103,12 +106,13 @@ describe('ol.parser.gml_v2', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multilinestring-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('linestring');
|
||||
@@ -137,12 +141,13 @@ describe('ol.parser.gml_v2', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/polygon-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
@@ -161,12 +166,13 @@ describe('ol.parser.gml_v2', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multipolygon-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('polygon');
|
||||
@@ -177,12 +183,14 @@ describe('ol.parser.gml_v2', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/' +
|
||||
'geometrycollection-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v2({srsName: 'foo',
|
||||
featureNS: 'http://foo'});
|
||||
var p = new ol.parser.ogc.GML_v2({featureNS: 'http://foo'});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry_({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('geometrycollection');
|
||||
expect(obj.geometry.parts.length).to.eql(3);
|
||||
@@ -222,12 +230,13 @@ describe('ol.parser.gml_v2', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/linearring-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linearring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4], [5, 6],
|
||||
[1, 2]]);
|
||||
@@ -237,18 +246,19 @@ describe('ol.parser.gml_v2', function() {
|
||||
it('FeatureCollection read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/topp-states.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var srsName = 'http://www.opengis.net/gml/srs/epsg.xml#4326';
|
||||
var schemaLoc = 'http://www.openplans.org/topp ' +
|
||||
'http://demo.opengeo.org/geoserver/wfs?service=WFS&version=' +
|
||||
'1.0.0&request=DescribeFeatureType&typeName=topp:states ' +
|
||||
'http://www.opengis.net/wfs http://demo.opengeo.org/' +
|
||||
'geoserver/schemas/wfs/1.0.0/WFS-basic.xsd';
|
||||
var p = new ol.parser.ogc.GML_v2({srsName: srsName,
|
||||
var p = new ol.parser.ogc.GML_v2({
|
||||
featureType: 'states',
|
||||
featureNS: 'http://www.openplans.org/topp',
|
||||
schemaLocation: schemaLoc});
|
||||
var obj = p.read(xml);
|
||||
var output = p.write(obj);
|
||||
// overwrite the axis orientation of the projection, since WFS 1.0.0
|
||||
// always uses enu
|
||||
var obj = p.read(xml, {axisOrientation: 'enu'});
|
||||
var output = p.write(obj, {axisOrientation: 'enu'});
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
expect(obj.features.length).to.eql(3);
|
||||
var feature = obj.features[0];
|
||||
@@ -261,6 +271,8 @@ describe('ol.parser.gml_v2', function() {
|
||||
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
||||
expect(attributes['STATE_ABBR']).to.eql('IL');
|
||||
expect(attributes['LAND_KM']).to.eql('143986.61');
|
||||
expect(ol.proj.get(obj.metadata.projection) instanceof ol.proj.EPSG4326)
|
||||
.to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -326,3 +338,5 @@ goog.require('ol.parser.ogc.GML_v2');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.proj.EPSG4326');
|
||||
|
||||
@@ -18,10 +18,11 @@ describe('ol.parser.gml_v3', function() {
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.srsName = 'foo';
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linearring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4], [5, 6],
|
||||
@@ -34,10 +35,11 @@ describe('ol.parser.gml_v3', function() {
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.srsName = 'foo';
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linestring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
@@ -57,11 +59,14 @@ describe('ol.parser.gml_v3', function() {
|
||||
it('Curve read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/curve.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({curve: true, srsName: 'foo'});
|
||||
var p = new ol.parser.ogc.GML_v3({curve: true});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry_({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linestring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
@@ -82,11 +87,14 @@ describe('ol.parser.gml_v3', function() {
|
||||
it('MultiLineString singular read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multilinestring-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({multiCurve: false, srsName: 'foo'});
|
||||
var p = new ol.parser.ogc.GML_v3({multiCurve: false});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry_({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
@@ -98,12 +106,13 @@ describe('ol.parser.gml_v3', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multicurve-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('linestring');
|
||||
@@ -114,11 +123,14 @@ describe('ol.parser.gml_v3', function() {
|
||||
it('MultiCurve curve read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multicurve-curve.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({curve: true, srsName: 'foo'});
|
||||
var p = new ol.parser.ogc.GML_v3({curve: true});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry_({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
@@ -142,12 +154,13 @@ describe('ol.parser.gml_v3', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multipoint-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipoint');
|
||||
expect(obj.geometry.parts.length).to.eql(3);
|
||||
expect(obj.geometry.parts[0].type).to.eql('point');
|
||||
@@ -168,11 +181,14 @@ describe('ol.parser.gml_v3', function() {
|
||||
it('MultiPolygon singular read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multipolygon-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({multiSurface: false, srsName: 'foo'});
|
||||
var p = new ol.parser.ogc.GML_v3({multiSurface: false});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry_({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
@@ -194,12 +210,13 @@ describe('ol.parser.gml_v3', function() {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multisurface-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.srsName = 'foo';
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('polygon');
|
||||
@@ -209,11 +226,14 @@ describe('ol.parser.gml_v3', function() {
|
||||
it('MultiSurface surface read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multisurface-surface.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({surface: true, srsName: 'foo'});
|
||||
var p = new ol.parser.ogc.GML_v3({surface: true});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry_({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
@@ -226,10 +246,11 @@ describe('ol.parser.gml_v3', function() {
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.srsName = 'foo';
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('point');
|
||||
expect(obj.geometry.coordinates).to.eql([1, 2]);
|
||||
@@ -241,10 +262,11 @@ describe('ol.parser.gml_v3', function() {
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry_({geometry: obj.geometry});
|
||||
parser.srsName = 'foo';
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
done();
|
||||
@@ -253,11 +275,14 @@ describe('ol.parser.gml_v3', function() {
|
||||
it('Surface read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/surface.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({surface: true, srsName: 'foo'});
|
||||
var p = new ol.parser.ogc.GML_v3({surface: true});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry_({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj, {srsName: 'foo'});
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
done();
|
||||
@@ -266,14 +291,12 @@ describe('ol.parser.gml_v3', function() {
|
||||
it('FeatureCollection from GML read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/topp-states-gml.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var srsName = 'urn:x-ogc:def:crs:EPSG:4326';
|
||||
var schemaLoc = 'http://www.openplans.org/topp ' +
|
||||
'http://demo.opengeo.org/geoserver/wfs?service=WFS&version=' +
|
||||
'1.1.0&request=DescribeFeatureType&typeName=topp:states ' +
|
||||
'http://www.opengis.net/gml ' +
|
||||
'http://schemas.opengis.net/gml/3.2.1/gml.xsd';
|
||||
var p = new ol.parser.ogc.GML_v3({srsName: srsName,
|
||||
schemaLocation: schemaLoc});
|
||||
var p = new ol.parser.ogc.GML_v3({schemaLocation: schemaLoc});
|
||||
var obj = p.read(xml);
|
||||
var output = p.write(obj);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
@@ -289,6 +312,8 @@ describe('ol.parser.gml_v3', function() {
|
||||
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
||||
expect(attributes['STATE_ABBR']).to.eql('IL');
|
||||
expect(attributes['LAND_KM']).to.eql('143986.61');
|
||||
expect(ol.proj.get(obj.metadata.projection) instanceof ol.proj.EPSG4326)
|
||||
.to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -307,6 +332,8 @@ describe('ol.parser.gml_v3', function() {
|
||||
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
||||
expect(attributes['STATE_ABBR']).to.eql('IL');
|
||||
expect(attributes['LAND_KM']).to.eql('143986.61');
|
||||
expect(ol.proj.get(obj.metadata.projection) instanceof ol.proj.EPSG4326)
|
||||
.to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -352,3 +379,5 @@ describe('ol.parser.gml_v3', function() {
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.parser.ogc.GML_v3');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.proj.EPSG4326');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="FOO">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -79,13 +79,13 @@ describe('ol.parser.TopoJSON', function() {
|
||||
};
|
||||
|
||||
var result = parser.readFeaturesFromString(text, {callback: callback});
|
||||
expect(result.length).to.be(178);
|
||||
expect(result.features.length).to.be(178);
|
||||
|
||||
expect(pointVertices.coordinates.length).to.be(0);
|
||||
expect(lineVertices.coordinates.length).to.be(0);
|
||||
expect(polygonVertices.coordinates.length).to.be(31400);
|
||||
|
||||
var first = result[0];
|
||||
var first = result.features[0];
|
||||
expect(first).to.be.a(ol.Feature);
|
||||
var firstGeom = first.getGeometry();
|
||||
expect(firstGeom).to.be.a(ol.geom.MultiPolygon);
|
||||
@@ -93,7 +93,7 @@ describe('ol.parser.TopoJSON', function() {
|
||||
-180, 180, -85.60903777459777, 83.64513000000002
|
||||
]);
|
||||
|
||||
var last = result[177];
|
||||
var last = result.features[177];
|
||||
expect(last).to.be.a(ol.Feature);
|
||||
var lastGeom = last.getGeometry();
|
||||
expect(lastGeom).to.be.a(ol.geom.Polygon);
|
||||
|
||||
Reference in New Issue
Block a user