Implement read transforms for ol.format.IGC
This commit is contained in:
@@ -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');
|
||||||
@@ -93,6 +94,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
|
||||||
*/
|
*/
|
||||||
@@ -102,7 +104,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>} */
|
||||||
@@ -167,7 +169,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, false, opt_options));
|
||||||
feature.setProperties(properties);
|
feature.setProperties(properties);
|
||||||
return feature;
|
return feature;
|
||||||
};
|
};
|
||||||
@@ -179,6 +182,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
|
||||||
*/
|
*/
|
||||||
@@ -188,8 +192,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 {
|
||||||
|
|||||||
123
test/spec/ol/format/igcformat.test.js
Normal file
123
test/spec/ol/format/igcformat.test.js
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
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, {
|
||||||
|
dataProjection: 'EPSG:4326',
|
||||||
|
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, {
|
||||||
|
dataProjection: 'EPSG:4326',
|
||||||
|
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');
|
|
||||||
Reference in New Issue
Block a user