Merge pull request #7646 from openlayers/ne_polyline
Named export for Polyline format and SimpleGeometry
This commit is contained in:
@@ -24,10 +24,9 @@ inherits(JSONFeature, FeatureFormat);
|
||||
|
||||
/**
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @private
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
JSONFeature.prototype.getObject_ = function(source) {
|
||||
function getObject(source) {
|
||||
if (typeof source === 'string') {
|
||||
var object = JSON.parse(source);
|
||||
return object ? /** @type {Object} */ (object) : null;
|
||||
@@ -36,7 +35,7 @@ JSONFeature.prototype.getObject_ = function(source) {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -52,7 +51,7 @@ JSONFeature.prototype.getType = function() {
|
||||
*/
|
||||
JSONFeature.prototype.readFeature = function(source, opt_options) {
|
||||
return this.readFeatureFromObject(
|
||||
this.getObject_(source), this.getReadOptions(source, opt_options));
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
};
|
||||
|
||||
|
||||
@@ -61,7 +60,7 @@ JSONFeature.prototype.readFeature = function(source, opt_options) {
|
||||
*/
|
||||
JSONFeature.prototype.readFeatures = function(source, opt_options) {
|
||||
return this.readFeaturesFromObject(
|
||||
this.getObject_(source), this.getReadOptions(source, opt_options));
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
};
|
||||
|
||||
|
||||
@@ -90,7 +89,7 @@ JSONFeature.prototype.readFeaturesFromObject = function(object, opt_options) {};
|
||||
*/
|
||||
JSONFeature.prototype.readGeometry = function(source, opt_options) {
|
||||
return this.readGeometryFromObject(
|
||||
this.getObject_(source), this.getReadOptions(source, opt_options));
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
};
|
||||
|
||||
|
||||
@@ -108,7 +107,7 @@ JSONFeature.prototype.readGeometryFromObject = function(object, opt_options) {};
|
||||
* @inheritDoc
|
||||
*/
|
||||
JSONFeature.prototype.readProjection = function(source) {
|
||||
return this.readProjectionFromObject(this.getObject_(source));
|
||||
return this.readProjectionFromObject(getObject(source));
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import FeatureFormat from '../format/Feature.js';
|
||||
import TextFeature from '../format/TextFeature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||
import {getStrideForLayout} from '../geom/SimpleGeometry.js';
|
||||
import _ol_geom_flat_flip_ from '../geom/flat/flip.js';
|
||||
import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
@@ -65,7 +65,7 @@ inherits(Polyline, TextFeature);
|
||||
* @return {string} The encoded string.
|
||||
* @api
|
||||
*/
|
||||
Polyline.encodeDeltas = function(numbers, stride, opt_factor) {
|
||||
export function encodeDeltas(numbers, stride, opt_factor) {
|
||||
var factor = opt_factor ? opt_factor : 1e5;
|
||||
var d;
|
||||
|
||||
@@ -85,8 +85,8 @@ Polyline.encodeDeltas = function(numbers, stride, opt_factor) {
|
||||
}
|
||||
}
|
||||
|
||||
return Polyline.encodeFloats(numbers, factor);
|
||||
};
|
||||
return encodeFloats(numbers, factor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -100,7 +100,7 @@ Polyline.encodeDeltas = function(numbers, stride, opt_factor) {
|
||||
* @return {Array.<number>} A list of n-dimensional points.
|
||||
* @api
|
||||
*/
|
||||
Polyline.decodeDeltas = function(encoded, stride, opt_factor) {
|
||||
export function decodeDeltas(encoded, stride, opt_factor) {
|
||||
var factor = opt_factor ? opt_factor : 1e5;
|
||||
var d;
|
||||
|
||||
@@ -110,7 +110,7 @@ Polyline.decodeDeltas = function(encoded, stride, opt_factor) {
|
||||
lastNumbers[d] = 0;
|
||||
}
|
||||
|
||||
var numbers = Polyline.decodeFloats(encoded, factor);
|
||||
var numbers = decodeFloats(encoded, factor);
|
||||
|
||||
var i, ii;
|
||||
for (i = 0, ii = numbers.length; i < ii;) {
|
||||
@@ -122,7 +122,7 @@ Polyline.decodeDeltas = function(encoded, stride, opt_factor) {
|
||||
}
|
||||
|
||||
return numbers;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -137,15 +137,15 @@ Polyline.decodeDeltas = function(encoded, stride, opt_factor) {
|
||||
* @return {string} The encoded string.
|
||||
* @api
|
||||
*/
|
||||
Polyline.encodeFloats = function(numbers, opt_factor) {
|
||||
export function encodeFloats(numbers, opt_factor) {
|
||||
var factor = opt_factor ? opt_factor : 1e5;
|
||||
var i, ii;
|
||||
for (i = 0, ii = numbers.length; i < ii; ++i) {
|
||||
numbers[i] = Math.round(numbers[i] * factor);
|
||||
}
|
||||
|
||||
return Polyline.encodeSignedIntegers(numbers);
|
||||
};
|
||||
return encodeSignedIntegers(numbers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -157,15 +157,15 @@ Polyline.encodeFloats = function(numbers, opt_factor) {
|
||||
* @return {Array.<number>} A list of floating point numbers.
|
||||
* @api
|
||||
*/
|
||||
Polyline.decodeFloats = function(encoded, opt_factor) {
|
||||
export function decodeFloats(encoded, opt_factor) {
|
||||
var factor = opt_factor ? opt_factor : 1e5;
|
||||
var numbers = Polyline.decodeSignedIntegers(encoded);
|
||||
var numbers = decodeSignedIntegers(encoded);
|
||||
var i, ii;
|
||||
for (i = 0, ii = numbers.length; i < ii; ++i) {
|
||||
numbers[i] /= factor;
|
||||
}
|
||||
return numbers;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -176,14 +176,14 @@ Polyline.decodeFloats = function(encoded, opt_factor) {
|
||||
* @param {Array.<number>} numbers A list of signed integers.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
Polyline.encodeSignedIntegers = function(numbers) {
|
||||
export function encodeSignedIntegers(numbers) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = numbers.length; i < ii; ++i) {
|
||||
var num = numbers[i];
|
||||
numbers[i] = (num < 0) ? ~(num << 1) : (num << 1);
|
||||
}
|
||||
return Polyline.encodeUnsignedIntegers(numbers);
|
||||
};
|
||||
return encodeUnsignedIntegers(numbers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -192,15 +192,15 @@ Polyline.encodeSignedIntegers = function(numbers) {
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {Array.<number>} A list of signed integers.
|
||||
*/
|
||||
Polyline.decodeSignedIntegers = function(encoded) {
|
||||
var numbers = Polyline.decodeUnsignedIntegers(encoded);
|
||||
export function decodeSignedIntegers(encoded) {
|
||||
var numbers = decodeUnsignedIntegers(encoded);
|
||||
var i, ii;
|
||||
for (i = 0, ii = numbers.length; i < ii; ++i) {
|
||||
var num = numbers[i];
|
||||
numbers[i] = (num & 1) ? ~(num >> 1) : (num >> 1);
|
||||
}
|
||||
return numbers;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -209,14 +209,14 @@ Polyline.decodeSignedIntegers = function(encoded) {
|
||||
* @param {Array.<number>} numbers A list of unsigned integers.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
Polyline.encodeUnsignedIntegers = function(numbers) {
|
||||
export function encodeUnsignedIntegers(numbers) {
|
||||
var encoded = '';
|
||||
var i, ii;
|
||||
for (i = 0, ii = numbers.length; i < ii; ++i) {
|
||||
encoded += Polyline.encodeUnsignedInteger(numbers[i]);
|
||||
encoded += encodeUnsignedInteger(numbers[i]);
|
||||
}
|
||||
return encoded;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -225,7 +225,7 @@ Polyline.encodeUnsignedIntegers = function(numbers) {
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {Array.<number>} A list of unsigned integers.
|
||||
*/
|
||||
Polyline.decodeUnsignedIntegers = function(encoded) {
|
||||
export function decodeUnsignedIntegers(encoded) {
|
||||
var numbers = [];
|
||||
var current = 0;
|
||||
var shift = 0;
|
||||
@@ -242,7 +242,7 @@ Polyline.decodeUnsignedIntegers = function(encoded) {
|
||||
}
|
||||
}
|
||||
return numbers;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -251,7 +251,7 @@ Polyline.decodeUnsignedIntegers = function(encoded) {
|
||||
* @param {number} num Unsigned integer that should be encoded.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
Polyline.encodeUnsignedInteger = function(num) {
|
||||
export function encodeUnsignedInteger(num) {
|
||||
var value, encoded = '';
|
||||
while (num >= 0x20) {
|
||||
value = (0x20 | (num & 0x1f)) + 63;
|
||||
@@ -261,7 +261,7 @@ Polyline.encodeUnsignedInteger = function(num) {
|
||||
value = num + 63;
|
||||
encoded += String.fromCharCode(value);
|
||||
return encoded;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -324,9 +324,8 @@ Polyline.prototype.readGeometry;
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polyline.prototype.readGeometryFromText = function(text, opt_options) {
|
||||
var stride = SimpleGeometry.getStrideForLayout(this.geometryLayout_);
|
||||
var flatCoordinates = Polyline.decodeDeltas(
|
||||
text, stride, this.factor_);
|
||||
var stride = getStrideForLayout(this.geometryLayout_);
|
||||
var flatCoordinates = decodeDeltas(text, stride, this.factor_);
|
||||
_ol_geom_flat_flip_.flipXY(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
|
||||
var coordinates = _ol_geom_flat_inflate_.coordinates(
|
||||
@@ -396,6 +395,6 @@ Polyline.prototype.writeGeometryText = function(geometry, opt_options) {
|
||||
var stride = geometry.getStride();
|
||||
_ol_geom_flat_flip_.flipXY(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
|
||||
return Polyline.encodeDeltas(flatCoordinates, stride, this.factor_);
|
||||
return encodeDeltas(flatCoordinates, stride, this.factor_);
|
||||
};
|
||||
export default Polyline;
|
||||
|
||||
@@ -48,10 +48,9 @@ inherits(SimpleGeometry, Geometry);
|
||||
|
||||
/**
|
||||
* @param {number} stride Stride.
|
||||
* @private
|
||||
* @return {ol.geom.GeometryLayout} layout Layout.
|
||||
*/
|
||||
SimpleGeometry.getLayoutForStride_ = function(stride) {
|
||||
function getLayoutForStride(stride) {
|
||||
var layout;
|
||||
if (stride == 2) {
|
||||
layout = GeometryLayout.XY;
|
||||
@@ -61,14 +60,14 @@ SimpleGeometry.getLayoutForStride_ = function(stride) {
|
||||
layout = GeometryLayout.XYZM;
|
||||
}
|
||||
return /** @type {ol.geom.GeometryLayout} */ (layout);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryLayout} layout Layout.
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
SimpleGeometry.getStrideForLayout = function(layout) {
|
||||
export function getStrideForLayout(layout) {
|
||||
var stride;
|
||||
if (layout == GeometryLayout.XY) {
|
||||
stride = 2;
|
||||
@@ -78,7 +77,7 @@ SimpleGeometry.getStrideForLayout = function(layout) {
|
||||
stride = 4;
|
||||
}
|
||||
return /** @type {number} */ (stride);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -205,7 +204,7 @@ SimpleGeometry.prototype.getStride = function() {
|
||||
* @protected
|
||||
*/
|
||||
SimpleGeometry.prototype.setFlatCoordinatesInternal = function(layout, flatCoordinates) {
|
||||
this.stride = SimpleGeometry.getStrideForLayout(layout);
|
||||
this.stride = getStrideForLayout(layout);
|
||||
this.layout = layout;
|
||||
this.flatCoordinates = flatCoordinates;
|
||||
};
|
||||
@@ -229,7 +228,7 @@ SimpleGeometry.prototype.setLayout = function(layout, coordinates, nesting) {
|
||||
/** @type {number} */
|
||||
var stride;
|
||||
if (layout) {
|
||||
stride = SimpleGeometry.getStrideForLayout(layout);
|
||||
stride = getStrideForLayout(layout);
|
||||
} else {
|
||||
var i;
|
||||
for (i = 0; i < nesting; ++i) {
|
||||
@@ -242,7 +241,7 @@ SimpleGeometry.prototype.setLayout = function(layout, coordinates, nesting) {
|
||||
}
|
||||
}
|
||||
stride = coordinates.length;
|
||||
layout = SimpleGeometry.getLayoutForStride_(stride);
|
||||
layout = getLayoutForStride(stride);
|
||||
}
|
||||
this.layout = layout;
|
||||
this.stride = stride;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import _ol_Feature_ from '../../../../src/ol/Feature.js';
|
||||
import Polyline from '../../../../src/ol/format/Polyline.js';
|
||||
import Polyline, * as polyline from '../../../../src/ol/format/Polyline.js';
|
||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
||||
import {get as getProjection, transform} from '../../../../src/ol/proj.js';
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('encodeDeltas', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeDeltas = Polyline.encodeDeltas;
|
||||
var encodeDeltas = polyline.encodeDeltas;
|
||||
|
||||
expect(encodeDeltas(flippedFlatPoints, 2)).to.eql(encodedFlatPoints);
|
||||
});
|
||||
@@ -68,7 +68,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('decodeDeltas', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeDeltas = Polyline.decodeDeltas;
|
||||
var decodeDeltas = polyline.decodeDeltas;
|
||||
|
||||
expect(decodeDeltas(encodedFlatPoints, 2)).to.eql(flippedFlatPoints);
|
||||
});
|
||||
@@ -77,7 +77,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('encodeFloats', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeFloats = Polyline.encodeFloats;
|
||||
var encodeFloats = polyline.encodeFloats;
|
||||
|
||||
expect(encodeFloats(smallFloats)).to.eql(encodedFloats);
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('decodeFloats', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeFloats = Polyline.decodeFloats;
|
||||
var decodeFloats = polyline.decodeFloats;
|
||||
|
||||
expect(decodeFloats(encodedFloats)).to.eql(smallFloats);
|
||||
expect(decodeFloats(encodedFloats, 1e5)).to.eql(smallFloats);
|
||||
@@ -101,7 +101,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('encodeSignedIntegers', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeSignedIntegers = Polyline.encodeSignedIntegers;
|
||||
var encodeSignedIntegers = polyline.encodeSignedIntegers;
|
||||
|
||||
expect(encodeSignedIntegers(
|
||||
signedIntegers)).to.eql(encodedSignedIntegers);
|
||||
@@ -110,7 +110,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('decodeSignedIntegers', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeSignedIntegers = Polyline.decodeSignedIntegers;
|
||||
var decodeSignedIntegers = polyline.decodeSignedIntegers;
|
||||
|
||||
expect(decodeSignedIntegers(
|
||||
encodedSignedIntegers)).to.eql(signedIntegers);
|
||||
@@ -120,7 +120,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('encodeUnsignedIntegers', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeUnsignedIntegers = Polyline.encodeUnsignedIntegers;
|
||||
var encodeUnsignedIntegers = polyline.encodeUnsignedIntegers;
|
||||
|
||||
expect(encodeUnsignedIntegers(
|
||||
unsignedIntegers)).to.eql(encodedUnsignedIntegers);
|
||||
@@ -129,7 +129,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('decodeUnsignedIntegers', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeUnsignedIntegers = Polyline.decodeUnsignedIntegers;
|
||||
var decodeUnsignedIntegers = polyline.decodeUnsignedIntegers;
|
||||
|
||||
expect(decodeUnsignedIntegers(
|
||||
encodedUnsignedIntegers)).to.eql(unsignedIntegers);
|
||||
@@ -139,7 +139,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('encodeFloat', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeFloats = Polyline.encodeFloats;
|
||||
var encodeFloats = polyline.encodeFloats;
|
||||
|
||||
expect(encodeFloats([0.00000])).to.eql('?');
|
||||
expect(encodeFloats([-0.00001])).to.eql('@');
|
||||
@@ -162,7 +162,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('decodeFloat', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeFloats = Polyline.decodeFloats;
|
||||
var decodeFloats = polyline.decodeFloats;
|
||||
|
||||
expect(decodeFloats('?')).to.eql([0.00000]);
|
||||
expect(decodeFloats('@')).to.eql([-0.00001]);
|
||||
@@ -186,7 +186,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('encodeSignedInteger', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeSignedIntegers = Polyline.encodeSignedIntegers;
|
||||
var encodeSignedIntegers = polyline.encodeSignedIntegers;
|
||||
|
||||
expect(encodeSignedIntegers([0])).to.eql('?');
|
||||
expect(encodeSignedIntegers([-1])).to.eql('@');
|
||||
@@ -204,7 +204,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('decodeSignedInteger', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeSignedIntegers = Polyline.decodeSignedIntegers;
|
||||
var decodeSignedIntegers = polyline.decodeSignedIntegers;
|
||||
|
||||
expect(decodeSignedIntegers('?')).to.eql([0]);
|
||||
expect(decodeSignedIntegers('@')).to.eql([-1]);
|
||||
@@ -223,7 +223,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('encodeUnsignedInteger', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeUnsignedInteger = Polyline.encodeUnsignedInteger;
|
||||
var encodeUnsignedInteger = polyline.encodeUnsignedInteger;
|
||||
|
||||
expect(encodeUnsignedInteger(0)).to.eql('?');
|
||||
expect(encodeUnsignedInteger(1)).to.eql('@');
|
||||
@@ -243,7 +243,7 @@ describe('ol.format.Polyline', function() {
|
||||
|
||||
describe('decodeUnsignedInteger', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeUnsignedIntegers = Polyline.decodeUnsignedIntegers;
|
||||
var decodeUnsignedIntegers = polyline.decodeUnsignedIntegers;
|
||||
|
||||
expect(decodeUnsignedIntegers('?')).to.eql([0]);
|
||||
expect(decodeUnsignedIntegers('@')).to.eql([1]);
|
||||
@@ -320,7 +320,7 @@ describe('ol.format.Polyline', function() {
|
||||
});
|
||||
|
||||
it('parses XYZ linestring', function() {
|
||||
var xyz = Polyline.encodeDeltas([
|
||||
var xyz = polyline.encodeDeltas([
|
||||
38.500, -120.200, 100,
|
||||
40.700, -120.950, 200,
|
||||
43.252, -126.453, 20
|
||||
|
||||
Reference in New Issue
Block a user