Port ol.parser.polyline to ol.format.Format

This commit is contained in:
Tom Payne
2013-12-04 17:27:40 +01:00
parent 461a0d0615
commit 3cf87ced1e
2 changed files with 212 additions and 49 deletions

View File

@@ -1,13 +1,19 @@
goog.provide('ol.test.parser.polyline');
goog.provide('ol.test.format.Polyline');
describe('ol.parser.polyline', function() {
describe('ol.format.Polyline', function() {
var format;
var points;
var flatPoints, encodedFlatPoints;
var floats, smallFloats, encodedFloats;
var signedIntegers, encodedSignedIntegers;
var unsignedIntegers, encodedUnsignedIntegers;
function resetTestingData() {
format = new ol.format.Polyline();
points = [[38.50000, -120.20000],
[40.70000, -120.95000],
[43.25200, -126.45300]];
flatPoints = [38.50000, -120.20000,
40.70000, -120.95000,
43.25200, -126.45300];
@@ -31,7 +37,7 @@ describe('ol.parser.polyline', function() {
describe('encodeFlatCoordinates', function() {
it('returns expected value', function() {
var encodeFlatCoordinates = ol.parser.polyline.encodeFlatCoordinates;
var encodeFlatCoordinates = ol.format.Polyline.encodeFlatCoordinates;
// from the "Encoded Polyline Algorithm Format" page at Google
expect(encodeFlatCoordinates(flatPoints)).to.eql(encodedFlatPoints);
@@ -40,7 +46,7 @@ describe('ol.parser.polyline', function() {
describe('decodeFlatCoordinates', function() {
it('returns expected value', function() {
var decodeFlatCoordinates = ol.parser.polyline.decodeFlatCoordinates;
var decodeFlatCoordinates = ol.format.Polyline.decodeFlatCoordinates;
// from the "Encoded Polyline Algorithm Format" page at Google
expect(decodeFlatCoordinates(encodedFlatPoints)).to.eql(flatPoints);
@@ -51,7 +57,7 @@ describe('ol.parser.polyline', function() {
describe('encodeDeltas', function() {
it('returns expected value', function() {
var encodeDeltas = ol.parser.polyline.encodeDeltas;
var encodeDeltas = ol.format.Polyline.encodeDeltas;
expect(encodeDeltas(flatPoints, 2)).to.eql(encodedFlatPoints);
});
@@ -59,7 +65,7 @@ describe('ol.parser.polyline', function() {
describe('decodeDeltas', function() {
it('returns expected value', function() {
var decodeDeltas = ol.parser.polyline.decodeDeltas;
var decodeDeltas = ol.format.Polyline.decodeDeltas;
expect(decodeDeltas(encodedFlatPoints, 2)).to.eql(flatPoints);
});
@@ -69,7 +75,7 @@ describe('ol.parser.polyline', function() {
describe('encodeFloats', function() {
it('returns expected value', function() {
var encodeFloats = ol.parser.polyline.encodeFloats;
var encodeFloats = ol.format.Polyline.encodeFloats;
expect(encodeFloats(smallFloats)).to.eql(encodedFloats);
@@ -82,7 +88,7 @@ describe('ol.parser.polyline', function() {
describe('decodeFloats', function() {
it('returns expected value', function() {
var decodeFloats = ol.parser.polyline.decodeFloats;
var decodeFloats = ol.format.Polyline.decodeFloats;
expect(decodeFloats(encodedFloats)).to.eql(smallFloats);
expect(decodeFloats(encodedFloats, 1e5)).to.eql(smallFloats);
@@ -94,7 +100,7 @@ describe('ol.parser.polyline', function() {
describe('encodeSignedIntegers', function() {
it('returns expected value', function() {
var encodeSignedIntegers = ol.parser.polyline.encodeSignedIntegers;
var encodeSignedIntegers = ol.format.Polyline.encodeSignedIntegers;
expect(encodeSignedIntegers(
signedIntegers)).to.eql(encodedSignedIntegers);
@@ -103,7 +109,7 @@ describe('ol.parser.polyline', function() {
describe('decodeSignedIntegers', function() {
it('returns expected value', function() {
var decodeSignedIntegers = ol.parser.polyline.decodeSignedIntegers;
var decodeSignedIntegers = ol.format.Polyline.decodeSignedIntegers;
expect(decodeSignedIntegers(
encodedSignedIntegers)).to.eql(signedIntegers);
@@ -114,7 +120,7 @@ describe('ol.parser.polyline', function() {
describe('encodeUnsignedIntegers', function() {
it('returns expected value', function() {
var encodeUnsignedIntegers = ol.parser.polyline.encodeUnsignedIntegers;
var encodeUnsignedIntegers = ol.format.Polyline.encodeUnsignedIntegers;
expect(encodeUnsignedIntegers(
unsignedIntegers)).to.eql(encodedUnsignedIntegers);
@@ -123,7 +129,7 @@ describe('ol.parser.polyline', function() {
describe('decodeUnsignedIntegers', function() {
it('returns expected value', function() {
var decodeUnsignedIntegers = ol.parser.polyline.decodeUnsignedIntegers;
var decodeUnsignedIntegers = ol.format.Polyline.decodeUnsignedIntegers;
expect(decodeUnsignedIntegers(
encodedUnsignedIntegers)).to.eql(unsignedIntegers);
@@ -134,7 +140,7 @@ describe('ol.parser.polyline', function() {
describe('encodeFloat', function() {
it('returns expected value', function() {
var encodeFloat = ol.parser.polyline.encodeFloat;
var encodeFloat = ol.format.Polyline.encodeFloat;
expect(encodeFloat(0.00000)).to.eql('?');
expect(encodeFloat(-0.00001)).to.eql('@');
@@ -157,7 +163,7 @@ describe('ol.parser.polyline', function() {
describe('decodeFloat', function() {
it('returns expected value', function() {
var decodeFloat = ol.parser.polyline.decodeFloat;
var decodeFloat = ol.format.Polyline.decodeFloat;
expect(decodeFloat('?')).to.eql(0.00000);
expect(decodeFloat('@')).to.eql(-0.00001);
@@ -182,7 +188,7 @@ describe('ol.parser.polyline', function() {
describe('encodeSignedInteger', function() {
it('returns expected value', function() {
var encodeSignedInteger = ol.parser.polyline.encodeSignedInteger;
var encodeSignedInteger = ol.format.Polyline.encodeSignedInteger;
expect(encodeSignedInteger(0)).to.eql('?');
expect(encodeSignedInteger(-1)).to.eql('@');
@@ -200,7 +206,7 @@ describe('ol.parser.polyline', function() {
describe('decodeSignedInteger', function() {
it('returns expected value', function() {
var decodeSignedInteger = ol.parser.polyline.decodeSignedInteger;
var decodeSignedInteger = ol.format.Polyline.decodeSignedInteger;
expect(decodeSignedInteger('?')).to.eql(0);
expect(decodeSignedInteger('@')).to.eql(-1);
@@ -220,7 +226,7 @@ describe('ol.parser.polyline', function() {
describe('encodeUnsignedInteger', function() {
it('returns expected value', function() {
var encodeUnsignedInteger = ol.parser.polyline.encodeUnsignedInteger;
var encodeUnsignedInteger = ol.format.Polyline.encodeUnsignedInteger;
expect(encodeUnsignedInteger(0)).to.eql('?');
expect(encodeUnsignedInteger(1)).to.eql('@');
@@ -240,7 +246,7 @@ describe('ol.parser.polyline', function() {
describe('decodeUnsignedInteger', function() {
it('returns expected value', function() {
var decodeUnsignedInteger = ol.parser.polyline.decodeUnsignedInteger;
var decodeUnsignedInteger = ol.format.Polyline.decodeUnsignedInteger;
expect(decodeUnsignedInteger('?')).to.eql(0);
expect(decodeUnsignedInteger('@')).to.eql(1);
@@ -257,6 +263,83 @@ describe('ol.parser.polyline', function() {
expect(decodeUnsignedInteger('mD')).to.eql(174);
});
});
describe('#readFeature', function() {
it('returns the expected feature', function() {
var feature = format.readFeature(encodedFlatPoints);
expect(feature).to.be.an(ol.Feature);
var geometry = feature.getGeometry();
expect(geometry).to.be.an(ol.geom.LineString);
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
});
});
describe('#readFeatures', function() {
it('returns the expected feature', function() {
var features = format.readFeatures(encodedFlatPoints);
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.getFlatCoordinates()).to.eql(flatPoints);
});
});
describe('#readGeometry', function() {
it('returns the expected geometry', function() {
var geometry = format.readGeometry(encodedFlatPoints);
expect(geometry).to.be.an(ol.geom.LineString);
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
});
});
describe('#readProjection', function() {
it('returns the expected projection', function() {
var projection = format.readProjection(encodedFlatPoints);
expect(projection).to.be(ol.proj.get('EPSG:4326'));
});
});
describe('#writeFeature', function() {
it('returns the expected text', function() {
var feature = new ol.Feature(new ol.geom.LineString(points));
expect(format.writeFeature(feature)).to.be(encodedFlatPoints);
});
});
describe('#writeFeature', function() {
it('returns the expected text', function() {
var features = [new ol.Feature(new ol.geom.LineString(points))];
expect(format.writeFeatures(features)).to.be(encodedFlatPoints);
});
});
describe('#writeGeometry', function() {
it('returns the expected text', function() {
var geometry = new ol.geom.LineString(points);
expect(format.writeGeometry(geometry)).to.be(encodedFlatPoints);
});
});
});
goog.require('ol.parser.polyline');
goog.require('ol.Feature');
goog.require('ol.format.Polyline');
goog.require('ol.geom.LineString');
goog.require('ol.proj');