Merge pull request #2906 from fredj/polyline-order
Assume a latitude, longitude order for Polyline format
This commit is contained in:
@@ -5,12 +5,17 @@ goog.require('ol.Feature');
|
|||||||
goog.require('ol.format.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.flip');
|
||||||
goog.require('ol.geom.flat.inflate');
|
goog.require('ol.geom.flat.inflate');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @classdesc
|
||||||
|
* Feature format for reading and writing data in the Encoded
|
||||||
|
* Polyline Algorithm Format.
|
||||||
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.format.TextFeature}
|
* @extends {ol.format.TextFeature}
|
||||||
* @param {olx.format.PolylineOptions=} opt_options
|
* @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
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
@@ -311,6 +317,8 @@ ol.format.Polyline.prototype.readGeometry;
|
|||||||
ol.format.Polyline.prototype.readGeometryFromText =
|
ol.format.Polyline.prototype.readGeometryFromText =
|
||||||
function(text, opt_options) {
|
function(text, opt_options) {
|
||||||
var flatCoordinates = ol.format.Polyline.decodeDeltas(text, 2, this.factor_);
|
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(
|
var coordinates = ol.geom.flat.inflate.coordinates(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2);
|
flatCoordinates, 0, flatCoordinates.length, 2);
|
||||||
|
|
||||||
@@ -387,5 +395,7 @@ ol.format.Polyline.prototype.writeGeometryText =
|
|||||||
geometry, true, this.adaptOptions(opt_options)));
|
geometry, true, this.adaptOptions(opt_options)));
|
||||||
var flatCoordinates = geometry.getFlatCoordinates();
|
var flatCoordinates = geometry.getFlatCoordinates();
|
||||||
var stride = geometry.getStride();
|
var stride = geometry.getStride();
|
||||||
|
ol.geom.flat.flip.flipXY(
|
||||||
|
flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
|
||||||
return ol.format.Polyline.encodeDeltas(flatCoordinates, stride, this.factor_);
|
return ol.format.Polyline.encodeDeltas(flatCoordinates, stride, this.factor_);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ describe('ol.format.Polyline', function() {
|
|||||||
flatPoints = [-120.20000, 38.50000,
|
flatPoints = [-120.20000, 38.50000,
|
||||||
-120.95000, 40.70000,
|
-120.95000, 40.70000,
|
||||||
-126.45300, 43.25200];
|
-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 = [
|
points3857 = [
|
||||||
ol.proj.transform([-120.20000, 38.50000], 'EPSG:4326', 'EPSG:3857'),
|
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([-120.95000, 40.70000], 'EPSG:4326', 'EPSG:3857'),
|
||||||
@@ -42,7 +45,7 @@ describe('ol.format.Polyline', function() {
|
|||||||
it('returns expected value', function() {
|
it('returns expected value', function() {
|
||||||
var encodeDeltas = ol.format.Polyline.encodeDeltas;
|
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() {
|
it('returns expected value', function() {
|
||||||
var decodeDeltas = ol.format.Polyline.decodeDeltas;
|
var decodeDeltas = ol.format.Polyline.decodeDeltas;
|
||||||
|
|
||||||
expect(decodeDeltas(encodedFlatPoints, 2)).to.eql(flatPoints);
|
expect(decodeDeltas(encodedFlatPoints, 2)).to.eql(flippedFlatPoints);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user