From 83025fb97d6821f70141f835942863328220179e Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 31 Oct 2014 11:47:44 +0100 Subject: [PATCH] Assume a latitude, longitude order for Polyline format --- src/ol/format/polylineformat.js | 12 +++++++++++- test/spec/ol/format/polylineformat.test.js | 9 ++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ol/format/polylineformat.js b/src/ol/format/polylineformat.js index 07f61873cf..cab6513231 100644 --- a/src/ol/format/polylineformat.js +++ b/src/ol/format/polylineformat.js @@ -5,12 +5,17 @@ goog.require('ol.Feature'); goog.require('ol.format.Feature'); goog.require('ol.format.TextFeature'); goog.require('ol.geom.LineString'); +goog.require('ol.geom.flat.flip'); goog.require('ol.geom.flat.inflate'); goog.require('ol.proj'); /** + * @classdesc + * Feature format for reading and writing data in the Encoded + * Polyline Algorithm Format. + * * @constructor * @extends {ol.format.TextFeature} * @param {olx.format.PolylineOptions=} opt_options @@ -250,7 +255,8 @@ ol.format.Polyline.encodeUnsignedInteger = function(num) { /** - * Read the feature from the Polyline source. + * Read the feature from the Polyline source. The coordinates are assumed to be + * in two dimensions and in latitude, longitude order. * * @function * @param {ArrayBuffer|Document|Node|Object|string} source Source. @@ -311,6 +317,8 @@ ol.format.Polyline.prototype.readGeometry; ol.format.Polyline.prototype.readGeometryFromText = function(text, opt_options) { var flatCoordinates = ol.format.Polyline.decodeDeltas(text, 2, this.factor_); + ol.geom.flat.flip.flipXY( + flatCoordinates, 0, flatCoordinates.length, 2, flatCoordinates); var coordinates = ol.geom.flat.inflate.coordinates( flatCoordinates, 0, flatCoordinates.length, 2); @@ -387,5 +395,7 @@ ol.format.Polyline.prototype.writeGeometryText = geometry, true, this.adaptOptions(opt_options))); var flatCoordinates = geometry.getFlatCoordinates(); var stride = geometry.getStride(); + ol.geom.flat.flip.flipXY( + flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates); return ol.format.Polyline.encodeDeltas(flatCoordinates, stride, this.factor_); }; diff --git a/test/spec/ol/format/polylineformat.test.js b/test/spec/ol/format/polylineformat.test.js index 2c09ff8dfc..1137d7c6c9 100644 --- a/test/spec/ol/format/polylineformat.test.js +++ b/test/spec/ol/format/polylineformat.test.js @@ -17,7 +17,10 @@ describe('ol.format.Polyline', function() { flatPoints = [-120.20000, 38.50000, -120.95000, 40.70000, -126.45300, 43.25200]; - encodedFlatPoints = '~ps|U_p~iFnnqC_ulLvxq`@_mqN'; + flippedFlatPoints = [38.50000, -120.20000, + 40.70000, -120.95000, + 43.25200, -126.45300]; + encodedFlatPoints = '_p~iF~ps|U_ulLnnqC_mqNvxq`@'; points3857 = [ ol.proj.transform([-120.20000, 38.50000], 'EPSG:4326', 'EPSG:3857'), ol.proj.transform([-120.95000, 40.70000], 'EPSG:4326', 'EPSG:3857'), @@ -42,7 +45,7 @@ describe('ol.format.Polyline', function() { it('returns expected value', function() { var encodeDeltas = ol.format.Polyline.encodeDeltas; - expect(encodeDeltas(flatPoints, 2)).to.eql(encodedFlatPoints); + expect(encodeDeltas(flippedFlatPoints, 2)).to.eql(encodedFlatPoints); }); }); @@ -50,7 +53,7 @@ describe('ol.format.Polyline', function() { it('returns expected value', function() { var decodeDeltas = ol.format.Polyline.decodeDeltas; - expect(decodeDeltas(encodedFlatPoints, 2)).to.eql(flatPoints); + expect(decodeDeltas(encodedFlatPoints, 2)).to.eql(flippedFlatPoints); }); });