Merge pull request #2407 from ahocevar/format-projection
Options for feature readers and writers to support transforms
This commit is contained in:
@@ -11,9 +11,7 @@ goog.require('ol.tilegrid.XYZ');
|
|||||||
|
|
||||||
var waterLayer = new ol.layer.Vector({
|
var waterLayer = new ol.layer.Vector({
|
||||||
source: new ol.source.TileVector({
|
source: new ol.source.TileVector({
|
||||||
format: new ol.format.TopoJSON({
|
format: new ol.format.TopoJSON(),
|
||||||
defaultProjection: 'EPSG:4326'
|
|
||||||
}),
|
|
||||||
projection: 'EPSG:3857',
|
projection: 'EPSG:3857',
|
||||||
tileGrid: new ol.tilegrid.XYZ({
|
tileGrid: new ol.tilegrid.XYZ({
|
||||||
maxZoom: 19
|
maxZoom: 19
|
||||||
@@ -31,9 +29,7 @@ var waterLayer = new ol.layer.Vector({
|
|||||||
var roadStyleCache = {};
|
var roadStyleCache = {};
|
||||||
var roadLayer = new ol.layer.Vector({
|
var roadLayer = new ol.layer.Vector({
|
||||||
source: new ol.source.TileVector({
|
source: new ol.source.TileVector({
|
||||||
format: new ol.format.TopoJSON({
|
format: new ol.format.TopoJSON(),
|
||||||
defaultProjection: 'EPSG:4326'
|
|
||||||
}),
|
|
||||||
projection: 'EPSG:3857',
|
projection: 'EPSG:3857',
|
||||||
tileGrid: new ol.tilegrid.XYZ({
|
tileGrid: new ol.tilegrid.XYZ({
|
||||||
maxZoom: 19
|
maxZoom: 19
|
||||||
|
|||||||
@@ -1162,7 +1162,58 @@ olx.control.ZoomToExtentOptions.prototype.extent;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{defaultProjection: ol.proj.ProjectionLike,
|
* @typedef {{dataProjection: (ol.proj.ProjectionLike|undefined),
|
||||||
|
* featureProjection: (ol.proj.ProjectionLike|undefined)}}
|
||||||
|
*/
|
||||||
|
olx.format.ReadOptions;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Projection of the data we are reading. If not provided, the projection will
|
||||||
|
* be derived from the data (where possible) or the `defaultDataProjection` of
|
||||||
|
* the format is assigned (where set). If the projection can not be derived from
|
||||||
|
* the data and if no `defaultDataProjection` is set for a format, the features
|
||||||
|
* will not be reprojected.
|
||||||
|
* @type {ol.proj.ProjectionLike|undefined}
|
||||||
|
*/
|
||||||
|
olx.format.ReadOptions.prototype.dataProjection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Projection of the feature geometries created by the format reader. If not
|
||||||
|
* provided, features will be returned in the `dataProjection`.
|
||||||
|
* @type {ol.proj.ProjectionLike|undefined}
|
||||||
|
*/
|
||||||
|
olx.format.ReadOptions.prototype.featureProjection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{dataProjection: (ol.proj.ProjectionLike|undefined),
|
||||||
|
* featureProjection: ol.proj.ProjectionLike}}
|
||||||
|
*/
|
||||||
|
olx.format.WriteOptions;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Projection of the data we are writing. If not provided, the
|
||||||
|
* `defaultDataProjection` of the format is assigned (where set). If no
|
||||||
|
* `defaultDataProjection` is set for a format, the features will be returned
|
||||||
|
* in the `featureProjection`.
|
||||||
|
* @type {ol.proj.ProjectionLike|undefined}
|
||||||
|
*/
|
||||||
|
olx.format.WriteOptions.prototype.dataProjection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Projection of the feature geometries that will be serialized by the format
|
||||||
|
* writer.
|
||||||
|
* @type {ol.proj.ProjectionLike}
|
||||||
|
*/
|
||||||
|
olx.format.WriteOptions.prototype.featureProjection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{defaultDataProjection: ol.proj.ProjectionLike,
|
||||||
* geometryName: (string|undefined)}}
|
* geometryName: (string|undefined)}}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -1170,10 +1221,10 @@ olx.format.GeoJSONOptions;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default projection.
|
* Default data projection.
|
||||||
* @type {ol.proj.ProjectionLike}
|
* @type {ol.proj.ProjectionLike}
|
||||||
*/
|
*/
|
||||||
olx.format.GeoJSONOptions.prototype.defaultProjection;
|
olx.format.GeoJSONOptions.prototype.defaultDataProjection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1198,19 +1249,18 @@ olx.format.PolylineOptions;
|
|||||||
olx.format.PolylineOptions.prototype.factor;
|
olx.format.PolylineOptions.prototype.factor;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{defaultProjection: ol.proj.ProjectionLike}}
|
* @typedef {{defaultDataProjection: ol.proj.ProjectionLike}}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
olx.format.TopoJSONOptions;
|
olx.format.TopoJSONOptions;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default projection.
|
* Default data projection.
|
||||||
* @type {ol.proj.ProjectionLike}
|
* @type {ol.proj.ProjectionLike}
|
||||||
*/
|
*/
|
||||||
olx.format.TopoJSONOptions.prototype.defaultProjection;
|
olx.format.TopoJSONOptions.prototype.defaultDataProjection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
goog.provide('ol.format.Feature');
|
goog.provide('ol.format.Feature');
|
||||||
|
|
||||||
goog.require('goog.functions');
|
goog.require('goog.array');
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +18,12 @@ goog.require('goog.functions');
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
ol.format.Feature = function() {
|
ol.format.Feature = function() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
* @type {ol.proj.Projection}
|
||||||
|
*/
|
||||||
|
this.defaultDataProjection = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -25,6 +33,50 @@ ol.format.Feature = function() {
|
|||||||
ol.format.Feature.prototype.getExtensions = goog.abstractMethod;
|
ol.format.Feature.prototype.getExtensions = goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the data projection to the read options.
|
||||||
|
* @param {Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Options.
|
||||||
|
* @return {olx.format.ReadOptions|undefined} Options.
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.format.Feature.prototype.getReadOptions = function(
|
||||||
|
source, opt_options) {
|
||||||
|
var options;
|
||||||
|
if (goog.isDef(opt_options)) {
|
||||||
|
options = {
|
||||||
|
dataProjection: goog.isDef(opt_options.dataProjection) ?
|
||||||
|
opt_options.dataProjection : this.readProjection(source),
|
||||||
|
featureProjection: opt_options.featureProjection
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return this.adaptOptions(options);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the `defaultDataProjection` on the options, if no `dataProjection`
|
||||||
|
* is set.
|
||||||
|
* @param {olx.format.WriteOptions|olx.format.ReadOptions|undefined} options
|
||||||
|
* Options.
|
||||||
|
* @protected
|
||||||
|
* @return {olx.format.WriteOptions|olx.format.ReadOptions|undefined}
|
||||||
|
* Updated options.
|
||||||
|
*/
|
||||||
|
ol.format.Feature.prototype.adaptOptions = function(
|
||||||
|
options) {
|
||||||
|
var updatedOptions;
|
||||||
|
if (goog.isDef(options)) {
|
||||||
|
updatedOptions = {
|
||||||
|
featureProjection: options.featureProjection,
|
||||||
|
dataProjection: goog.isDefAndNotNull(options.dataProjection) ?
|
||||||
|
options.dataProjection : this.defaultDataProjection
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return updatedOptions;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.format.FormatType} Format.
|
* @return {ol.format.FormatType} Format.
|
||||||
*/
|
*/
|
||||||
@@ -35,6 +87,7 @@ ol.format.Feature.prototype.getType = goog.abstractMethod;
|
|||||||
* Read a single feature from a source.
|
* Read a single feature from a source.
|
||||||
*
|
*
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
*/
|
*/
|
||||||
ol.format.Feature.prototype.readFeature = goog.abstractMethod;
|
ol.format.Feature.prototype.readFeature = goog.abstractMethod;
|
||||||
@@ -44,6 +97,7 @@ ol.format.Feature.prototype.readFeature = goog.abstractMethod;
|
|||||||
* Read all features from a source.
|
* Read all features from a source.
|
||||||
*
|
*
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
*/
|
*/
|
||||||
ol.format.Feature.prototype.readFeatures = goog.abstractMethod;
|
ol.format.Feature.prototype.readFeatures = goog.abstractMethod;
|
||||||
@@ -53,6 +107,7 @@ ol.format.Feature.prototype.readFeatures = goog.abstractMethod;
|
|||||||
* Read a single geometry from a source.
|
* Read a single geometry from a source.
|
||||||
*
|
*
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
ol.format.Feature.prototype.readGeometry = goog.abstractMethod;
|
ol.format.Feature.prototype.readGeometry = goog.abstractMethod;
|
||||||
@@ -71,6 +126,7 @@ ol.format.Feature.prototype.readProjection = goog.abstractMethod;
|
|||||||
* Encode a feature in this format.
|
* Encode a feature in this format.
|
||||||
*
|
*
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @return {ArrayBuffer|Node|Object|string} Result.
|
* @return {ArrayBuffer|Node|Object|string} Result.
|
||||||
*/
|
*/
|
||||||
ol.format.Feature.prototype.writeFeature = goog.abstractMethod;
|
ol.format.Feature.prototype.writeFeature = goog.abstractMethod;
|
||||||
@@ -80,6 +136,7 @@ ol.format.Feature.prototype.writeFeature = goog.abstractMethod;
|
|||||||
* Encode an array of features in this format.
|
* Encode an array of features in this format.
|
||||||
*
|
*
|
||||||
* @param {Array.<ol.Feature>} features Features.
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @return {ArrayBuffer|Node|Object|string} Result.
|
* @return {ArrayBuffer|Node|Object|string} Result.
|
||||||
*/
|
*/
|
||||||
ol.format.Feature.prototype.writeFeatures = goog.abstractMethod;
|
ol.format.Feature.prototype.writeFeatures = goog.abstractMethod;
|
||||||
@@ -89,6 +146,41 @@ ol.format.Feature.prototype.writeFeatures = goog.abstractMethod;
|
|||||||
* Write a single geometry in this format.
|
* Write a single geometry in this format.
|
||||||
*
|
*
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @return {ArrayBuffer|Node|Object|string} Node.
|
* @return {ArrayBuffer|Node|Object|string} Node.
|
||||||
*/
|
*/
|
||||||
ol.format.Feature.prototype.writeGeometry = goog.abstractMethod;
|
ol.format.Feature.prototype.writeGeometry = goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.Geometry|ol.Extent} geometry Geometry.
|
||||||
|
* @param {boolean} write Set to true for writing, false for reading.
|
||||||
|
* @param {(olx.format.WriteOptions|olx.format.ReadOptions)=} opt_options
|
||||||
|
* Options.
|
||||||
|
* @return {ol.geom.Geometry|ol.Extent} Transformed geometry.
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.format.Feature.transformWithOptions = function(
|
||||||
|
geometry, write, opt_options) {
|
||||||
|
var featureProjection = goog.isDef(opt_options) ?
|
||||||
|
ol.proj.get(opt_options.featureProjection) : null;
|
||||||
|
var dataProjection = goog.isDef(opt_options) ?
|
||||||
|
ol.proj.get(opt_options.dataProjection) : null;
|
||||||
|
if (!goog.isNull(featureProjection) && !goog.isNull(dataProjection) &&
|
||||||
|
!ol.proj.equivalent(featureProjection, dataProjection)) {
|
||||||
|
if (geometry instanceof ol.geom.Geometry) {
|
||||||
|
return (write ? geometry.clone() : geometry).transform(
|
||||||
|
write ? featureProjection : dataProjection,
|
||||||
|
write ? dataProjection : featureProjection);
|
||||||
|
} else {
|
||||||
|
// FIXME this is necessary because ol.format.GML treats extents
|
||||||
|
// as geometries
|
||||||
|
return ol.proj.transformExtent(
|
||||||
|
write ? goog.array.clone(geometry) : geometry,
|
||||||
|
write ? featureProjection : dataProjection,
|
||||||
|
write ? dataProjection : featureProjection);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return geometry;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ goog.require('goog.array');
|
|||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.JSONFeature');
|
goog.require('ol.format.JSONFeature');
|
||||||
goog.require('ol.geom.GeometryCollection');
|
goog.require('ol.geom.GeometryCollection');
|
||||||
goog.require('ol.geom.GeometryType');
|
goog.require('ol.geom.GeometryType');
|
||||||
@@ -36,11 +37,11 @@ ol.format.GeoJSON = function(opt_options) {
|
|||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @inheritDoc
|
||||||
* @type {ol.proj.Projection}
|
|
||||||
*/
|
*/
|
||||||
this.defaultProjection_ = ol.proj.get(options.defaultProjection ?
|
this.defaultDataProjection = ol.proj.get(
|
||||||
options.defaultProjection : 'EPSG:4326');
|
goog.isDefAndNotNull(options.defaultDataProjection) ?
|
||||||
|
options.defaultDataProjection : 'EPSG:4326');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,28 +65,39 @@ ol.format.GeoJSON.EXTENSIONS_ = ['.geojson'];
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {GeoJSONObject} object Object.
|
* @param {GeoJSONObject} object Object.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @private
|
* @private
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.readGeometry_ = function(object) {
|
ol.format.GeoJSON.readGeometry_ = function(object, opt_options) {
|
||||||
if (goog.isNull(object)) {
|
if (goog.isNull(object)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var geometryReader = ol.format.GeoJSON.GEOMETRY_READERS_[object.type];
|
var geometryReader = ol.format.GeoJSON.GEOMETRY_READERS_[object.type];
|
||||||
goog.asserts.assert(goog.isDef(geometryReader));
|
goog.asserts.assert(goog.isDef(geometryReader));
|
||||||
return geometryReader(object);
|
return /** @type {ol.geom.Geometry} */ (
|
||||||
|
ol.format.Feature.transformWithOptions(
|
||||||
|
geometryReader(object), false, opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {GeoJSONGeometryCollection} object Object.
|
* @param {GeoJSONGeometryCollection} object Object.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @private
|
* @private
|
||||||
* @return {ol.geom.GeometryCollection} Geometry collection.
|
* @return {ol.geom.GeometryCollection} Geometry collection.
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.readGeometryCollectionGeometry_ = function(object) {
|
ol.format.GeoJSON.readGeometryCollectionGeometry_ = function(
|
||||||
|
object, opt_options) {
|
||||||
goog.asserts.assert(object.type == 'GeometryCollection');
|
goog.asserts.assert(object.type == 'GeometryCollection');
|
||||||
var geometries = goog.array.map(
|
var geometries = goog.array.map(object.geometries,
|
||||||
object.geometries, ol.format.GeoJSON.readGeometry_);
|
/**
|
||||||
|
* @param {GeoJSONObject} geometry Geometry.
|
||||||
|
* @return {ol.geom.Geometry} geometry Geometry.
|
||||||
|
*/
|
||||||
|
function(geometry) {
|
||||||
|
return ol.format.GeoJSON.readGeometry_(geometry, opt_options);
|
||||||
|
});
|
||||||
return new ol.geom.GeometryCollection(geometries);
|
return new ol.geom.GeometryCollection(geometries);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -158,13 +170,15 @@ ol.format.GeoJSON.readPolygonGeometry_ = function(object) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @private
|
* @private
|
||||||
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} GeoJSON geometry.
|
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} GeoJSON geometry.
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.writeGeometry_ = function(geometry) {
|
ol.format.GeoJSON.writeGeometry_ = function(geometry, opt_options) {
|
||||||
var geometryWriter = ol.format.GeoJSON.GEOMETRY_WRITERS_[geometry.getType()];
|
var geometryWriter = ol.format.GeoJSON.GEOMETRY_WRITERS_[geometry.getType()];
|
||||||
goog.asserts.assert(goog.isDef(geometryWriter));
|
goog.asserts.assert(goog.isDef(geometryWriter));
|
||||||
return geometryWriter(geometry);
|
return geometryWriter(/** @type {ol.geom.Geometry} */ (
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, true, opt_options)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -183,13 +197,17 @@ ol.format.GeoJSON.writeEmptyGeometryCollectionGeometry_ = function(geometry) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @private
|
* @private
|
||||||
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
|
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.writeGeometryCollectionGeometry_ = function(geometry) {
|
ol.format.GeoJSON.writeGeometryCollectionGeometry_ = function(
|
||||||
|
geometry, opt_options) {
|
||||||
goog.asserts.assertInstanceof(geometry, ol.geom.GeometryCollection);
|
goog.asserts.assertInstanceof(geometry, ol.geom.GeometryCollection);
|
||||||
var geometries = goog.array.map(
|
var geometries = goog.array.map(
|
||||||
geometry.getGeometriesArray(), ol.format.GeoJSON.writeGeometry_);
|
geometry.getGeometriesArray(), function(geometry) {
|
||||||
|
return ol.format.GeoJSON.writeGeometry_(geometry, opt_options);
|
||||||
|
});
|
||||||
return /** @type {GeoJSONGeometryCollection} */ ({
|
return /** @type {GeoJSONGeometryCollection} */ ({
|
||||||
'type': 'GeometryCollection',
|
'type': 'GeometryCollection',
|
||||||
'geometries': geometries
|
'geometries': geometries
|
||||||
@@ -330,6 +348,7 @@ ol.format.GeoJSON.prototype.getExtensions = function() {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -342,6 +361,7 @@ ol.format.GeoJSON.prototype.readFeature;
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -351,10 +371,12 @@ ol.format.GeoJSON.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.prototype.readFeatureFromObject = function(object) {
|
ol.format.GeoJSON.prototype.readFeatureFromObject = function(
|
||||||
|
object, opt_options) {
|
||||||
var geoJSONFeature = /** @type {GeoJSONFeature} */ (object);
|
var geoJSONFeature = /** @type {GeoJSONFeature} */ (object);
|
||||||
goog.asserts.assert(geoJSONFeature.type == 'Feature');
|
goog.asserts.assert(geoJSONFeature.type == 'Feature');
|
||||||
var geometry = ol.format.GeoJSON.readGeometry_(geoJSONFeature.geometry);
|
var geometry = ol.format.GeoJSON.readGeometry_(geoJSONFeature.geometry,
|
||||||
|
opt_options);
|
||||||
var feature = new ol.Feature();
|
var feature = new ol.Feature();
|
||||||
if (goog.isDef(this.geometryName_)) {
|
if (goog.isDef(this.geometryName_)) {
|
||||||
feature.setGeometryName(this.geometryName_);
|
feature.setGeometryName(this.geometryName_);
|
||||||
@@ -373,10 +395,11 @@ ol.format.GeoJSON.prototype.readFeatureFromObject = function(object) {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.prototype.readFeaturesFromObject = function(object) {
|
ol.format.GeoJSON.prototype.readFeaturesFromObject = function(
|
||||||
|
object, opt_options) {
|
||||||
var geoJSONObject = /** @type {GeoJSONObject} */ (object);
|
var geoJSONObject = /** @type {GeoJSONObject} */ (object);
|
||||||
if (geoJSONObject.type == 'Feature') {
|
if (geoJSONObject.type == 'Feature') {
|
||||||
return [this.readFeatureFromObject(object)];
|
return [this.readFeatureFromObject(object, opt_options)];
|
||||||
} else if (geoJSONObject.type == 'FeatureCollection') {
|
} else if (geoJSONObject.type == 'FeatureCollection') {
|
||||||
var geoJSONFeatureCollection = /** @type {GeoJSONFeatureCollection} */
|
var geoJSONFeatureCollection = /** @type {GeoJSONFeatureCollection} */
|
||||||
(object);
|
(object);
|
||||||
@@ -385,7 +408,8 @@ ol.format.GeoJSON.prototype.readFeaturesFromObject = function(object) {
|
|||||||
var geoJSONFeatures = geoJSONFeatureCollection.features;
|
var geoJSONFeatures = geoJSONFeatureCollection.features;
|
||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
|
for (i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
|
||||||
features.push(this.readFeatureFromObject(geoJSONFeatures[i]));
|
features.push(this.readFeatureFromObject(geoJSONFeatures[i],
|
||||||
|
opt_options));
|
||||||
}
|
}
|
||||||
return features;
|
return features;
|
||||||
} else {
|
} else {
|
||||||
@@ -400,6 +424,7 @@ ol.format.GeoJSON.prototype.readFeaturesFromObject = function(object) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -409,9 +434,10 @@ ol.format.GeoJSON.prototype.readGeometry;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.prototype.readGeometryFromObject = function(object) {
|
ol.format.GeoJSON.prototype.readGeometryFromObject = function(
|
||||||
|
object, opt_options) {
|
||||||
return ol.format.GeoJSON.readGeometry_(
|
return ol.format.GeoJSON.readGeometry_(
|
||||||
/** @type {GeoJSONGeometry} */ (object));
|
/** @type {GeoJSONGeometry} */ (object), opt_options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -446,7 +472,7 @@ ol.format.GeoJSON.prototype.readProjectionFromObject = function(object) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.defaultProjection_;
|
return this.defaultDataProjection;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -456,6 +482,7 @@ ol.format.GeoJSON.prototype.readProjectionFromObject = function(object) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
|
* @param {olx.format.WriteOptions} options Write options.
|
||||||
* @return {GeoJSONFeature} GeoJSON.
|
* @return {GeoJSONFeature} GeoJSON.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -465,7 +492,8 @@ ol.format.GeoJSON.prototype.writeFeature;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.prototype.writeFeatureObject = function(feature) {
|
ol.format.GeoJSON.prototype.writeFeatureObject = function(
|
||||||
|
feature, opt_options) {
|
||||||
var object = {
|
var object = {
|
||||||
'type': 'Feature'
|
'type': 'Feature'
|
||||||
};
|
};
|
||||||
@@ -476,7 +504,8 @@ ol.format.GeoJSON.prototype.writeFeatureObject = function(feature) {
|
|||||||
var geometry = feature.getGeometry();
|
var geometry = feature.getGeometry();
|
||||||
if (goog.isDefAndNotNull(geometry)) {
|
if (goog.isDefAndNotNull(geometry)) {
|
||||||
goog.object.set(
|
goog.object.set(
|
||||||
object, 'geometry', ol.format.GeoJSON.writeGeometry_(geometry));
|
object, 'geometry',
|
||||||
|
ol.format.GeoJSON.writeGeometry_(geometry, opt_options));
|
||||||
}
|
}
|
||||||
var properties = feature.getProperties();
|
var properties = feature.getProperties();
|
||||||
goog.object.remove(properties, 'geometry');
|
goog.object.remove(properties, 'geometry');
|
||||||
@@ -492,6 +521,7 @@ ol.format.GeoJSON.prototype.writeFeatureObject = function(feature) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {Array.<ol.Feature>} features Features.
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions} options Write options.
|
||||||
* @return {GeoJSONObject} GeoJSON.
|
* @return {GeoJSONObject} GeoJSON.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -501,11 +531,12 @@ ol.format.GeoJSON.prototype.writeFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.prototype.writeFeaturesObject = function(features) {
|
ol.format.GeoJSON.prototype.writeFeaturesObject =
|
||||||
|
function(features, opt_options) {
|
||||||
var objects = [];
|
var objects = [];
|
||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = features.length; i < ii; ++i) {
|
for (i = 0, ii = features.length; i < ii; ++i) {
|
||||||
objects.push(this.writeFeatureObject(features[i]));
|
objects.push(this.writeFeatureObject(features[i], opt_options));
|
||||||
}
|
}
|
||||||
return /** @type {GeoJSONFeatureCollection} */ ({
|
return /** @type {GeoJSONFeatureCollection} */ ({
|
||||||
'type': 'FeatureCollection',
|
'type': 'FeatureCollection',
|
||||||
@@ -519,6 +550,7 @@ ol.format.GeoJSON.prototype.writeFeaturesObject = function(features) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions} options Write options.
|
||||||
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} GeoJSON.
|
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} GeoJSON.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// FIXME Envelopes should not be treated as geometries! readEnvelope_ is part
|
||||||
|
// of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect
|
||||||
|
// envelopes/extents, only geometries!
|
||||||
goog.provide('ol.format.GML');
|
goog.provide('ol.format.GML');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
@@ -8,6 +11,7 @@ goog.require('goog.string');
|
|||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.array');
|
goog.require('ol.array');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.XMLFeature');
|
goog.require('ol.format.XMLFeature');
|
||||||
goog.require('ol.format.XSD');
|
goog.require('ol.format.XSD');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.Geometry');
|
||||||
@@ -162,7 +166,8 @@ ol.format.GML.readGeometry = function(node, objectStack) {
|
|||||||
var geometry = ol.xml.pushParseAndPop(/** @type {ol.geom.Geometry} */(null),
|
var geometry = ol.xml.pushParseAndPop(/** @type {ol.geom.Geometry} */(null),
|
||||||
ol.format.GML.GEOMETRY_PARSERS_, node, objectStack);
|
ol.format.GML.GEOMETRY_PARSERS_, node, objectStack);
|
||||||
if (goog.isDefAndNotNull(geometry)) {
|
if (goog.isDefAndNotNull(geometry)) {
|
||||||
return geometry;
|
return /** @type {ol.geom.Geometry} */ (
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, false, context));
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -1037,9 +1042,10 @@ ol.format.GML.RING_PARSERS_ = {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GML.prototype.readGeometryFromNode = function(node) {
|
ol.format.GML.prototype.readGeometryFromNode = function(node, opt_options) {
|
||||||
var geometry = ol.format.GML.readGeometry(node, [{}]);
|
var geometry = ol.format.GML.readGeometry(node,
|
||||||
return (goog.isDef(geometry)) ? geometry : null;
|
[this.getReadOptions(node, goog.isDef(opt_options) ? opt_options : {})]);
|
||||||
|
return (goog.isDef(geometry) ? geometry : null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1048,6 +1054,7 @@ ol.format.GML.prototype.readGeometryFromNode = function(node) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -1057,12 +1064,24 @@ ol.format.GML.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GML.prototype.readFeaturesFromNode = function(node) {
|
ol.format.GML.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||||
var objectStack = [{
|
var options = {
|
||||||
'featureType': this.featureType_,
|
'featureType': this.featureType_,
|
||||||
'featureNS': this.featureNS_
|
'featureNS': this.featureNS_
|
||||||
}];
|
};
|
||||||
return ol.format.GML.readFeatures_(node, objectStack);
|
if (goog.isDef(opt_options)) {
|
||||||
|
goog.object.extend(options, this.getReadOptions(node, opt_options));
|
||||||
|
}
|
||||||
|
return ol.format.GML.readFeatures_(node, [options]);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.format.GML.prototype.readProjectionFromNode = function(node) {
|
||||||
|
return ol.proj.get(goog.isDef(this.srsName_) ? this.srsName_ :
|
||||||
|
node.firstElementChild.getAttribute('srsName'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1443,9 +1462,22 @@ ol.format.GML.writeGeometry = function(node, geometry, objectStack) {
|
|||||||
goog.asserts.assert(goog.isObject(context));
|
goog.asserts.assert(goog.isObject(context));
|
||||||
var item = goog.object.clone(context);
|
var item = goog.object.clone(context);
|
||||||
item.node = node;
|
item.node = node;
|
||||||
|
var value;
|
||||||
|
if (goog.isArray(geometry)) {
|
||||||
|
if (goog.isDef(context.dataProjection)) {
|
||||||
|
value = ol.proj.transformExtent(
|
||||||
|
geometry, context.featureProjection, context.dataProjection);
|
||||||
|
} else {
|
||||||
|
value = geometry;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.Geometry);
|
||||||
|
value =
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, true, context);
|
||||||
|
}
|
||||||
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
||||||
(item), ol.format.GML.GEOMETRY_SERIALIZERS_,
|
(item), ol.format.GML.GEOMETRY_SERIALIZERS_,
|
||||||
ol.format.GML.GEOMETRY_NODE_FACTORY_, [geometry], objectStack);
|
ol.format.GML.GEOMETRY_NODE_FACTORY_, [value], objectStack);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1673,14 +1705,15 @@ ol.format.GML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GML.prototype.writeGeometryNode = function(geometry) {
|
ol.format.GML.prototype.writeGeometryNode = function(geometry, opt_options) {
|
||||||
var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom');
|
var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom');
|
||||||
var context = {node: geom, srsName: this.srsName_,
|
var context = {node: geom, srsName: this.srsName_,
|
||||||
curve: this.curve_, surface: this.surface_,
|
curve: this.curve_, surface: this.surface_,
|
||||||
multiSurface: this.multiSurface_, multiCurve: this.multiCurve_};
|
multiSurface: this.multiSurface_, multiCurve: this.multiCurve_};
|
||||||
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
if (goog.isDef(opt_options)) {
|
||||||
(context), ol.format.GML.GEOMETRY_SERIALIZERS_,
|
goog.object.extend(context, opt_options);
|
||||||
ol.format.GML.GEOMETRY_NODE_FACTORY_, [geometry], []);
|
}
|
||||||
|
ol.format.GML.writeGeometry(geom, geometry, [context]);
|
||||||
return geom;
|
return geom;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1690,6 +1723,7 @@ ol.format.GML.prototype.writeGeometryNode = function(geometry) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {Array.<ol.Feature>} features Features.
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Options.
|
||||||
* @return {Node} Result.
|
* @return {Node} Result.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -1699,7 +1733,7 @@ ol.format.GML.prototype.writeFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GML.prototype.writeFeaturesNode = function(features) {
|
ol.format.GML.prototype.writeFeaturesNode = function(features, opt_options) {
|
||||||
var node = ol.xml.createElementNS('http://www.opengis.net/gml',
|
var node = ol.xml.createElementNS('http://www.opengis.net/gml',
|
||||||
'featureMembers');
|
'featureMembers');
|
||||||
ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
|
ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||||
@@ -1713,6 +1747,9 @@ ol.format.GML.prototype.writeFeaturesNode = function(features) {
|
|||||||
featureNS: this.featureNS_,
|
featureNS: this.featureNS_,
|
||||||
featureType: this.featureType_
|
featureType: this.featureType_
|
||||||
};
|
};
|
||||||
|
if (goog.isDef(opt_options)) {
|
||||||
|
goog.object.extend(context, opt_options);
|
||||||
|
}
|
||||||
ol.format.GML.writeFeatureMembers_(node, features, [context]);
|
ol.format.GML.writeFeatureMembers_(node, features, [context]);
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.dom.NodeType');
|
goog.require('goog.dom.NodeType');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.XMLFeature');
|
goog.require('ol.format.XMLFeature');
|
||||||
goog.require('ol.format.XSD');
|
goog.require('ol.format.XSD');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
@@ -30,6 +31,11 @@ ol.format.GPX = function(opt_options) {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
this.defaultDataProjection = ol.proj.get('EPSG:4326');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {function(ol.Feature, Node)|undefined}
|
* @type {function(ol.Feature, Node)|undefined}
|
||||||
* @private
|
* @private
|
||||||
@@ -175,6 +181,7 @@ ol.format.GPX.parseTrkSeg_ = function(node, objectStack) {
|
|||||||
ol.format.GPX.readRte_ = function(node, objectStack) {
|
ol.format.GPX.readRte_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'rte');
|
goog.asserts.assert(node.localName == 'rte');
|
||||||
|
var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
|
||||||
var values = ol.xml.pushParseAndPop({
|
var values = ol.xml.pushParseAndPop({
|
||||||
'flatCoordinates': []
|
'flatCoordinates': []
|
||||||
}, ol.format.GPX.RTE_PARSERS_, node, objectStack);
|
}, ol.format.GPX.RTE_PARSERS_, node, objectStack);
|
||||||
@@ -186,6 +193,7 @@ ol.format.GPX.readRte_ = function(node, objectStack) {
|
|||||||
goog.object.remove(values, 'flatCoordinates');
|
goog.object.remove(values, 'flatCoordinates');
|
||||||
var geometry = new ol.geom.LineString(null);
|
var geometry = new ol.geom.LineString(null);
|
||||||
geometry.setFlatCoordinates(ol.geom.GeometryLayout.XYZM, flatCoordinates);
|
geometry.setFlatCoordinates(ol.geom.GeometryLayout.XYZM, flatCoordinates);
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, false, options);
|
||||||
var feature = new ol.Feature(geometry);
|
var feature = new ol.Feature(geometry);
|
||||||
feature.setProperties(values);
|
feature.setProperties(values);
|
||||||
return feature;
|
return feature;
|
||||||
@@ -201,6 +209,7 @@ ol.format.GPX.readRte_ = function(node, objectStack) {
|
|||||||
ol.format.GPX.readTrk_ = function(node, objectStack) {
|
ol.format.GPX.readTrk_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'trk');
|
goog.asserts.assert(node.localName == 'trk');
|
||||||
|
var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
|
||||||
var values = ol.xml.pushParseAndPop({
|
var values = ol.xml.pushParseAndPop({
|
||||||
'flatCoordinates': [],
|
'flatCoordinates': [],
|
||||||
'ends': []
|
'ends': []
|
||||||
@@ -216,6 +225,7 @@ ol.format.GPX.readTrk_ = function(node, objectStack) {
|
|||||||
var geometry = new ol.geom.MultiLineString(null);
|
var geometry = new ol.geom.MultiLineString(null);
|
||||||
geometry.setFlatCoordinates(
|
geometry.setFlatCoordinates(
|
||||||
ol.geom.GeometryLayout.XYZM, flatCoordinates, ends);
|
ol.geom.GeometryLayout.XYZM, flatCoordinates, ends);
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, false, options);
|
||||||
var feature = new ol.Feature(geometry);
|
var feature = new ol.Feature(geometry);
|
||||||
feature.setProperties(values);
|
feature.setProperties(values);
|
||||||
return feature;
|
return feature;
|
||||||
@@ -231,6 +241,7 @@ ol.format.GPX.readTrk_ = function(node, objectStack) {
|
|||||||
ol.format.GPX.readWpt_ = function(node, objectStack) {
|
ol.format.GPX.readWpt_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'wpt');
|
goog.asserts.assert(node.localName == 'wpt');
|
||||||
|
var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
|
||||||
var values = ol.xml.pushParseAndPop(
|
var values = ol.xml.pushParseAndPop(
|
||||||
{}, ol.format.GPX.WPT_PARSERS_, node, objectStack);
|
{}, ol.format.GPX.WPT_PARSERS_, node, objectStack);
|
||||||
if (!goog.isDef(values)) {
|
if (!goog.isDef(values)) {
|
||||||
@@ -239,6 +250,7 @@ ol.format.GPX.readWpt_ = function(node, objectStack) {
|
|||||||
var coordinates = ol.format.GPX.appendCoordinate_([], node, values);
|
var coordinates = ol.format.GPX.appendCoordinate_([], node, values);
|
||||||
var geometry = new ol.geom.Point(
|
var geometry = new ol.geom.Point(
|
||||||
coordinates, ol.geom.GeometryLayout.XYZM);
|
coordinates, ol.geom.GeometryLayout.XYZM);
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, false, options);
|
||||||
var feature = new ol.Feature(geometry);
|
var feature = new ol.Feature(geometry);
|
||||||
feature.setProperties(values);
|
feature.setProperties(values);
|
||||||
return feature;
|
return feature;
|
||||||
@@ -415,6 +427,7 @@ ol.format.GPX.prototype.handleReadExtensions_ = function(features) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -424,7 +437,7 @@ ol.format.GPX.prototype.readFeature;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GPX.prototype.readFeatureFromNode = function(node) {
|
ol.format.GPX.prototype.readFeatureFromNode = function(node, opt_options) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
if (!goog.array.contains(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) {
|
if (!goog.array.contains(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -433,7 +446,7 @@ ol.format.GPX.prototype.readFeatureFromNode = function(node) {
|
|||||||
if (!goog.isDef(featureReader)) {
|
if (!goog.isDef(featureReader)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var feature = featureReader(node, []);
|
var feature = featureReader(node, [this.getReadOptions(node, opt_options)]);
|
||||||
if (!goog.isDef(feature)) {
|
if (!goog.isDef(feature)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -447,6 +460,7 @@ ol.format.GPX.prototype.readFeatureFromNode = function(node) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -456,7 +470,7 @@ ol.format.GPX.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GPX.prototype.readFeaturesFromNode = function(node) {
|
ol.format.GPX.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
if (!goog.array.contains(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) {
|
if (!goog.array.contains(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) {
|
||||||
return [];
|
return [];
|
||||||
@@ -464,7 +478,7 @@ ol.format.GPX.prototype.readFeaturesFromNode = function(node) {
|
|||||||
if (node.localName == 'gpx') {
|
if (node.localName == 'gpx') {
|
||||||
var features = ol.xml.pushParseAndPop(
|
var features = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<ol.Feature>} */ ([]), ol.format.GPX.GPX_PARSERS_,
|
/** @type {Array.<ol.Feature>} */ ([]), ol.format.GPX.GPX_PARSERS_,
|
||||||
node, []);
|
node, [this.getReadOptions(node, opt_options)]);
|
||||||
if (goog.isDef(features)) {
|
if (goog.isDef(features)) {
|
||||||
this.handleReadExtensions_(features);
|
this.handleReadExtensions_(features);
|
||||||
return features;
|
return features;
|
||||||
@@ -491,7 +505,7 @@ ol.format.GPX.prototype.readProjection;
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GPX.prototype.readProjectionFromDocument = function(doc) {
|
ol.format.GPX.prototype.readProjectionFromDocument = function(doc) {
|
||||||
return ol.proj.get('EPSG:4326');
|
return this.defaultDataProjection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -499,7 +513,7 @@ ol.format.GPX.prototype.readProjectionFromDocument = function(doc) {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GPX.prototype.readProjectionFromNode = function(node) {
|
ol.format.GPX.prototype.readProjectionFromNode = function(node) {
|
||||||
return ol.proj.get('EPSG:4326');
|
return this.defaultDataProjection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -574,11 +588,14 @@ ol.format.GPX.writeWptType_ = function(node, coordinate, objectStack) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GPX.writeRte_ = function(node, feature, objectStack) {
|
ol.format.GPX.writeRte_ = function(node, feature, objectStack) {
|
||||||
|
var options = /** @type {olx.format.WriteOptions} */ (objectStack[0]);
|
||||||
var properties = feature.getProperties();
|
var properties = feature.getProperties();
|
||||||
var context = {node: node, 'properties': properties};
|
var context = {node: node, 'properties': properties};
|
||||||
var geometry = feature.getGeometry();
|
var geometry = feature.getGeometry();
|
||||||
if (goog.isDef(geometry)) {
|
if (goog.isDef(geometry)) {
|
||||||
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
||||||
|
geometry = /** @type {ol.geom.LineString} */
|
||||||
|
(ol.format.Feature.transformWithOptions(geometry, true, options));
|
||||||
goog.object.set(context, 'geometryLayout', geometry.getLayout());
|
goog.object.set(context, 'geometryLayout', geometry.getLayout());
|
||||||
goog.object.set(properties, 'rtept', geometry.getCoordinates());
|
goog.object.set(properties, 'rtept', geometry.getCoordinates());
|
||||||
}
|
}
|
||||||
@@ -598,11 +615,14 @@ ol.format.GPX.writeRte_ = function(node, feature, objectStack) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GPX.writeTrk_ = function(node, feature, objectStack) {
|
ol.format.GPX.writeTrk_ = function(node, feature, objectStack) {
|
||||||
|
var options = /** @type {olx.format.WriteOptions} */ (objectStack[0]);
|
||||||
var properties = feature.getProperties();
|
var properties = feature.getProperties();
|
||||||
var context = {node: node, 'properties': properties};
|
var context = {node: node, 'properties': properties};
|
||||||
var geometry = feature.getGeometry();
|
var geometry = feature.getGeometry();
|
||||||
if (goog.isDef(geometry)) {
|
if (goog.isDef(geometry)) {
|
||||||
goog.asserts.assertInstanceof(geometry, ol.geom.MultiLineString);
|
goog.asserts.assertInstanceof(geometry, ol.geom.MultiLineString);
|
||||||
|
geometry = /** @type {ol.geom.MultiLineString} */
|
||||||
|
(ol.format.Feature.transformWithOptions(geometry, true, options));
|
||||||
goog.object.set(properties, 'trkseg', geometry.getLineStrings());
|
goog.object.set(properties, 'trkseg', geometry.getLineStrings());
|
||||||
}
|
}
|
||||||
var parentNode = objectStack[objectStack.length - 1].node;
|
var parentNode = objectStack[objectStack.length - 1].node;
|
||||||
@@ -636,12 +656,15 @@ ol.format.GPX.writeTrkSeg_ = function(node, lineString, objectStack) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GPX.writeWpt_ = function(node, feature, objectStack) {
|
ol.format.GPX.writeWpt_ = function(node, feature, objectStack) {
|
||||||
|
var options = /** @type {olx.format.WriteOptions} */ (objectStack[0]);
|
||||||
var context = objectStack[objectStack.length - 1];
|
var context = objectStack[objectStack.length - 1];
|
||||||
goog.asserts.assert(goog.isObject(context));
|
goog.asserts.assert(goog.isObject(context));
|
||||||
goog.object.set(context, 'properties', feature.getProperties());
|
goog.object.set(context, 'properties', feature.getProperties());
|
||||||
var geometry = feature.getGeometry();
|
var geometry = feature.getGeometry();
|
||||||
if (goog.isDef(geometry)) {
|
if (goog.isDef(geometry)) {
|
||||||
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
|
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
|
||||||
|
geometry = /** @type {ol.geom.Point} */
|
||||||
|
(ol.format.Feature.transformWithOptions(geometry, true, options));
|
||||||
goog.object.set(context, 'geometryLayout', geometry.getLayout());
|
goog.object.set(context, 'geometryLayout', geometry.getLayout());
|
||||||
ol.format.GPX.writeWptType_(node, geometry.getCoordinates(), objectStack);
|
ol.format.GPX.writeWptType_(node, geometry.getCoordinates(), objectStack);
|
||||||
}
|
}
|
||||||
@@ -845,6 +868,7 @@ ol.format.GPX.GPX_SERIALIZERS_ = ol.xml.makeStructureNS(
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {Array.<ol.Feature>} features Features.
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @return {Node} Result.
|
* @return {Node} Result.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -854,11 +878,12 @@ ol.format.GPX.prototype.writeFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GPX.prototype.writeFeaturesNode = function(features) {
|
ol.format.GPX.prototype.writeFeaturesNode = function(features, opt_options) {
|
||||||
//FIXME Serialize metadata
|
//FIXME Serialize metadata
|
||||||
var gpx = ol.xml.createElementNS('http://www.topografix.com/GPX/1/1', 'gpx');
|
var gpx = ol.xml.createElementNS('http://www.topografix.com/GPX/1/1', 'gpx');
|
||||||
|
|
||||||
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
||||||
({node: gpx}), ol.format.GPX.GPX_SERIALIZERS_,
|
({node: gpx}), ol.format.GPX.GPX_SERIALIZERS_,
|
||||||
ol.format.GPX.GPX_NODE_FACTORY_, features, []);
|
ol.format.GPX.GPX_NODE_FACTORY_, features, [opt_options]);
|
||||||
return gpx;
|
return gpx;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.string');
|
goog.require('goog.string');
|
||||||
goog.require('goog.string.newlines');
|
goog.require('goog.string.newlines');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.TextFeature');
|
goog.require('ol.format.TextFeature');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
@@ -38,6 +39,11 @@ ol.format.IGC = function(opt_options) {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
this.defaultDataProjection = ol.proj.get('EPSG:4326');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.format.IGCZ}
|
* @type {ol.format.IGCZ}
|
||||||
@@ -95,6 +101,7 @@ ol.format.IGC.prototype.getExtensions = function() {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -104,7 +111,7 @@ ol.format.IGC.prototype.readFeature;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.IGC.prototype.readFeatureFromText = function(text) {
|
ol.format.IGC.prototype.readFeatureFromText = function(text, opt_options) {
|
||||||
var altitudeMode = this.altitudeMode_;
|
var altitudeMode = this.altitudeMode_;
|
||||||
var lines = goog.string.newlines.splitLines(text);
|
var lines = goog.string.newlines.splitLines(text);
|
||||||
/** @type {Object.<string, string>} */
|
/** @type {Object.<string, string>} */
|
||||||
@@ -169,7 +176,8 @@ ol.format.IGC.prototype.readFeatureFromText = function(text) {
|
|||||||
var layout = altitudeMode == ol.format.IGCZ.NONE ?
|
var layout = altitudeMode == ol.format.IGCZ.NONE ?
|
||||||
ol.geom.GeometryLayout.XYM : ol.geom.GeometryLayout.XYZM;
|
ol.geom.GeometryLayout.XYM : ol.geom.GeometryLayout.XYZM;
|
||||||
lineString.setFlatCoordinates(layout, flatCoordinates);
|
lineString.setFlatCoordinates(layout, flatCoordinates);
|
||||||
var feature = new ol.Feature(lineString);
|
var feature = new ol.Feature(ol.format.Feature.transformWithOptions(
|
||||||
|
lineString, false, opt_options));
|
||||||
feature.setProperties(properties);
|
feature.setProperties(properties);
|
||||||
return feature;
|
return feature;
|
||||||
};
|
};
|
||||||
@@ -181,6 +189,7 @@ ol.format.IGC.prototype.readFeatureFromText = function(text) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -190,8 +199,8 @@ ol.format.IGC.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.IGC.prototype.readFeaturesFromText = function(text) {
|
ol.format.IGC.prototype.readFeaturesFromText = function(text, opt_options) {
|
||||||
var feature = this.readFeatureFromText(text);
|
var feature = this.readFeatureFromText(text, opt_options);
|
||||||
if (!goog.isNull(feature)) {
|
if (!goog.isNull(feature)) {
|
||||||
return [feature];
|
return [feature];
|
||||||
} else {
|
} else {
|
||||||
@@ -215,5 +224,5 @@ ol.format.IGC.prototype.readProjection;
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.IGC.prototype.readProjectionFromText = function(text) {
|
ol.format.IGC.prototype.readProjectionFromText = function(text) {
|
||||||
return ol.proj.get('EPSG:4326');
|
return this.defaultDataProjection;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,21 +51,24 @@ ol.format.JSONFeature.prototype.getType = function() {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.JSONFeature.prototype.readFeature = function(source) {
|
ol.format.JSONFeature.prototype.readFeature = function(source, opt_options) {
|
||||||
return this.readFeatureFromObject(this.getObject_(source));
|
return this.readFeatureFromObject(
|
||||||
|
this.getObject_(source), this.getReadOptions(source, opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.JSONFeature.prototype.readFeatures = function(source) {
|
ol.format.JSONFeature.prototype.readFeatures = function(source, opt_options) {
|
||||||
return this.readFeaturesFromObject(this.getObject_(source));
|
return this.readFeaturesFromObject(
|
||||||
|
this.getObject_(source), this.getReadOptions(source, opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} object Object.
|
* @param {Object} object Object.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
*/
|
*/
|
||||||
@@ -74,6 +77,7 @@ ol.format.JSONFeature.prototype.readFeatureFromObject = goog.abstractMethod;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} object Object.
|
* @param {Object} object Object.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
*/
|
*/
|
||||||
@@ -83,13 +87,15 @@ ol.format.JSONFeature.prototype.readFeaturesFromObject = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.JSONFeature.prototype.readGeometry = function(source) {
|
ol.format.JSONFeature.prototype.readGeometry = function(source, opt_options) {
|
||||||
return this.readGeometryFromObject(this.getObject_(source));
|
return this.readGeometryFromObject(
|
||||||
|
this.getObject_(source), this.getReadOptions(source, opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} object Object.
|
* @param {Object} object Object.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
@@ -115,13 +121,14 @@ ol.format.JSONFeature.prototype.readProjectionFromObject = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.JSONFeature.prototype.writeFeature = function(feature) {
|
ol.format.JSONFeature.prototype.writeFeature = function(feature, opt_options) {
|
||||||
return this.writeFeatureObject(feature);
|
return this.writeFeatureObject(feature, this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Object} Object.
|
* @return {Object} Object.
|
||||||
*/
|
*/
|
||||||
@@ -131,13 +138,15 @@ ol.format.JSONFeature.prototype.writeFeatureObject = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.JSONFeature.prototype.writeFeatures = function(features) {
|
ol.format.JSONFeature.prototype.writeFeatures = function(
|
||||||
return this.writeFeaturesObject(features);
|
features, opt_options) {
|
||||||
|
return this.writeFeaturesObject(features, this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array.<ol.Feature>} features Features.
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Object} Object.
|
* @return {Object} Object.
|
||||||
*/
|
*/
|
||||||
@@ -147,13 +156,15 @@ ol.format.JSONFeature.prototype.writeFeaturesObject = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.JSONFeature.prototype.writeGeometry = function(geometry) {
|
ol.format.JSONFeature.prototype.writeGeometry = function(
|
||||||
return this.writeGeometryObject(geometry);
|
geometry, opt_options) {
|
||||||
|
return this.writeGeometryObject(geometry, this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Object} Object.
|
* @return {Object} Object.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ goog.require('ol.Feature');
|
|||||||
goog.require('ol.array');
|
goog.require('ol.array');
|
||||||
goog.require('ol.color');
|
goog.require('ol.color');
|
||||||
goog.require('ol.feature');
|
goog.require('ol.feature');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.XMLFeature');
|
goog.require('ol.format.XMLFeature');
|
||||||
goog.require('ol.format.XSD');
|
goog.require('ol.format.XSD');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.Geometry');
|
||||||
@@ -71,6 +72,11 @@ ol.format.KML = function(opt_options) {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
this.defaultDataProjection = ol.proj.get('EPSG:4326');
|
||||||
|
|
||||||
var defaultStyle = goog.isDef(options.defaultStyle) ?
|
var defaultStyle = goog.isDef(options.defaultStyle) ?
|
||||||
options.defaultStyle : ol.format.KML.DEFAULT_STYLE_ARRAY_;
|
options.defaultStyle : ol.format.KML.DEFAULT_STYLE_ARRAY_;
|
||||||
|
|
||||||
@@ -1434,6 +1440,10 @@ ol.format.KML.prototype.readPlacemark_ = function(node, objectStack) {
|
|||||||
if (!goog.isNull(id)) {
|
if (!goog.isNull(id)) {
|
||||||
feature.setId(id);
|
feature.setId(id);
|
||||||
}
|
}
|
||||||
|
var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
|
||||||
|
if (goog.isDefAndNotNull(object.geometry)) {
|
||||||
|
ol.format.Feature.transformWithOptions(object.geometry, false, options);
|
||||||
|
}
|
||||||
feature.setProperties(object);
|
feature.setProperties(object);
|
||||||
if (this.extractStyles_) {
|
if (this.extractStyles_) {
|
||||||
feature.setStyle(this.featureStyleFunction_);
|
feature.setStyle(this.featureStyleFunction_);
|
||||||
@@ -1497,6 +1507,7 @@ ol.format.KML.prototype.readSharedStyleMap_ = function(node, objectStack) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -1506,13 +1517,14 @@ ol.format.KML.prototype.readFeature;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.KML.prototype.readFeatureFromNode = function(node) {
|
ol.format.KML.prototype.readFeatureFromNode = function(node, opt_options) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
if (!goog.array.contains(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) {
|
if (!goog.array.contains(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
goog.asserts.assert(node.localName == 'Placemark');
|
goog.asserts.assert(node.localName == 'Placemark');
|
||||||
var feature = this.readPlacemark_(node, []);
|
var feature = this.readPlacemark_(
|
||||||
|
node, [this.getReadOptions(node, opt_options)]);
|
||||||
if (goog.isDef(feature)) {
|
if (goog.isDef(feature)) {
|
||||||
return feature;
|
return feature;
|
||||||
} else {
|
} else {
|
||||||
@@ -1526,6 +1538,7 @@ ol.format.KML.prototype.readFeatureFromNode = function(node) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -1535,7 +1548,7 @@ ol.format.KML.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.KML.prototype.readFeaturesFromNode = function(node) {
|
ol.format.KML.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
if (!goog.array.contains(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) {
|
if (!goog.array.contains(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) {
|
||||||
return [];
|
return [];
|
||||||
@@ -1543,14 +1556,16 @@ ol.format.KML.prototype.readFeaturesFromNode = function(node) {
|
|||||||
var features;
|
var features;
|
||||||
var localName = ol.xml.getLocalName(node);
|
var localName = ol.xml.getLocalName(node);
|
||||||
if (localName == 'Document' || localName == 'Folder') {
|
if (localName == 'Document' || localName == 'Folder') {
|
||||||
features = this.readDocumentOrFolder_(node, []);
|
features = this.readDocumentOrFolder_(
|
||||||
|
node, [this.getReadOptions(node, opt_options)]);
|
||||||
if (goog.isDef(features)) {
|
if (goog.isDef(features)) {
|
||||||
return features;
|
return features;
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
} else if (localName == 'Placemark') {
|
} else if (localName == 'Placemark') {
|
||||||
var feature = this.readPlacemark_(node, []);
|
var feature = this.readPlacemark_(
|
||||||
|
node, [this.getReadOptions(node, opt_options)]);
|
||||||
if (goog.isDef(feature)) {
|
if (goog.isDef(feature)) {
|
||||||
return [feature];
|
return [feature];
|
||||||
} else {
|
} else {
|
||||||
@@ -1561,7 +1576,7 @@ ol.format.KML.prototype.readFeaturesFromNode = function(node) {
|
|||||||
var n;
|
var n;
|
||||||
for (n = node.firstElementChild; !goog.isNull(n);
|
for (n = node.firstElementChild; !goog.isNull(n);
|
||||||
n = n.nextElementSibling) {
|
n = n.nextElementSibling) {
|
||||||
var fs = this.readFeaturesFromNode(n);
|
var fs = this.readFeaturesFromNode(n, opt_options);
|
||||||
if (goog.isDef(fs)) {
|
if (goog.isDef(fs)) {
|
||||||
goog.array.extend(features, fs);
|
goog.array.extend(features, fs);
|
||||||
}
|
}
|
||||||
@@ -1655,7 +1670,7 @@ ol.format.KML.prototype.readProjection;
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.KML.prototype.readProjectionFromDocument = function(doc) {
|
ol.format.KML.prototype.readProjectionFromDocument = function(doc) {
|
||||||
return ol.proj.get('EPSG:4326');
|
return this.defaultDataProjection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1663,7 +1678,7 @@ ol.format.KML.prototype.readProjectionFromDocument = function(doc) {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.KML.prototype.readProjectionFromNode = function(node) {
|
ol.format.KML.prototype.readProjectionFromNode = function(node) {
|
||||||
return ol.proj.get('EPSG:4326');
|
return this.defaultDataProjection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1963,9 +1978,14 @@ ol.format.KML.writePlacemark_ = function(node, feature, objectStack) {
|
|||||||
ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
|
ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
|
||||||
|
|
||||||
// serialize geometry
|
// serialize geometry
|
||||||
|
var options = /** @type {olx.format.WriteOptions} */ (objectStack[0]);
|
||||||
|
var geometry = feature.getGeometry();
|
||||||
|
if (goog.isDefAndNotNull(geometry)) {
|
||||||
|
geometry =
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, true, options);
|
||||||
|
}
|
||||||
ol.xml.pushSerializeAndPop(context, ol.format.KML.PLACEMARK_SERIALIZERS_,
|
ol.xml.pushSerializeAndPop(context, ol.format.KML.PLACEMARK_SERIALIZERS_,
|
||||||
ol.format.KML.GEOMETRY_NODE_FACTORY_,
|
ol.format.KML.GEOMETRY_NODE_FACTORY_, [geometry], objectStack);
|
||||||
[feature.getGeometry()], objectStack);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -2504,6 +2524,7 @@ ol.format.KML.OUTER_BOUNDARY_NODE_FACTORY_ =
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {Array.<ol.Feature>} features Features.
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Options.
|
||||||
* @return {Node} Result.
|
* @return {Node} Result.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -2513,7 +2534,7 @@ ol.format.KML.prototype.writeFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.KML.prototype.writeFeaturesNode = function(features) {
|
ol.format.KML.prototype.writeFeaturesNode = function(features, opt_options) {
|
||||||
var kml = ol.xml.createElementNS(ol.format.KML.NAMESPACE_URIS_[4], 'kml');
|
var kml = ol.xml.createElementNS(ol.format.KML.NAMESPACE_URIS_[4], 'kml');
|
||||||
var xmlnsUri = 'http://www.w3.org/2000/xmlns/';
|
var xmlnsUri = 'http://www.w3.org/2000/xmlns/';
|
||||||
var xmlSchemaInstanceUri = 'http://www.w3.org/2001/XMLSchema-instance';
|
var xmlSchemaInstanceUri = 'http://www.w3.org/2001/XMLSchema-instance';
|
||||||
@@ -2533,6 +2554,6 @@ ol.format.KML.prototype.writeFeaturesNode = function(features) {
|
|||||||
var orderedKeys = ol.format.KML.KML_SEQUENCE_[kml.namespaceURI];
|
var orderedKeys = ol.format.KML.KML_SEQUENCE_[kml.namespaceURI];
|
||||||
var values = ol.xml.makeSequence(properties, orderedKeys);
|
var values = ol.xml.makeSequence(properties, orderedKeys);
|
||||||
ol.xml.pushSerializeAndPop(context, ol.format.KML.KML_SERIALIZERS_,
|
ol.xml.pushSerializeAndPop(context, ol.format.KML.KML_SERIALIZERS_,
|
||||||
ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, [], orderedKeys);
|
ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, [opt_options], orderedKeys);
|
||||||
return kml;
|
return kml;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.dom.NodeType');
|
goog.require('goog.dom.NodeType');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.XMLFeature');
|
goog.require('ol.format.XMLFeature');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
@@ -26,6 +27,11 @@ goog.require('ol.xml');
|
|||||||
*/
|
*/
|
||||||
ol.format.OSMXML = function() {
|
ol.format.OSMXML = function() {
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
this.defaultDataProjection = ol.proj.get('EPSG:4326');
|
||||||
};
|
};
|
||||||
goog.inherits(ol.format.OSMXML, ol.format.XMLFeature);
|
goog.inherits(ol.format.OSMXML, ol.format.XMLFeature);
|
||||||
|
|
||||||
@@ -54,6 +60,7 @@ ol.format.OSMXML.prototype.getExtensions = function() {
|
|||||||
ol.format.OSMXML.readNode_ = function(node, objectStack) {
|
ol.format.OSMXML.readNode_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'node');
|
goog.asserts.assert(node.localName == 'node');
|
||||||
|
var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
|
||||||
var state = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
var state = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
||||||
var id = node.getAttribute('id');
|
var id = node.getAttribute('id');
|
||||||
var coordinates = /** @type {Array.<number>} */ ([
|
var coordinates = /** @type {Array.<number>} */ ([
|
||||||
@@ -67,6 +74,7 @@ ol.format.OSMXML.readNode_ = function(node, objectStack) {
|
|||||||
}, ol.format.OSMXML.NODE_PARSERS_, node, objectStack);
|
}, ol.format.OSMXML.NODE_PARSERS_, node, objectStack);
|
||||||
if (!goog.object.isEmpty(values.tags)) {
|
if (!goog.object.isEmpty(values.tags)) {
|
||||||
var geometry = new ol.geom.Point(coordinates);
|
var geometry = new ol.geom.Point(coordinates);
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, false, options);
|
||||||
var feature = new ol.Feature(geometry);
|
var feature = new ol.Feature(geometry);
|
||||||
feature.setId(id);
|
feature.setId(id);
|
||||||
feature.setProperties(values.tags);
|
feature.setProperties(values.tags);
|
||||||
@@ -83,6 +91,7 @@ ol.format.OSMXML.readNode_ = function(node, objectStack) {
|
|||||||
ol.format.OSMXML.readWay_ = function(node, objectStack) {
|
ol.format.OSMXML.readWay_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'way');
|
goog.asserts.assert(node.localName == 'way');
|
||||||
|
var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
|
||||||
var id = node.getAttribute('id');
|
var id = node.getAttribute('id');
|
||||||
var values = ol.xml.pushParseAndPop({
|
var values = ol.xml.pushParseAndPop({
|
||||||
ndrefs: [],
|
ndrefs: [],
|
||||||
@@ -104,6 +113,7 @@ ol.format.OSMXML.readWay_ = function(node, objectStack) {
|
|||||||
geometry = new ol.geom.LineString(null);
|
geometry = new ol.geom.LineString(null);
|
||||||
geometry.setFlatCoordinates(ol.geom.GeometryLayout.XY, flatCoordinates);
|
geometry.setFlatCoordinates(ol.geom.GeometryLayout.XY, flatCoordinates);
|
||||||
}
|
}
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, false, options);
|
||||||
var feature = new ol.Feature(geometry);
|
var feature = new ol.Feature(geometry);
|
||||||
feature.setId(id);
|
feature.setId(id);
|
||||||
feature.setProperties(values.tags);
|
feature.setProperties(values.tags);
|
||||||
@@ -189,6 +199,7 @@ ol.format.OSMXML.NODE_PARSERS_ = ol.xml.makeParsersNS(
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -198,13 +209,14 @@ ol.format.OSMXML.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.OSMXML.prototype.readFeaturesFromNode = function(node) {
|
ol.format.OSMXML.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
|
var options = this.getReadOptions(node, opt_options);
|
||||||
if (node.localName == 'osm') {
|
if (node.localName == 'osm') {
|
||||||
var state = ol.xml.pushParseAndPop({
|
var state = ol.xml.pushParseAndPop({
|
||||||
nodes: {},
|
nodes: {},
|
||||||
features: []
|
features: []
|
||||||
}, ol.format.OSMXML.PARSERS_, node, []);
|
}, ol.format.OSMXML.PARSERS_, node, [options]);
|
||||||
if (goog.isDef(state.features)) {
|
if (goog.isDef(state.features)) {
|
||||||
return state.features;
|
return state.features;
|
||||||
}
|
}
|
||||||
@@ -228,7 +240,7 @@ ol.format.OSMXML.prototype.readProjection;
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.OSMXML.prototype.readProjectionFromDocument = function(doc) {
|
ol.format.OSMXML.prototype.readProjectionFromDocument = function(doc) {
|
||||||
return ol.proj.get('EPSG:4326');
|
return this.defaultDataProjection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -236,5 +248,5 @@ ol.format.OSMXML.prototype.readProjectionFromDocument = function(doc) {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.OSMXML.prototype.readProjectionFromNode = function(node) {
|
ol.format.OSMXML.prototype.readProjectionFromNode = function(node) {
|
||||||
return ol.proj.get('EPSG:4326');
|
return this.defaultDataProjection;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ goog.provide('ol.format.Polyline');
|
|||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.TextFeature');
|
goog.require('ol.format.TextFeature');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.flat.inflate');
|
goog.require('ol.geom.flat.inflate');
|
||||||
@@ -22,6 +23,11 @@ ol.format.Polyline = function(opt_options) {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
this.defaultDataProjection = ol.proj.get('EPSG:4326');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -248,6 +254,7 @@ ol.format.Polyline.encodeUnsignedInteger = function(num) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -257,8 +264,8 @@ ol.format.Polyline.prototype.readFeature;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.Polyline.prototype.readFeatureFromText = function(text) {
|
ol.format.Polyline.prototype.readFeatureFromText = function(text, opt_options) {
|
||||||
var geometry = this.readGeometryFromText(text);
|
var geometry = this.readGeometryFromText(text, opt_options);
|
||||||
return new ol.Feature(geometry);
|
return new ol.Feature(geometry);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -269,6 +276,7 @@ ol.format.Polyline.prototype.readFeatureFromText = function(text) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -278,8 +286,9 @@ ol.format.Polyline.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.Polyline.prototype.readFeaturesFromText = function(text) {
|
ol.format.Polyline.prototype.readFeaturesFromText =
|
||||||
var feature = this.readFeatureFromText(text);
|
function(text, opt_options) {
|
||||||
|
var feature = this.readFeatureFromText(text, opt_options);
|
||||||
return [feature];
|
return [feature];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -289,6 +298,7 @@ ol.format.Polyline.prototype.readFeaturesFromText = function(text) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -298,11 +308,16 @@ ol.format.Polyline.prototype.readGeometry;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.Polyline.prototype.readGeometryFromText = function(text) {
|
ol.format.Polyline.prototype.readGeometryFromText =
|
||||||
|
function(text, opt_options) {
|
||||||
var flatCoordinates = ol.format.Polyline.decodeDeltas(text, 2, this.factor_);
|
var flatCoordinates = ol.format.Polyline.decodeDeltas(text, 2, this.factor_);
|
||||||
var coordinates = ol.geom.flat.inflate.coordinates(
|
var coordinates = ol.geom.flat.inflate.coordinates(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2);
|
flatCoordinates, 0, flatCoordinates.length, 2);
|
||||||
return new ol.geom.LineString(coordinates);
|
|
||||||
|
return /** @type {ol.geom.Geometry} */ (
|
||||||
|
ol.format.Feature.transformWithOptions(
|
||||||
|
new ol.geom.LineString(coordinates), false,
|
||||||
|
this.adaptOptions(opt_options)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -321,17 +336,17 @@ ol.format.Polyline.prototype.readProjection;
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.Polyline.prototype.readProjectionFromText = function(text) {
|
ol.format.Polyline.prototype.readProjectionFromText = function(text) {
|
||||||
return ol.proj.get('EPSG:4326');
|
return this.defaultDataProjection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.Polyline.prototype.writeFeatureText = function(feature) {
|
ol.format.Polyline.prototype.writeFeatureText = function(feature, opt_options) {
|
||||||
var geometry = feature.getGeometry();
|
var geometry = feature.getGeometry();
|
||||||
if (goog.isDefAndNotNull(geometry)) {
|
if (goog.isDefAndNotNull(geometry)) {
|
||||||
return this.writeGeometryText(geometry);
|
return this.writeGeometryText(geometry, opt_options);
|
||||||
} else {
|
} else {
|
||||||
goog.asserts.fail();
|
goog.asserts.fail();
|
||||||
return '';
|
return '';
|
||||||
@@ -342,9 +357,10 @@ ol.format.Polyline.prototype.writeFeatureText = function(feature) {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.Polyline.prototype.writeFeaturesText = function(features) {
|
ol.format.Polyline.prototype.writeFeaturesText =
|
||||||
|
function(features, opt_options) {
|
||||||
goog.asserts.assert(features.length == 1);
|
goog.asserts.assert(features.length == 1);
|
||||||
return this.writeFeatureText(features[0]);
|
return this.writeFeatureText(features[0], opt_options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -353,6 +369,7 @@ ol.format.Polyline.prototype.writeFeaturesText = function(features) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @return {string} Geometry.
|
* @return {string} Geometry.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -362,8 +379,12 @@ ol.format.Polyline.prototype.writeGeometry;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.Polyline.prototype.writeGeometryText = function(geometry) {
|
ol.format.Polyline.prototype.writeGeometryText =
|
||||||
|
function(geometry, opt_options) {
|
||||||
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
||||||
|
geometry = /** @type {ol.geom.LineString} */
|
||||||
|
(ol.format.Feature.transformWithOptions(
|
||||||
|
geometry, true, this.adaptOptions(opt_options)));
|
||||||
var flatCoordinates = geometry.getFlatCoordinates();
|
var flatCoordinates = geometry.getFlatCoordinates();
|
||||||
var stride = geometry.getStride();
|
var stride = geometry.getStride();
|
||||||
return ol.format.Polyline.encodeDeltas(flatCoordinates, stride, this.factor_);
|
return ol.format.Polyline.encodeDeltas(flatCoordinates, stride, this.factor_);
|
||||||
|
|||||||
@@ -47,13 +47,15 @@ ol.format.TextFeature.prototype.getType = function() {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.TextFeature.prototype.readFeature = function(source) {
|
ol.format.TextFeature.prototype.readFeature = function(source, opt_options) {
|
||||||
return this.readFeatureFromText(this.getText_(source));
|
return this.readFeatureFromText(
|
||||||
|
this.getText_(source), this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} text Text.
|
* @param {string} text Text.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
*/
|
*/
|
||||||
@@ -63,13 +65,15 @@ ol.format.TextFeature.prototype.readFeatureFromText = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.TextFeature.prototype.readFeatures = function(source) {
|
ol.format.TextFeature.prototype.readFeatures = function(source, opt_options) {
|
||||||
return this.readFeaturesFromText(this.getText_(source));
|
return this.readFeaturesFromText(
|
||||||
|
this.getText_(source), this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} text Text.
|
* @param {string} text Text.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
*/
|
*/
|
||||||
@@ -79,13 +83,15 @@ ol.format.TextFeature.prototype.readFeaturesFromText = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.TextFeature.prototype.readGeometry = function(source) {
|
ol.format.TextFeature.prototype.readGeometry = function(source, opt_options) {
|
||||||
return this.readGeometryFromText(this.getText_(source));
|
return this.readGeometryFromText(
|
||||||
|
this.getText_(source), this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} text Text.
|
* @param {string} text Text.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
@@ -111,13 +117,14 @@ ol.format.TextFeature.prototype.readProjectionFromText = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.TextFeature.prototype.writeFeature = function(feature) {
|
ol.format.TextFeature.prototype.writeFeature = function(feature, opt_options) {
|
||||||
return this.writeFeatureText(feature);
|
return this.writeFeatureText(feature, this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Features.
|
* @param {ol.Feature} feature Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {string} Text.
|
* @return {string} Text.
|
||||||
*/
|
*/
|
||||||
@@ -127,13 +134,15 @@ ol.format.TextFeature.prototype.writeFeatureText = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.TextFeature.prototype.writeFeatures = function(features) {
|
ol.format.TextFeature.prototype.writeFeatures = function(
|
||||||
return this.writeFeaturesText(features);
|
features, opt_options) {
|
||||||
|
return this.writeFeaturesText(features, this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array.<ol.Feature>} features Features.
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {string} Text.
|
* @return {string} Text.
|
||||||
*/
|
*/
|
||||||
@@ -143,13 +152,15 @@ ol.format.TextFeature.prototype.writeFeaturesText = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.TextFeature.prototype.writeGeometry = function(geometry) {
|
ol.format.TextFeature.prototype.writeGeometry = function(
|
||||||
return this.writeGeometryText(geometry);
|
geometry, opt_options) {
|
||||||
|
return this.writeGeometryText(geometry, this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {string} Text.
|
* @return {string} Text.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ goog.provide('ol.format.TopoJSON');
|
|||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.JSONFeature');
|
goog.require('ol.format.JSONFeature');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.MultiLineString');
|
goog.require('ol.geom.MultiLineString');
|
||||||
@@ -30,11 +31,11 @@ ol.format.TopoJSON = function(opt_options) {
|
|||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @inheritDoc
|
||||||
* @type {ol.proj.Projection}
|
|
||||||
*/
|
*/
|
||||||
this.defaultProjection_ =
|
this.defaultDataProjection = ol.proj.get(
|
||||||
ol.proj.get(options.defaultProjection || 'EPSG:4326');
|
goog.isDefAndNotNull(options.defaultDataProjection) ?
|
||||||
|
options.defaultDataProjection : 'EPSG:4326');
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.format.TopoJSON, ol.format.JSONFeature);
|
goog.inherits(ol.format.TopoJSON, ol.format.JSONFeature);
|
||||||
@@ -217,17 +218,18 @@ ol.format.TopoJSON.prototype.getExtensions = function() {
|
|||||||
* @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
|
* @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
|
||||||
* @param {Array.<number>} scale Scale for each dimension.
|
* @param {Array.<number>} scale Scale for each dimension.
|
||||||
* @param {Array.<number>} translate Translation for each dimension.
|
* @param {Array.<number>} translate Translation for each dimension.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Array of features.
|
* @return {Array.<ol.Feature>} Array of features.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.TopoJSON.readFeaturesFromGeometryCollection_ = function(
|
ol.format.TopoJSON.readFeaturesFromGeometryCollection_ = function(
|
||||||
collection, arcs, scale, translate) {
|
collection, arcs, scale, translate, opt_options) {
|
||||||
var geometries = collection.geometries;
|
var geometries = collection.geometries;
|
||||||
var features = [];
|
var features = [];
|
||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
features[i] = ol.format.TopoJSON.readFeatureFromGeometry_(
|
features[i] = ol.format.TopoJSON.readFeatureFromGeometry_(
|
||||||
geometries[i], arcs, scale, translate);
|
geometries[i], arcs, scale, translate, opt_options);
|
||||||
}
|
}
|
||||||
return features;
|
return features;
|
||||||
};
|
};
|
||||||
@@ -240,11 +242,12 @@ ol.format.TopoJSON.readFeaturesFromGeometryCollection_ = function(
|
|||||||
* @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
|
* @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
|
||||||
* @param {Array.<number>} scale Scale for each dimension.
|
* @param {Array.<number>} scale Scale for each dimension.
|
||||||
* @param {Array.<number>} translate Translation for each dimension.
|
* @param {Array.<number>} translate Translation for each dimension.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.TopoJSON.readFeatureFromGeometry_ = function(object, arcs,
|
ol.format.TopoJSON.readFeatureFromGeometry_ = function(object, arcs,
|
||||||
scale, translate) {
|
scale, translate, opt_options) {
|
||||||
var geometry;
|
var geometry;
|
||||||
var type = object.type;
|
var type = object.type;
|
||||||
var geometryReader = ol.format.TopoJSON.GEOMETRY_READERS_[type];
|
var geometryReader = ol.format.TopoJSON.GEOMETRY_READERS_[type];
|
||||||
@@ -255,7 +258,8 @@ ol.format.TopoJSON.readFeatureFromGeometry_ = function(object, arcs,
|
|||||||
geometry = geometryReader(object, arcs);
|
geometry = geometryReader(object, arcs);
|
||||||
}
|
}
|
||||||
var feature = new ol.Feature();
|
var feature = new ol.Feature();
|
||||||
feature.setGeometry(geometry);
|
feature.setGeometry(/** @type {ol.geom.Geometry} */ (
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, false, opt_options)));
|
||||||
if (goog.isDef(object.id)) {
|
if (goog.isDef(object.id)) {
|
||||||
feature.setId(object.id);
|
feature.setId(object.id);
|
||||||
}
|
}
|
||||||
@@ -280,7 +284,8 @@ ol.format.TopoJSON.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.TopoJSON.prototype.readFeaturesFromObject = function(object) {
|
ol.format.TopoJSON.prototype.readFeaturesFromObject = function(
|
||||||
|
object, opt_options) {
|
||||||
if (object.type == 'Topology') {
|
if (object.type == 'Topology') {
|
||||||
var topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
|
var topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
|
||||||
var transform, scale = null, translate = null;
|
var transform, scale = null, translate = null;
|
||||||
@@ -305,12 +310,12 @@ ol.format.TopoJSON.prototype.readFeaturesFromObject = function(object) {
|
|||||||
(topoJSONFeatures[i]);
|
(topoJSONFeatures[i]);
|
||||||
features.push.apply(features,
|
features.push.apply(features,
|
||||||
ol.format.TopoJSON.readFeaturesFromGeometryCollection_(
|
ol.format.TopoJSON.readFeaturesFromGeometryCollection_(
|
||||||
feature, arcs, scale, translate));
|
feature, arcs, scale, translate, opt_options));
|
||||||
} else {
|
} else {
|
||||||
feature = /** @type {TopoJSONGeometry} */
|
feature = /** @type {TopoJSONGeometry} */
|
||||||
(topoJSONFeatures[i]);
|
(topoJSONFeatures[i]);
|
||||||
features.push(ol.format.TopoJSON.readFeatureFromGeometry_(
|
features.push(ol.format.TopoJSON.readFeatureFromGeometry_(
|
||||||
feature, arcs, scale, translate));
|
feature, arcs, scale, translate, opt_options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return features;
|
return features;
|
||||||
@@ -385,7 +390,7 @@ ol.format.TopoJSON.transformVertex_ = function(vertex, scale, translate) {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.format.TopoJSON.prototype.readProjection = function(object) {
|
ol.format.TopoJSON.prototype.readProjection = function(object) {
|
||||||
return this.defaultProjection_;
|
return this.defaultDataProjection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ ol.format.WFS.schemaLocation_ = 'http://www.opengis.net/wfs ' +
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -109,11 +110,14 @@ ol.format.WFS.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.WFS.prototype.readFeaturesFromNode = function(node) {
|
ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||||
var objectStack = [{
|
var context = {
|
||||||
'featureType': this.featureType_,
|
'featureType': this.featureType_,
|
||||||
'featureNS': this.featureNS_
|
'featureNS': this.featureNS_
|
||||||
}];
|
};
|
||||||
|
goog.object.extend(context, this.getReadOptions(node,
|
||||||
|
goog.isDef(opt_options) ? opt_options : {}));
|
||||||
|
var objectStack = [context];
|
||||||
var features = ol.xml.pushParseAndPop([],
|
var features = ol.xml.pushParseAndPop([],
|
||||||
ol.format.GML.FEATURE_COLLECTION_PARSERS, node, objectStack);
|
ol.format.GML.FEATURE_COLLECTION_PARSERS, node, objectStack);
|
||||||
if (!goog.isDef(features)) {
|
if (!goog.isDef(features)) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ goog.provide('ol.format.WKT');
|
|||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.TextFeature');
|
goog.require('ol.format.TextFeature');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.GeometryCollection');
|
goog.require('ol.geom.GeometryCollection');
|
||||||
@@ -208,6 +209,7 @@ ol.format.WKT.prototype.parse_ = function(wkt) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -217,8 +219,8 @@ ol.format.WKT.prototype.readFeature;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.WKT.prototype.readFeatureFromText = function(text) {
|
ol.format.WKT.prototype.readFeatureFromText = function(text, opt_options) {
|
||||||
var geom = this.readGeometryFromText(text);
|
var geom = this.readGeometryFromText(text, opt_options);
|
||||||
if (goog.isDef(geom)) {
|
if (goog.isDef(geom)) {
|
||||||
var feature = new ol.Feature();
|
var feature = new ol.Feature();
|
||||||
feature.setGeometry(geom);
|
feature.setGeometry(geom);
|
||||||
@@ -233,6 +235,7 @@ ol.format.WKT.prototype.readFeatureFromText = function(text) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -242,9 +245,9 @@ ol.format.WKT.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.WKT.prototype.readFeaturesFromText = function(text) {
|
ol.format.WKT.prototype.readFeaturesFromText = function(text, opt_options) {
|
||||||
var geometries = [];
|
var geometries = [];
|
||||||
var geometry = this.readGeometryFromText(text);
|
var geometry = this.readGeometryFromText(text, opt_options);
|
||||||
if (this.splitCollection_ &&
|
if (this.splitCollection_ &&
|
||||||
geometry.getType() == ol.geom.GeometryType.GEOMETRY_COLLECTION) {
|
geometry.getType() == ol.geom.GeometryType.GEOMETRY_COLLECTION) {
|
||||||
geometries = (/** @type {ol.geom.GeometryCollection} */ (geometry))
|
geometries = (/** @type {ol.geom.GeometryCollection} */ (geometry))
|
||||||
@@ -267,6 +270,7 @@ ol.format.WKT.prototype.readFeaturesFromText = function(text) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -276,8 +280,14 @@ ol.format.WKT.prototype.readGeometry;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.WKT.prototype.readGeometryFromText = function(text) {
|
ol.format.WKT.prototype.readGeometryFromText = function(text, opt_options) {
|
||||||
return this.parse_(text) || null;
|
var geometry = this.parse_(text);
|
||||||
|
if (goog.isDef(geometry)) {
|
||||||
|
return /** @type {ol.geom.Geometry} */ (
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, false, opt_options));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -294,6 +304,7 @@ ol.format.WKT.prototype.readProjectionFromText = function(text) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @return {string} WKT string.
|
* @return {string} WKT string.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -303,10 +314,10 @@ ol.format.WKT.prototype.writeFeature;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.WKT.prototype.writeFeatureText = function(feature) {
|
ol.format.WKT.prototype.writeFeatureText = function(feature, opt_options) {
|
||||||
var geometry = feature.getGeometry();
|
var geometry = feature.getGeometry();
|
||||||
if (goog.isDef(geometry)) {
|
if (goog.isDef(geometry)) {
|
||||||
return this.writeGeometryText(geometry);
|
return this.writeGeometryText(geometry, opt_options);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
@@ -317,6 +328,7 @@ ol.format.WKT.prototype.writeFeatureText = function(feature) {
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {Array.<ol.Feature>} features Features.
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
* @return {string} WKT string.
|
* @return {string} WKT string.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -326,16 +338,16 @@ ol.format.WKT.prototype.writeFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.WKT.prototype.writeFeaturesText = function(features) {
|
ol.format.WKT.prototype.writeFeaturesText = function(features, opt_options) {
|
||||||
if (features.length == 1) {
|
if (features.length == 1) {
|
||||||
return this.writeFeatureText(features[0]);
|
return this.writeFeatureText(features[0], opt_options);
|
||||||
}
|
}
|
||||||
var geometries = [];
|
var geometries = [];
|
||||||
for (var i = 0, ii = features.length; i < ii; ++i) {
|
for (var i = 0, ii = features.length; i < ii; ++i) {
|
||||||
geometries.push(features[i].getGeometry());
|
geometries.push(features[i].getGeometry());
|
||||||
}
|
}
|
||||||
var collection = new ol.geom.GeometryCollection(geometries);
|
var collection = new ol.geom.GeometryCollection(geometries);
|
||||||
return this.writeGeometryText(collection);
|
return this.writeGeometryText(collection, opt_options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -353,8 +365,9 @@ ol.format.WKT.prototype.writeGeometry;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.WKT.prototype.writeGeometryText = function(geometry) {
|
ol.format.WKT.prototype.writeGeometryText = function(geometry, opt_options) {
|
||||||
return ol.format.WKT.encode_(geometry);
|
return ol.format.WKT.encode_(/** @type {ol.geom.Geometry} */ (
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, true, opt_options)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.dom.NodeType');
|
goog.require('goog.dom.NodeType');
|
||||||
goog.require('ol.format.Feature');
|
goog.require('ol.format.Feature');
|
||||||
goog.require('ol.format.FormatType');
|
goog.require('ol.format.FormatType');
|
||||||
|
goog.require('ol.proj');
|
||||||
goog.require('ol.xml');
|
goog.require('ol.xml');
|
||||||
|
|
||||||
|
|
||||||
@@ -35,14 +36,15 @@ ol.format.XMLFeature.prototype.getType = function() {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.XMLFeature.prototype.readFeature = function(source) {
|
ol.format.XMLFeature.prototype.readFeature = function(source, opt_options) {
|
||||||
if (ol.xml.isDocument(source)) {
|
if (ol.xml.isDocument(source)) {
|
||||||
return this.readFeatureFromDocument(/** @type {Document} */ (source));
|
return this.readFeatureFromDocument(
|
||||||
|
/** @type {Document} */ (source), opt_options);
|
||||||
} else if (ol.xml.isNode(source)) {
|
} else if (ol.xml.isNode(source)) {
|
||||||
return this.readFeatureFromNode(/** @type {Node} */ (source));
|
return this.readFeatureFromNode(/** @type {Node} */ (source), opt_options);
|
||||||
} else if (goog.isString(source)) {
|
} else if (goog.isString(source)) {
|
||||||
var doc = ol.xml.load(source);
|
var doc = ol.xml.load(source);
|
||||||
return this.readFeatureFromDocument(doc);
|
return this.readFeatureFromDocument(doc, opt_options);
|
||||||
} else {
|
} else {
|
||||||
goog.asserts.fail();
|
goog.asserts.fail();
|
||||||
return null;
|
return null;
|
||||||
@@ -52,10 +54,12 @@ ol.format.XMLFeature.prototype.readFeature = function(source) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Document} doc Document.
|
* @param {Document} doc Document.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
*/
|
*/
|
||||||
ol.format.XMLFeature.prototype.readFeatureFromDocument = function(doc) {
|
ol.format.XMLFeature.prototype.readFeatureFromDocument = function(
|
||||||
var features = this.readFeaturesFromDocument(doc);
|
doc, opt_options) {
|
||||||
|
var features = this.readFeaturesFromDocument(doc, opt_options);
|
||||||
if (features.length > 0) {
|
if (features.length > 0) {
|
||||||
return features[0];
|
return features[0];
|
||||||
} else {
|
} else {
|
||||||
@@ -66,6 +70,7 @@ ol.format.XMLFeature.prototype.readFeatureFromDocument = function(doc) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Options.
|
||||||
* @return {ol.Feature} Feature.
|
* @return {ol.Feature} Feature.
|
||||||
*/
|
*/
|
||||||
ol.format.XMLFeature.prototype.readFeatureFromNode = goog.abstractMethod;
|
ol.format.XMLFeature.prototype.readFeatureFromNode = goog.abstractMethod;
|
||||||
@@ -74,14 +79,15 @@ ol.format.XMLFeature.prototype.readFeatureFromNode = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.XMLFeature.prototype.readFeatures = function(source) {
|
ol.format.XMLFeature.prototype.readFeatures = function(source, opt_options) {
|
||||||
if (ol.xml.isDocument(source)) {
|
if (ol.xml.isDocument(source)) {
|
||||||
return this.readFeaturesFromDocument(/** @type {Document} */ (source));
|
return this.readFeaturesFromDocument(
|
||||||
|
/** @type {Document} */ (source), opt_options);
|
||||||
} else if (ol.xml.isNode(source)) {
|
} else if (ol.xml.isNode(source)) {
|
||||||
return this.readFeaturesFromNode(/** @type {Node} */ (source));
|
return this.readFeaturesFromNode(/** @type {Node} */ (source), opt_options);
|
||||||
} else if (goog.isString(source)) {
|
} else if (goog.isString(source)) {
|
||||||
var doc = ol.xml.load(source);
|
var doc = ol.xml.load(source);
|
||||||
return this.readFeaturesFromDocument(doc);
|
return this.readFeaturesFromDocument(doc, opt_options);
|
||||||
} else {
|
} else {
|
||||||
goog.asserts.fail();
|
goog.asserts.fail();
|
||||||
return [];
|
return [];
|
||||||
@@ -91,16 +97,18 @@ ol.format.XMLFeature.prototype.readFeatures = function(source) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Document} doc Document.
|
* @param {Document} doc Document.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
*/
|
*/
|
||||||
ol.format.XMLFeature.prototype.readFeaturesFromDocument = function(doc) {
|
ol.format.XMLFeature.prototype.readFeaturesFromDocument = function(
|
||||||
|
doc, opt_options) {
|
||||||
/** @type {Array.<ol.Feature>} */
|
/** @type {Array.<ol.Feature>} */
|
||||||
var features = [];
|
var features = [];
|
||||||
var n;
|
var n;
|
||||||
for (n = doc.firstChild; !goog.isNull(n); n = n.nextSibling) {
|
for (n = doc.firstChild; !goog.isNull(n); n = n.nextSibling) {
|
||||||
if (n.nodeType == goog.dom.NodeType.ELEMENT) {
|
if (n.nodeType == goog.dom.NodeType.ELEMENT) {
|
||||||
goog.array.extend(features, this.readFeaturesFromNode(n));
|
goog.array.extend(features, this.readFeaturesFromNode(n, opt_options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return features;
|
return features;
|
||||||
@@ -109,6 +117,7 @@ ol.format.XMLFeature.prototype.readFeaturesFromDocument = function(doc) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
*/
|
*/
|
||||||
@@ -118,14 +127,15 @@ ol.format.XMLFeature.prototype.readFeaturesFromNode = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.XMLFeature.prototype.readGeometry = function(source) {
|
ol.format.XMLFeature.prototype.readGeometry = function(source, opt_options) {
|
||||||
if (ol.xml.isDocument(source)) {
|
if (ol.xml.isDocument(source)) {
|
||||||
return this.readGeometryFromDocument(/** @type {Document} */ (source));
|
return this.readGeometryFromDocument(
|
||||||
|
/** @type {Document} */ (source), opt_options);
|
||||||
} else if (ol.xml.isNode(source)) {
|
} else if (ol.xml.isNode(source)) {
|
||||||
return this.readGeometryFromNode(/** @type {Node} */ (source));
|
return this.readGeometryFromNode(/** @type {Node} */ (source), opt_options);
|
||||||
} else if (goog.isString(source)) {
|
} else if (goog.isString(source)) {
|
||||||
var doc = ol.xml.load(source);
|
var doc = ol.xml.load(source);
|
||||||
return this.readGeometryFromDocument(doc);
|
return this.readGeometryFromDocument(doc, opt_options);
|
||||||
} else {
|
} else {
|
||||||
goog.asserts.fail();
|
goog.asserts.fail();
|
||||||
return null;
|
return null;
|
||||||
@@ -135,6 +145,7 @@ ol.format.XMLFeature.prototype.readGeometry = function(source) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Document} doc Document.
|
* @param {Document} doc Document.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
@@ -143,6 +154,7 @@ ol.format.XMLFeature.prototype.readGeometryFromDocument = goog.abstractMethod;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
@@ -186,13 +198,14 @@ ol.format.XMLFeature.prototype.readProjectionFromNode = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.XMLFeature.prototype.writeFeature = function(feature) {
|
ol.format.XMLFeature.prototype.writeFeature = function(feature, opt_options) {
|
||||||
return this.writeFeatureNode(feature);
|
return this.writeFeatureNode(feature, this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Node} Node.
|
* @return {Node} Node.
|
||||||
*/
|
*/
|
||||||
@@ -202,13 +215,14 @@ ol.format.XMLFeature.prototype.writeFeatureNode = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.XMLFeature.prototype.writeFeatures = function(features) {
|
ol.format.XMLFeature.prototype.writeFeatures = function(features, opt_options) {
|
||||||
return this.writeFeaturesNode(features);
|
return this.writeFeaturesNode(features, this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array.<ol.Feature>} features Features.
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Node} Node.
|
* @return {Node} Node.
|
||||||
*/
|
*/
|
||||||
@@ -218,13 +232,14 @@ ol.format.XMLFeature.prototype.writeFeaturesNode = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.XMLFeature.prototype.writeGeometry = function(geometry) {
|
ol.format.XMLFeature.prototype.writeGeometry = function(geometry, opt_options) {
|
||||||
return this.writeGeometryNode(geometry);
|
return this.writeGeometryNode(geometry, this.adaptOptions(opt_options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Options.
|
||||||
* @protected
|
* @protected
|
||||||
* @return {Node} Node.
|
* @return {Node} Node.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ ol.source.GeoJSON = function(opt_options) {
|
|||||||
attributions: options.attributions,
|
attributions: options.attributions,
|
||||||
extent: options.extent,
|
extent: options.extent,
|
||||||
format: new ol.format.GeoJSON({
|
format: new ol.format.GeoJSON({
|
||||||
defaultProjection: options.defaultProjection
|
defaultDataProjection: options.defaultProjection
|
||||||
}),
|
}),
|
||||||
logo: options.logo,
|
logo: options.logo,
|
||||||
object: options.object,
|
object: options.object,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ ol.source.TopoJSON = function(opt_options) {
|
|||||||
attributions: options.attributions,
|
attributions: options.attributions,
|
||||||
extent: options.extent,
|
extent: options.extent,
|
||||||
format: new ol.format.TopoJSON({
|
format: new ol.format.TopoJSON({
|
||||||
defaultProjection: options.defaultProjection
|
defaultDataProjection: options.defaultProjection
|
||||||
}),
|
}),
|
||||||
logo: options.logo,
|
logo: options.logo,
|
||||||
object: options.object,
|
object: options.object,
|
||||||
|
|||||||
@@ -174,6 +174,36 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
expect(features[2].getGeometry()).to.be.an(ol.geom.Polygon);
|
expect(features[2].getGeometry()).to.be.an(ol.geom.Polygon);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can read and transform a point', function() {
|
||||||
|
var feature = format.readFeatures(pointGeoJSON, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(feature[0].getGeometry()).to.be.an(ol.geom.Point);
|
||||||
|
expect(feature[0].getGeometry().getCoordinates()).to.eql(
|
||||||
|
ol.proj.transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can read and transform a feature collection', function() {
|
||||||
|
var features = format.readFeatures(featureCollectionGeoJSON, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(features[0].getGeometry()).to.be.an(ol.geom.Point);
|
||||||
|
expect(features[0].getGeometry().getCoordinates()).to.eql(
|
||||||
|
ol.proj.transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
|
||||||
|
expect(features[1].getGeometry().getCoordinates()).to.eql([
|
||||||
|
ol.proj.transform([102.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([103.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([104.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([105.0, 1.0], 'EPSG:4326', 'EPSG:3857')
|
||||||
|
]);
|
||||||
|
expect(features[2].getGeometry().getCoordinates()).to.eql([[
|
||||||
|
ol.proj.transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([100.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([101.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([101.0, 0.0], 'EPSG:4326', 'EPSG:3857')
|
||||||
|
]]);
|
||||||
|
});
|
||||||
|
|
||||||
it('can create a feature with a specific geometryName', function() {
|
it('can create a feature with a specific geometryName', function() {
|
||||||
var feature = new ol.format.GeoJSON({geometryName: 'the_geom'}).
|
var feature = new ol.format.GeoJSON({geometryName: 'the_geom'}).
|
||||||
readFeature(pointGeoJSON);
|
readFeature(pointGeoJSON);
|
||||||
@@ -452,6 +482,22 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms and encodes feature collection', function() {
|
||||||
|
var str = JSON.stringify(data),
|
||||||
|
array = format.readFeatures(str);
|
||||||
|
var geojson = format.writeFeatures(array, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
var result = format.readFeatures(geojson);
|
||||||
|
var got, exp;
|
||||||
|
for (var i = 0, ii = array.length; i < ii; ++i) {
|
||||||
|
got = array[i];
|
||||||
|
exp = result[i];
|
||||||
|
expect(got.getGeometry().transform('EPSG:3857', 'EPSG:4326')
|
||||||
|
.getCoordinates()).to.eql(exp.getGeometry().getCoordinates());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#writeGeometry', function() {
|
describe('#writeGeometry', function() {
|
||||||
@@ -507,6 +553,20 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms and encodes a point', function() {
|
||||||
|
var point = new ol.geom.Point([2, 3]);
|
||||||
|
var geojson = format.writeGeometry(point, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
var newPoint = format.readGeometry(geojson, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(point.getCoordinates()[0]).to.eql(newPoint.getCoordinates()[0]);
|
||||||
|
expect(
|
||||||
|
Math.abs(point.getCoordinates()[1] - newPoint.getCoordinates()[1]))
|
||||||
|
.to.be.lessThan(0.0000001);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
goog.provide('ol.test.format.GML');
|
goog.provide('ol.test.format.GML');
|
||||||
|
|
||||||
var readGeometry = function(format, text) {
|
var readGeometry = function(format, text, opt_options) {
|
||||||
var doc = ol.xml.load(text);
|
var doc = ol.xml.load(text);
|
||||||
// we need an intermediate node for testing purposes
|
// we need an intermediate node for testing purposes
|
||||||
var node = goog.dom.createElement(goog.dom.TagName.PRE);
|
var node = goog.dom.createElement(goog.dom.TagName.PRE);
|
||||||
node.appendChild(doc.documentElement);
|
node.appendChild(doc.documentElement);
|
||||||
return format.readGeometryFromNode(node);
|
return format.readGeometryFromNode(node, opt_options);
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('ol.format.GML', function() {
|
describe('ol.format.GML', function() {
|
||||||
|
|
||||||
var format, formatWGS84;
|
var format, formatWGS84, formatNoSrs;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
format = new ol.format.GML({srsName: 'CRS:84'});
|
format = new ol.format.GML({srsName: 'CRS:84'});
|
||||||
formatWGS84 = new ol.format.GML({srsName: 'urn:x-ogc:def:crs:EPSG:4326'});
|
formatWGS84 = new ol.format.GML({srsName: 'urn:x-ogc:def:crs:EPSG:4326'});
|
||||||
|
formatNoSrs = new ol.format.GML();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#readGeometry', function() {
|
describe('#readGeometry', function() {
|
||||||
@@ -33,6 +34,44 @@ describe('ol.format.GML', function() {
|
|||||||
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
|
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can read, transform and write a point geometry', function() {
|
||||||
|
var config = {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
};
|
||||||
|
var text =
|
||||||
|
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="CRS:84">' +
|
||||||
|
' <gml:pos>1 2</gml:pos>' +
|
||||||
|
'</gml:Point>';
|
||||||
|
var g = readGeometry(format, text, config);
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
var coordinates = g.getCoordinates();
|
||||||
|
expect(coordinates.splice(0, 2)).to.eql(
|
||||||
|
ol.proj.transform([1, 2], 'CRS:84', 'EPSG:3857'));
|
||||||
|
config.dataProjection = 'CRS:84';
|
||||||
|
var serialized = format.writeGeometry(g, config);
|
||||||
|
var pos = serialized.firstElementChild.firstElementChild.textContent;
|
||||||
|
var coordinate = pos.split(' ');
|
||||||
|
expect(coordinate[0]).to.roughlyEqual(1, 1e-9);
|
||||||
|
expect(coordinate[1]).to.roughlyEqual(2, 1e-9);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can detect SRS, read and transform a point geometry', function() {
|
||||||
|
var config = {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
};
|
||||||
|
var text =
|
||||||
|
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="CRS:84">' +
|
||||||
|
' <gml:pos>1 2</gml:pos>' +
|
||||||
|
'</gml:Point>';
|
||||||
|
var g = readGeometry(formatNoSrs, text, config);
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
var coordinates = g.getCoordinates();
|
||||||
|
expect(coordinates.splice(0, 2)).to.eql(
|
||||||
|
ol.proj.transform([1, 2], 'CRS:84', 'EPSG:3857'));
|
||||||
|
});
|
||||||
|
|
||||||
it('can read and write a point geometry in EPSG:4326', function() {
|
it('can read and write a point geometry in EPSG:4326', function() {
|
||||||
var text =
|
var text =
|
||||||
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
|
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
@@ -63,6 +102,32 @@ describe('ol.format.GML', function() {
|
|||||||
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
|
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can read, transform and write a linestring geometry', function() {
|
||||||
|
var config = {
|
||||||
|
dataProjection: 'CRS:84',
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
};
|
||||||
|
var text =
|
||||||
|
'<gml:LineString xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="CRS:84">' +
|
||||||
|
' <gml:posList>1 2 3 4</gml:posList>' +
|
||||||
|
'</gml:LineString>';
|
||||||
|
var g = readGeometry(format, text, config);
|
||||||
|
expect(g).to.be.an(ol.geom.LineString);
|
||||||
|
var coordinates = g.getCoordinates();
|
||||||
|
expect(coordinates[0].slice(0, 2)).to.eql(
|
||||||
|
ol.proj.transform([1, 2], 'CRS:84', 'EPSG:3857'));
|
||||||
|
expect(coordinates[1].slice(0, 2)).to.eql(
|
||||||
|
ol.proj.transform([3, 4], 'CRS:84', 'EPSG:3857'));
|
||||||
|
var serialized = format.writeGeometry(g, config);
|
||||||
|
var poss = serialized.firstElementChild.firstElementChild.textContent;
|
||||||
|
var coordinate = poss.split(' ');
|
||||||
|
expect(coordinate[0]).to.roughlyEqual(1, 1e-9);
|
||||||
|
expect(coordinate[1]).to.roughlyEqual(2, 1e-9);
|
||||||
|
expect(coordinate[2]).to.roughlyEqual(3, 1e-9);
|
||||||
|
expect(coordinate[3]).to.roughlyEqual(4, 1e-9);
|
||||||
|
});
|
||||||
|
|
||||||
it('can read and write a linestring geometry in EPSG:4326', function() {
|
it('can read and write a linestring geometry in EPSG:4326', function() {
|
||||||
var text =
|
var text =
|
||||||
'<gml:LineString xmlns:gml="http://www.opengis.net/gml" ' +
|
'<gml:LineString xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
@@ -779,7 +844,7 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
describe('when parsing more than one geometry', function() {
|
describe('when parsing more than one geometry', function() {
|
||||||
|
|
||||||
var features, feature;
|
var features;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
afterLoadText('spec/ol/format/gml/more-geoms.xml', function(xml) {
|
afterLoadText('spec/ol/format/gml/more-geoms.xml', function(xml) {
|
||||||
try {
|
try {
|
||||||
@@ -805,7 +870,7 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
describe('when parsing an attribute name equal to featureType', function() {
|
describe('when parsing an attribute name equal to featureType', function() {
|
||||||
|
|
||||||
var features, feature;
|
var features;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
afterLoadText('spec/ol/format/gml/repeated-name.xml', function(xml) {
|
afterLoadText('spec/ol/format/gml/repeated-name.xml', function(xml) {
|
||||||
try {
|
try {
|
||||||
@@ -842,3 +907,4 @@ goog.require('ol.geom.MultiPolygon');
|
|||||||
goog.require('ol.xml');
|
goog.require('ol.xml');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
goog.provide('ol.test.format.GPX');
|
goog.provide('ol.test.format.GPX');
|
||||||
|
|
||||||
|
|
||||||
describe('ol.format.GPX', function() {
|
describe('ol.format.GPX', function() {
|
||||||
|
|
||||||
var format;
|
var format;
|
||||||
@@ -80,6 +79,34 @@ describe('ol.format.GPX', function() {
|
|||||||
expect(serialized).to.xmleql(ol.xml.load(text));
|
expect(serialized).to.xmleql(ol.xml.load(text));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can transform, read and write a rte', function() {
|
||||||
|
var text =
|
||||||
|
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
|
||||||
|
' <rte>' +
|
||||||
|
' <rtept lat="1" lon="2"/>' +
|
||||||
|
' <rtept lat="5" lon="6"/>' +
|
||||||
|
' </rte>' +
|
||||||
|
'</gpx>';
|
||||||
|
var fs = format.readFeatures(text, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(fs).to.have.length(1);
|
||||||
|
var f = fs[0];
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var g = f.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.LineString);
|
||||||
|
var p1 = ol.proj.transform([2, 1], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
p1.push(0, 0);
|
||||||
|
var p2 = ol.proj.transform([6, 5], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
p2.push(0, 0);
|
||||||
|
expect(g.getCoordinates()).to.eql([p1, p2]);
|
||||||
|
expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM);
|
||||||
|
var serialized = format.writeFeatures(fs, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(serialized).to.xmleql(ol.xml.load(text));
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('trk', function() {
|
describe('trk', function() {
|
||||||
@@ -181,6 +208,42 @@ describe('ol.format.GPX', function() {
|
|||||||
expect(serialized).to.xmleql(ol.xml.load(text));
|
expect(serialized).to.xmleql(ol.xml.load(text));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can tranform, read and write a trk with a trkseg', function() {
|
||||||
|
var text =
|
||||||
|
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
|
||||||
|
' <trk>' +
|
||||||
|
' <trkseg>' +
|
||||||
|
' <trkpt lat="1" lon="2">' +
|
||||||
|
' <ele>3</ele>' +
|
||||||
|
' <time>2010-01-10T09:29:12Z</time>' +
|
||||||
|
' </trkpt>' +
|
||||||
|
' <trkpt lat="5" lon="6">' +
|
||||||
|
' <ele>7</ele>' +
|
||||||
|
' <time>2010-01-10T09:30:12Z</time>' +
|
||||||
|
' </trkpt>' +
|
||||||
|
' </trkseg>' +
|
||||||
|
' </trk>' +
|
||||||
|
'</gpx>';
|
||||||
|
var fs = format.readFeatures(text, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(fs).to.have.length(1);
|
||||||
|
var f = fs[0];
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var g = f.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.MultiLineString);
|
||||||
|
var p1 = ol.proj.transform([2, 1], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
p1.push(3, 1263115752);
|
||||||
|
var p2 = ol.proj.transform([6, 5], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
p2.push(7, 1263115812);
|
||||||
|
expect(g.getCoordinates()).to.eql([[p1, p2]]);
|
||||||
|
expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM);
|
||||||
|
var serialized = format.writeFeatures(fs, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(serialized).to.xmleql(ol.xml.load(text));
|
||||||
|
});
|
||||||
|
|
||||||
it('can read and write a trk with multiple trksegs', function() {
|
it('can read and write a trk with multiple trksegs', function() {
|
||||||
var text =
|
var text =
|
||||||
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
|
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
|
||||||
@@ -243,6 +306,29 @@ describe('ol.format.GPX', function() {
|
|||||||
expect(serialized).to.xmleql(ol.xml.load(text));
|
expect(serialized).to.xmleql(ol.xml.load(text));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can transform, read and write a wpt', function() {
|
||||||
|
var text =
|
||||||
|
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
|
||||||
|
' <wpt lat="1" lon="2"/>' +
|
||||||
|
'</gpx>';
|
||||||
|
var fs = format.readFeatures(text, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(fs).to.have.length(1);
|
||||||
|
var f = fs[0];
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var g = f.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
var expectedPoint = ol.proj.transform([2, 1], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint.push(0, 0);
|
||||||
|
expect(g.getCoordinates()).to.eql(expectedPoint);
|
||||||
|
expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM);
|
||||||
|
var serialized = format.writeFeatures(fs, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(serialized).to.xmleql(ol.xml.load(text));
|
||||||
|
});
|
||||||
|
|
||||||
it('can read and write a wpt with ele', function() {
|
it('can read and write a wpt with ele', function() {
|
||||||
var text =
|
var text =
|
||||||
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
|
'<gpx xmlns="http://www.topografix.com/GPX/1/1">' +
|
||||||
@@ -471,4 +557,5 @@ goog.require('ol.format.GPX');
|
|||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.MultiLineString');
|
goog.require('ol.geom.MultiLineString');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
|
goog.require('ol.proj');
|
||||||
goog.require('ol.xml');
|
goog.require('ol.xml');
|
||||||
|
|||||||
121
test/spec/ol/format/igcformat.test.js
Normal file
121
test/spec/ol/format/igcformat.test.js
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
goog.provide('ol.test.format.IGC');
|
||||||
|
|
||||||
|
|
||||||
|
describe('ol.format.IGC', function() {
|
||||||
|
|
||||||
|
var format;
|
||||||
|
var igc =
|
||||||
|
'AFLY05094\n' +
|
||||||
|
'HFDTE190411\n' +
|
||||||
|
'HFFXA100\n' +
|
||||||
|
'HFPLTPILOT:Tom Payne\n' +
|
||||||
|
'HFGTYGLIDERTYPE:Axis Mercury\n' +
|
||||||
|
'HFGIDGLIDERID:\n' +
|
||||||
|
'HFDTM100GPSDATUM:WGS84\n' +
|
||||||
|
'HFGPSGPS:FURUNO GH-80\n' +
|
||||||
|
'HFRFWFIRMWAREVERSION:1.22\n' +
|
||||||
|
'HFRHWHARDWAREVERSION:1.00\n' +
|
||||||
|
'HFFTYFRTYPE:FLYTEC,5020\n' +
|
||||||
|
'I013638TAS\n' +
|
||||||
|
'B0848484556256N00651095EA0205102039000\n' +
|
||||||
|
'B0855534556037N00651011EA0259302513000\n' +
|
||||||
|
'B0903354554964N00648049EA0272402758000\n' +
|
||||||
|
'GAB890A77AFE5CE63979AF6B1BED7F07D\n' +
|
||||||
|
'G62BB282E44D63A1149EF2F5E8AF6F2F1\n' +
|
||||||
|
'GEC14381987B15F81003EDE1E01A47843\n' +
|
||||||
|
'G60189641B00B00800019000000000000';
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
format = new ol.format.IGC();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#readFeature', function() {
|
||||||
|
it('does not read invalid features', function() {
|
||||||
|
expect(format.readFeature('invalid')).to.be(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does read a feature', function() {
|
||||||
|
var feature = format.readFeature(igc);
|
||||||
|
expect(feature).to.be.an(ol.Feature);
|
||||||
|
var geom = feature.getGeometry();
|
||||||
|
expect(geom.getType()).to.eql(ol.geom.GeometryType.LINE_STRING);
|
||||||
|
expect(geom.getCoordinates()).to.eql([
|
||||||
|
[6.851583333333333, 45.9376, 1303202928],
|
||||||
|
[6.850183333333334, 45.93395, 1303203353],
|
||||||
|
[6.800816666666667, 45.916066666666666, 1303203815]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does transform and read a feature', function() {
|
||||||
|
var feature = format.readFeature(igc, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(feature).to.be.an(ol.Feature);
|
||||||
|
var geom = feature.getGeometry();
|
||||||
|
expect(geom.getType()).to.eql(ol.geom.GeometryType.LINE_STRING);
|
||||||
|
|
||||||
|
var expectedPoint1 = ol.proj.transform(
|
||||||
|
[6.851583333333333, 45.9376], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint1.push(1303202928);
|
||||||
|
var expectedPoint2 = ol.proj.transform(
|
||||||
|
[6.850183333333334, 45.93395], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint2.push(1303203353);
|
||||||
|
var expectedPoint3 = ol.proj.transform(
|
||||||
|
[6.800816666666667, 45.916066666666666], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint3.push(1303203815);
|
||||||
|
|
||||||
|
expect(geom.getCoordinates()).to.eql(
|
||||||
|
[expectedPoint1, expectedPoint2, expectedPoint3]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#readFeatures', function() {
|
||||||
|
|
||||||
|
it('does not read invalid features', function() {
|
||||||
|
expect(format.readFeatures('invalid')).to.be.empty();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does read features', function() {
|
||||||
|
var features = format.readFeatures(igc);
|
||||||
|
expect(features.length).to.eql(1);
|
||||||
|
var feature = features[0];
|
||||||
|
expect(feature).to.be.an(ol.Feature);
|
||||||
|
var geom = feature.getGeometry();
|
||||||
|
expect(geom.getType()).to.eql(ol.geom.GeometryType.LINE_STRING);
|
||||||
|
expect(geom.getCoordinates()).to.eql([
|
||||||
|
[6.851583333333333, 45.9376, 1303202928],
|
||||||
|
[6.850183333333334, 45.93395, 1303203353],
|
||||||
|
[6.800816666666667, 45.916066666666666, 1303203815]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does transform and read features', function() {
|
||||||
|
var features = format.readFeatures(igc, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(features.length).to.eql(1);
|
||||||
|
var feature = features[0];
|
||||||
|
expect(feature).to.be.an(ol.Feature);
|
||||||
|
var geom = feature.getGeometry();
|
||||||
|
expect(geom.getType()).to.eql(ol.geom.GeometryType.LINE_STRING);
|
||||||
|
|
||||||
|
var expectedPoint1 = ol.proj.transform(
|
||||||
|
[6.851583333333333, 45.9376], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint1.push(1303202928);
|
||||||
|
var expectedPoint2 = ol.proj.transform(
|
||||||
|
[6.850183333333334, 45.93395], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint2.push(1303203353);
|
||||||
|
var expectedPoint3 = ol.proj.transform(
|
||||||
|
[6.800816666666667, 45.916066666666666], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint3.push(1303203815);
|
||||||
|
|
||||||
|
expect(geom.getCoordinates()).to.eql(
|
||||||
|
[expectedPoint1, expectedPoint2, expectedPoint3]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
goog.require('ol.format.IGC');
|
||||||
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.geom.GeometryType');
|
||||||
|
goog.require('ol.proj');
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
goog.provide('ol.test.format.IGC');
|
|
||||||
|
|
||||||
|
|
||||||
describe('ol.format.IGC', function() {
|
|
||||||
|
|
||||||
var format;
|
|
||||||
beforeEach(function() {
|
|
||||||
format = new ol.format.IGC();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#readFeature', function() {
|
|
||||||
|
|
||||||
it('does not read invalid features', function() {
|
|
||||||
expect(format.readFeature('invalid')).to.be(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#readFeatures', function() {
|
|
||||||
|
|
||||||
it('does not read invalid features', function() {
|
|
||||||
expect(format.readFeatures('invalid')).to.be.empty();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
goog.require('ol.format.IGC');
|
|
||||||
@@ -119,6 +119,76 @@ describe('ol.format.KML', function() {
|
|||||||
expect(g.getCoordinates()).to.eql([1, 2, 3]);
|
expect(g.getCoordinates()).to.eql([1, 2, 3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can transform and read Point geometries', function() {
|
||||||
|
var text =
|
||||||
|
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
|
||||||
|
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
|
||||||
|
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
|
||||||
|
' xsi:schemaLocation="http://www.opengis.net/kml/2.2' +
|
||||||
|
' https://developers.google.com/kml/schema/kml22gx.xsd">' +
|
||||||
|
' <Placemark>' +
|
||||||
|
' <Point>' +
|
||||||
|
' <coordinates>1,2,3</coordinates>' +
|
||||||
|
' </Point>' +
|
||||||
|
' </Placemark>' +
|
||||||
|
'</kml>';
|
||||||
|
var fs = format.readFeatures(text, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(fs).to.have.length(1);
|
||||||
|
var f = fs[0];
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var g = f.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
var expectedPoint = ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint.push(3);
|
||||||
|
expect(g.getCoordinates()).to.eql(expectedPoint);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can read a single Point geometry', function() {
|
||||||
|
var text =
|
||||||
|
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
|
||||||
|
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
|
||||||
|
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
|
||||||
|
' xsi:schemaLocation="http://www.opengis.net/kml/2.2' +
|
||||||
|
' https://developers.google.com/kml/schema/kml22gx.xsd">' +
|
||||||
|
' <Placemark>' +
|
||||||
|
' <Point>' +
|
||||||
|
' <coordinates>1,2,3</coordinates>' +
|
||||||
|
' </Point>' +
|
||||||
|
' </Placemark>' +
|
||||||
|
'</kml>';
|
||||||
|
var f = format.readFeature(text);
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var g = f.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
expect(g.getCoordinates()).to.eql([1, 2, 3]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can transform and read a single Point geometry', function() {
|
||||||
|
var text =
|
||||||
|
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
|
||||||
|
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
|
||||||
|
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
|
||||||
|
' xsi:schemaLocation="http://www.opengis.net/kml/2.2' +
|
||||||
|
' https://developers.google.com/kml/schema/kml22gx.xsd">' +
|
||||||
|
' <Placemark>' +
|
||||||
|
' <Point>' +
|
||||||
|
' <coordinates>1,2,3</coordinates>' +
|
||||||
|
' </Point>' +
|
||||||
|
' </Placemark>' +
|
||||||
|
'</kml>';
|
||||||
|
var f = format.readFeature(text, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var g = f.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
var expectedPoint = ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint.push(3);
|
||||||
|
expect(g.getCoordinates()).to.eql(expectedPoint);
|
||||||
|
});
|
||||||
|
|
||||||
it('can write XY Point geometries', function() {
|
it('can write XY Point geometries', function() {
|
||||||
var layout = ol.geom.GeometryLayout.XY;
|
var layout = ol.geom.GeometryLayout.XY;
|
||||||
var point = new ol.geom.Point([1, 2], layout);
|
var point = new ol.geom.Point([1, 2], layout);
|
||||||
@@ -159,6 +229,29 @@ describe('ol.format.KML', function() {
|
|||||||
expect(node).to.xmleql(ol.xml.load(text));
|
expect(node).to.xmleql(ol.xml.load(text));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can transform and write XYZ Point geometries', function() {
|
||||||
|
var layout = ol.geom.GeometryLayout.XYZ;
|
||||||
|
var point = new ol.geom.Point([1, 2, 3], layout).transform(
|
||||||
|
'EPSG:4326', 'EPSG:3857');
|
||||||
|
var features = [new ol.Feature(point)];
|
||||||
|
var node = format.writeFeatures(features, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
var text =
|
||||||
|
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
|
||||||
|
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
|
||||||
|
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
|
||||||
|
' xsi:schemaLocation="http://www.opengis.net/kml/2.2' +
|
||||||
|
' https://developers.google.com/kml/schema/kml22gx.xsd">' +
|
||||||
|
' <Placemark>' +
|
||||||
|
' <Point>' +
|
||||||
|
' <coordinates>1,2,3</coordinates>' +
|
||||||
|
' </Point>' +
|
||||||
|
' </Placemark>' +
|
||||||
|
'</kml>';
|
||||||
|
expect(node).to.xmleql(ol.xml.load(text));
|
||||||
|
});
|
||||||
|
|
||||||
it('can write XYM Point geometries', function() {
|
it('can write XYM Point geometries', function() {
|
||||||
var layout = ol.geom.GeometryLayout.XYM;
|
var layout = ol.geom.GeometryLayout.XYM;
|
||||||
var point = new ol.geom.Point([1, 2, 100], layout);
|
var point = new ol.geom.Point([1, 2, 100], layout);
|
||||||
@@ -1890,6 +1983,28 @@ describe('ol.format.KML', function() {
|
|||||||
expect(fs[0]).to.be.an(ol.Feature);
|
expect(fs[0]).to.be.an(ol.Feature);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can transform and read a single feature from a Document', function() {
|
||||||
|
var text =
|
||||||
|
'<Document xmlns="http://earth.google.com/kml/2.2">' +
|
||||||
|
' <Placemark>' +
|
||||||
|
' <Point>' +
|
||||||
|
' <coordinates>1,2,3</coordinates>' +
|
||||||
|
' </Point>' +
|
||||||
|
' </Placemark>' +
|
||||||
|
'</Document>';
|
||||||
|
var fs = format.readFeatures(text, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(fs).to.have.length(1);
|
||||||
|
var f = fs[0];
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var g = f.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
var expectedPoint = ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
expectedPoint.push(3);
|
||||||
|
expect(g.getCoordinates()).to.eql(expectedPoint);
|
||||||
|
});
|
||||||
|
|
||||||
it('can read a multiple features from a Document', function() {
|
it('can read a multiple features from a Document', function() {
|
||||||
var text =
|
var text =
|
||||||
'<Document xmlns="http://earth.google.com/kml/2.2">' +
|
'<Document xmlns="http://earth.google.com/kml/2.2">' +
|
||||||
@@ -2317,6 +2432,7 @@ goog.require('ol.geom.Polygon');
|
|||||||
goog.require('ol.style.Fill');
|
goog.require('ol.style.Fill');
|
||||||
goog.require('ol.style.Icon');
|
goog.require('ol.style.Icon');
|
||||||
goog.require('ol.style.IconOrigin');
|
goog.require('ol.style.IconOrigin');
|
||||||
|
goog.require('ol.proj');
|
||||||
goog.require('ol.style.Stroke');
|
goog.require('ol.style.Stroke');
|
||||||
goog.require('ol.style.Style');
|
goog.require('ol.style.Style');
|
||||||
goog.require('ol.style.Text');
|
goog.require('ol.style.Text');
|
||||||
|
|||||||
105
test/spec/ol/format/osmxmlformat.test.js
Normal file
105
test/spec/ol/format/osmxmlformat.test.js
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
goog.provide('ol.test.format.OSMXML');
|
||||||
|
|
||||||
|
|
||||||
|
describe('ol.format.OSMXML', function() {
|
||||||
|
|
||||||
|
var format;
|
||||||
|
beforeEach(function() {
|
||||||
|
format = new ol.format.OSMXML();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#readFeatures', function() {
|
||||||
|
|
||||||
|
it('can read an empty document', function() {
|
||||||
|
var text =
|
||||||
|
'<?xml version="1.0" encoding="UTF-8"?>' +
|
||||||
|
'<osm version="0.6" generator="my hand">' +
|
||||||
|
'</osm>';
|
||||||
|
var fs = format.readFeatures(text);
|
||||||
|
expect(fs).to.have.length(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can read nodes', function() {
|
||||||
|
var text =
|
||||||
|
'<?xml version="1.0" encoding="UTF-8"?>' +
|
||||||
|
'<osm version="0.6" generator="my hand">' +
|
||||||
|
' <node id="1" lat="1" lon="2">' +
|
||||||
|
' <tag k="name" v="1"/>' +
|
||||||
|
' </node>' +
|
||||||
|
' <node id="2" lat="3" lon="4">' +
|
||||||
|
' <tag k="name" v="2"/>' +
|
||||||
|
' </node>' +
|
||||||
|
'</osm>';
|
||||||
|
var fs = format.readFeatures(text);
|
||||||
|
expect(fs).to.have.length(2);
|
||||||
|
var f = fs[0];
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var g = f.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
expect(g.getCoordinates()).to.eql([2, 1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can read nodes and ways', function() {
|
||||||
|
var text =
|
||||||
|
'<?xml version="1.0" encoding="UTF-8"?>' +
|
||||||
|
'<osm version="0.6" generator="my hand">' +
|
||||||
|
' <node id="1" lat="1" lon="2">' +
|
||||||
|
' <tag k="name" v="1"/>' +
|
||||||
|
' </node>' +
|
||||||
|
' <node id="2" lat="3" lon="4">' +
|
||||||
|
' <tag k="name" v="2"/>' +
|
||||||
|
' </node>' +
|
||||||
|
' <way id="3">' +
|
||||||
|
' <tag k="name" v="3"/>' +
|
||||||
|
' <nd ref="1" />' +
|
||||||
|
' <nd ref="2" />' +
|
||||||
|
' </node>' +
|
||||||
|
'</osm>';
|
||||||
|
var fs = format.readFeatures(text);
|
||||||
|
expect(fs).to.have.length(3);
|
||||||
|
var point = fs[0];
|
||||||
|
expect(point).to.be.an(ol.Feature);
|
||||||
|
var g = point.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
expect(g.getCoordinates()).to.eql([2, 1]);
|
||||||
|
var line = fs[2];
|
||||||
|
expect(line).to.be.an(ol.Feature);
|
||||||
|
g = line.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.LineString);
|
||||||
|
expect(g.getCoordinates()).to.eql([[2, 1], [4, 3]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can transform and read nodes', function() {
|
||||||
|
var text =
|
||||||
|
'<?xml version="1.0" encoding="UTF-8"?>' +
|
||||||
|
'<osm version="0.6" generator="my hand">' +
|
||||||
|
' <node id="1" lat="1" lon="2">' +
|
||||||
|
' <tag k="name" v="1"/>' +
|
||||||
|
' </node>' +
|
||||||
|
' <node id="2" lat="3" lon="4">' +
|
||||||
|
' <tag k="name" v="2"/>' +
|
||||||
|
' </node>' +
|
||||||
|
'</osm>';
|
||||||
|
var fs = format.readFeatures(text, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(fs).to.have.length(2);
|
||||||
|
var f = fs[0];
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var g = f.getGeometry();
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
expect(g.getCoordinates()).to.eql(
|
||||||
|
ol.proj.transform([2, 1], 'EPSG:4326', 'EPSG:3857'));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
goog.require('goog.dom.xml');
|
||||||
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.format.OSMXML');
|
||||||
|
goog.require('ol.geom.Point');
|
||||||
|
goog.require('ol.geom.LineString');
|
||||||
|
goog.require('ol.proj');
|
||||||
@@ -11,13 +11,17 @@ describe('ol.format.Polyline', function() {
|
|||||||
|
|
||||||
function resetTestingData() {
|
function resetTestingData() {
|
||||||
format = new ol.format.Polyline();
|
format = new ol.format.Polyline();
|
||||||
points = [[38.50000, -120.20000],
|
points = [[-120.20000, 38.50000],
|
||||||
[40.70000, -120.95000],
|
[-120.95000, 40.70000],
|
||||||
[43.25200, -126.45300]];
|
[-126.45300, 43.25200]];
|
||||||
flatPoints = [38.50000, -120.20000,
|
flatPoints = [-120.20000, 38.50000,
|
||||||
40.70000, -120.95000,
|
-120.95000, 40.70000,
|
||||||
43.25200, -126.45300];
|
-126.45300, 43.25200];
|
||||||
encodedFlatPoints = '_p~iF~ps|U_ulLnnqC_mqNvxq`@';
|
encodedFlatPoints = '~ps|U_p~iFnnqC_ulLvxq`@_mqN';
|
||||||
|
points3857 = [
|
||||||
|
ol.proj.transform([-120.20000, 38.50000], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([-120.95000, 40.70000], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([-126.45300, 43.25200], 'EPSG:4326', 'EPSG:3857')];
|
||||||
|
|
||||||
floats = [0.00, 0.15, -0.01, -0.16, 0.16, 0.01];
|
floats = [0.00, 0.15, -0.01, -0.16, 0.16, 0.01];
|
||||||
smallFloats = [0.00000, 0.00015, -0.00001, -0.00016, 0.00016, 0.00001];
|
smallFloats = [0.00000, 0.00015, -0.00001, -0.00016, 0.00016, 0.00001];
|
||||||
@@ -253,6 +257,16 @@ describe('ol.format.Polyline', function() {
|
|||||||
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
|
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms and returns the expected feature', function() {
|
||||||
|
var feature = format.readFeature(encodedFlatPoints, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(feature).to.be.an(ol.Feature);
|
||||||
|
var geometry = feature.getGeometry();
|
||||||
|
expect(geometry).to.be.an(ol.geom.LineString);
|
||||||
|
expect(geometry.getCoordinates()).to.eql(points3857);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#readFeatures', function() {
|
describe('#readFeatures', function() {
|
||||||
@@ -268,6 +282,19 @@ describe('ol.format.Polyline', function() {
|
|||||||
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
|
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms and returns the expected features', function() {
|
||||||
|
var features = format.readFeatures(encodedFlatPoints, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(features).to.be.an(Array);
|
||||||
|
expect(features).to.have.length(1);
|
||||||
|
var feature = features[0];
|
||||||
|
expect(feature).to.be.an(ol.Feature);
|
||||||
|
var geometry = feature.getGeometry();
|
||||||
|
expect(geometry).to.be.an(ol.geom.LineString);
|
||||||
|
expect(geometry.getCoordinates()).to.eql(points3857);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#readGeometry', function() {
|
describe('#readGeometry', function() {
|
||||||
@@ -278,6 +305,14 @@ describe('ol.format.Polyline', function() {
|
|||||||
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
|
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms and returns the expected geometry', function() {
|
||||||
|
var geometry = format.readGeometry(encodedFlatPoints, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(geometry).to.be.an(ol.geom.LineString);
|
||||||
|
expect(geometry.getCoordinates()).to.eql(points3857);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#readProjection', function() {
|
describe('#readProjection', function() {
|
||||||
@@ -296,6 +331,13 @@ describe('ol.format.Polyline', function() {
|
|||||||
expect(format.writeFeature(feature)).to.be(encodedFlatPoints);
|
expect(format.writeFeature(feature)).to.be(encodedFlatPoints);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms and returns the expected text', function() {
|
||||||
|
var feature = new ol.Feature(new ol.geom.LineString(points3857));
|
||||||
|
expect(format.writeFeature(feature, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
})).to.be(encodedFlatPoints);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#writeFeature', function() {
|
describe('#writeFeature', function() {
|
||||||
@@ -305,6 +347,13 @@ describe('ol.format.Polyline', function() {
|
|||||||
expect(format.writeFeatures(features)).to.be(encodedFlatPoints);
|
expect(format.writeFeatures(features)).to.be(encodedFlatPoints);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms and returns the expected text', function() {
|
||||||
|
var features = [new ol.Feature(new ol.geom.LineString(points3857))];
|
||||||
|
expect(format.writeFeatures(features, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
})).to.be(encodedFlatPoints);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#writeGeometry', function() {
|
describe('#writeGeometry', function() {
|
||||||
@@ -314,6 +363,13 @@ describe('ol.format.Polyline', function() {
|
|||||||
expect(format.writeGeometry(geometry)).to.be(encodedFlatPoints);
|
expect(format.writeGeometry(geometry)).to.be(encodedFlatPoints);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms and returns the expected text', function() {
|
||||||
|
var geometry = new ol.geom.LineString(points3857);
|
||||||
|
expect(format.writeGeometry(geometry, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
})).to.be(encodedFlatPoints);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -89,6 +89,41 @@ describe('ol.format.TopoJSON', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parses simple.json and transforms', function(done) {
|
||||||
|
afterLoadText('spec/ol/format/topojson/simple.json', function(text) {
|
||||||
|
var features = format.readFeatures(text, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(features.length).to.be(3);
|
||||||
|
|
||||||
|
var point = features[0].getGeometry();
|
||||||
|
expect(point.getType()).to.be('Point');
|
||||||
|
expect(features[0].getGeometry().getCoordinates()).to.eql(
|
||||||
|
ol.proj.transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
|
||||||
|
|
||||||
|
var line = features[1].getGeometry();
|
||||||
|
expect(line.getType()).to.be('LineString');
|
||||||
|
expect(line.getCoordinates()).to.eql([
|
||||||
|
ol.proj.transform([102.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([103.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([104.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([105.0, 1.0], 'EPSG:4326', 'EPSG:3857')
|
||||||
|
]);
|
||||||
|
|
||||||
|
var polygon = features[2].getGeometry();
|
||||||
|
expect(polygon.getType()).to.be('Polygon');
|
||||||
|
expect(polygon.getCoordinates()).to.eql([[
|
||||||
|
ol.proj.transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([100.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([101.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([101.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
ol.proj.transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857')
|
||||||
|
]]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('parses world-110m.json', function(done) {
|
it('parses world-110m.json', function(done) {
|
||||||
afterLoadText('spec/ol/format/topojson/world-110m.json', function(text) {
|
afterLoadText('spec/ol/format/topojson/world-110m.json', function(text) {
|
||||||
|
|
||||||
@@ -123,4 +158,5 @@ goog.require('ol.Feature');
|
|||||||
goog.require('ol.geom.MultiPolygon');
|
goog.require('ol.geom.MultiPolygon');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
goog.require('ol.format.Feature');
|
goog.require('ol.format.Feature');
|
||||||
|
goog.require('ol.proj');
|
||||||
goog.require('ol.format.TopoJSON');
|
goog.require('ol.format.TopoJSON');
|
||||||
|
|||||||
@@ -4,15 +4,17 @@ describe('ol.format.WFS', function() {
|
|||||||
|
|
||||||
describe('when parsing TOPP states GML from WFS', function() {
|
describe('when parsing TOPP states GML from WFS', function() {
|
||||||
|
|
||||||
var features, feature;
|
var features, feature, xml;
|
||||||
before(function(done) {
|
|
||||||
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
|
|
||||||
afterLoadText('spec/ol/format/wfs/topp-states-wfs.xml', function(xml) {
|
|
||||||
try {
|
|
||||||
var config = {
|
var config = {
|
||||||
'featureNS': 'http://www.openplans.org/topp',
|
'featureNS': 'http://www.openplans.org/topp',
|
||||||
'featureType': 'states'
|
'featureType': 'states'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
before(function(done) {
|
||||||
|
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
|
||||||
|
afterLoadText('spec/ol/format/wfs/topp-states-wfs.xml', function(data) {
|
||||||
|
try {
|
||||||
|
xml = data;
|
||||||
features = new ol.format.WFS(config).readFeatures(xml);
|
features = new ol.format.WFS(config).readFeatures(xml);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
done(e);
|
done(e);
|
||||||
@@ -32,6 +34,20 @@ describe('ol.format.WFS', function() {
|
|||||||
expect(feature.getGeometry()).to.be.an(ol.geom.MultiPolygon);
|
expect(feature.getGeometry()).to.be.an(ol.geom.MultiPolygon);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms and creates a polygon for Illinois', function() {
|
||||||
|
features = new ol.format.WFS(config).readFeatures(xml, {
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
feature = features[0];
|
||||||
|
expect(feature.getId()).to.equal('states.1');
|
||||||
|
expect(feature.get('STATE_NAME')).to.equal('Illinois');
|
||||||
|
var geom = feature.getGeometry();
|
||||||
|
expect(geom).to.be.an(ol.geom.MultiPolygon);
|
||||||
|
var p = ol.proj.transform([-88.071, 37.511], 'EPSG:4326', 'EPSG:3857');
|
||||||
|
p.push(0);
|
||||||
|
expect(geom.getFirstCoordinate()).to.eql(p);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when parsing FeatureCollection', function() {
|
describe('when parsing FeatureCollection', function() {
|
||||||
@@ -388,3 +404,4 @@ goog.require('ol.geom.MultiPoint');
|
|||||||
goog.require('ol.geom.MultiPolygon');
|
goog.require('ol.geom.MultiPolygon');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
goog.require('ol.format.WFS');
|
goog.require('ol.format.WFS');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
|||||||
@@ -15,6 +15,21 @@ describe('ol.format.WKT', function() {
|
|||||||
expect(geom.getCoordinates()).to.eql([30, 10]);
|
expect(geom.getCoordinates()).to.eql([30, 10]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Point transformed / read / written correctly', function() {
|
||||||
|
var wkt = 'POINT(1 2)';
|
||||||
|
var geom = format.readGeometry(wkt, {
|
||||||
|
dataProjection: 'EPSG:4326',
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(geom.getCoordinates()).to.eql(
|
||||||
|
ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857'));
|
||||||
|
var newWkt = format.writeGeometry(geom, {
|
||||||
|
dataProjection: 'EPSG:4326',
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(newWkt).to.eql(wkt);
|
||||||
|
});
|
||||||
|
|
||||||
it('MultiPoint read / written correctly', function() {
|
it('MultiPoint read / written correctly', function() {
|
||||||
// there are two forms to test
|
// there are two forms to test
|
||||||
var wkt = 'MULTIPOINT((10 40),(40 30),(20 20),(30 10))';
|
var wkt = 'MULTIPOINT((10 40),(40 30),(20 20),(30 10))';
|
||||||
@@ -231,7 +246,67 @@ describe('ol.format.WKT', function() {
|
|||||||
expect(format.writeFeatures(features)).to.eql(wkt);
|
expect(format.writeFeatures(features)).to.eql(wkt);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Point feature read / written correctly', function() {
|
||||||
|
var wkt = 'POINT(30 10)';
|
||||||
|
var feature = format.readFeature(wkt);
|
||||||
|
var geom = feature.getGeometry();
|
||||||
|
expect(geom.getCoordinates()).to.eql([30, 10]);
|
||||||
|
expect(format.writeFeature(feature)).to.eql(wkt);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Point feature transformed / read / written correctly', function() {
|
||||||
|
var wkt = 'POINT(1 2)';
|
||||||
|
var feature = format.readFeature(wkt, {
|
||||||
|
dataProjection: 'EPSG:4326',
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
var geom = feature.getGeometry();
|
||||||
|
expect(geom.getCoordinates()).to.eql(
|
||||||
|
ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857'));
|
||||||
|
var newWkt = format.writeFeature(feature, {
|
||||||
|
dataProjection: 'EPSG:4326',
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(newWkt).to.eql(wkt);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Features read / written correctly', function() {
|
||||||
|
var wkt = 'GEOMETRYCOLLECTION(POINT(1 2),POINT(3 4))';
|
||||||
|
var features = format.readFeatures(wkt);
|
||||||
|
expect(features.length).to.eql(2);
|
||||||
|
var point1 = features[0].getGeometry();
|
||||||
|
var point2 = features[1].getGeometry();
|
||||||
|
expect(point1.getType()).to.eql(ol.geom.GeometryType.POINT);
|
||||||
|
expect(point2.getType()).to.eql(ol.geom.GeometryType.POINT);
|
||||||
|
expect(point1.getCoordinates()).to.eql([1, 2]);
|
||||||
|
expect(point2.getCoordinates()).to.eql([3, 4]);
|
||||||
|
expect(format.writeFeatures(features)).to.eql(wkt);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Features transformed / read / written correctly', function() {
|
||||||
|
var wkt = 'GEOMETRYCOLLECTION(POINT(1 2),POINT(4 5))';
|
||||||
|
var features = format.readFeatures(wkt, {
|
||||||
|
dataProjection: 'EPSG:4326',
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(features.length).to.eql(2);
|
||||||
|
var point1 = features[0].getGeometry();
|
||||||
|
var point2 = features[1].getGeometry();
|
||||||
|
expect(point1.getType()).to.eql(ol.geom.GeometryType.POINT);
|
||||||
|
expect(point2.getType()).to.eql(ol.geom.GeometryType.POINT);
|
||||||
|
expect(point1.getCoordinates()).to.eql(
|
||||||
|
ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857'));
|
||||||
|
expect(point2.getCoordinates()).to.eql(
|
||||||
|
ol.proj.transform([4, 5], 'EPSG:4326', 'EPSG:3857'));
|
||||||
|
var newWkt = format.writeFeatures(features, {
|
||||||
|
dataProjection: 'EPSG:4326',
|
||||||
|
featureProjection: 'EPSG:3857'
|
||||||
|
});
|
||||||
|
expect(newWkt).to.eql(wkt);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
goog.require('ol.geom.GeometryType');
|
goog.require('ol.geom.GeometryType');
|
||||||
goog.require('ol.format.WKT');
|
goog.require('ol.format.WKT');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
|||||||
Reference in New Issue
Block a user