Files
iD/test/spec/util/units.js
Martin Raifer 607f953465 add alternative formats for coordinate search: (#10805)
* zoom/x/y – copy/paste from an osm.org URL or web map with map-hash param (this also sets map zoom to the respective value)
* x/y – like the above, but does not set zoom level
* x y – where x and y are numbers in the user's locale's number format
2025-03-11 21:20:21 +01:00

78 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
describe('iD.units', function() {
describe('dmsMatcher', function() {
it('parses D M SS format', function() {
var result = iD.dmsMatcher('35 11 10.1 , 136 49 53.8');
expect(result[0]).to.be.closeTo( 35.18614, 0.00001);
expect(result[1]).to.be.closeTo(136.83161, 0.00001);
});
it('parses D M SS format, with negative value', function() {
var result = iD.dmsMatcher('-35 11 10.1 , -136 49 53.8');
expect(result[0]).to.be.closeTo( -35.18614, 0.00001);
expect(result[1]).to.be.closeTo(-136.83161, 0.00001);
});
it('parses D MM format', function() {
var result = iD.dmsMatcher('35 11.1683 , 136 49.8966');
expect(result[0]).to.be.closeTo( 35.18614, 0.00001);
expect(result[1]).to.be.closeTo(136.83161, 0.00001);
});
it('parses D MM format, with negative value', function() {
var result = iD.dmsMatcher('-35 11.1683 , -136 49.8966');
expect(result[0]).to.be.closeTo( -35.18614, 0.00001);
expect(result[1]).to.be.closeTo(-136.83161, 0.00001);
});
it('parses z/x/y coordinate', () => {
var result = iD.dmsMatcher('2/-1.23/34.44');
expect(result[0]).to.be.closeTo(-1.23, 0.00001);
expect(result[1]).to.be.closeTo(34.44, 0.00001);
expect(result[2]).to.eql(2);
});
it('parses x/y coordinate', () => {
var result = iD.dmsMatcher('-1.23/34.44');
expect(result[0]).to.be.closeTo(-1.23, 0.00001);
expect(result[1]).to.be.closeTo(34.44, 0.00001);
});
it('parses z/x/y coordinate', () => {
var result = iD.dmsMatcher('2/-1.23/34.44');
expect(result[0]).to.be.closeTo(-1.23, 0.00001);
expect(result[1]).to.be.closeTo(34.44, 0.00001);
expect(result[2]).to.eql(2);
});
it('parses coordinate with localized numbers', () => {
var result = iD.dmsMatcher('49,4109399, 8,7147086', 'de');
expect(result[0]).to.be.closeTo(49.4109399, 0.00001);
expect(result[1]).to.be.closeTo( 8.7147086, 0.00001);
});
it('handles invalid input', function() {
var result = iD.dmsMatcher('!@#$');
expect(result).to.be.null;
});
});
describe('dmsCoordinatePair', function() {
it('formats coordinate pair', function () {
var result = iD.dmsCoordinatePair([90 + 0.5/3600, 45]);
expect(result).to.be.eql('45°N, 90°01″E');
});
it('formats 0°', function () {
var result = iD.dmsCoordinatePair([0, 0]);
expect(result).to.be.eql('0°, 0°');
});
it('formats negative value', function () {
var result = iD.dmsCoordinatePair([-179, -90]);
expect(result).to.be.eql('90°S, 179°W');
});
it('formats 180° lng, should be E or W', function () {
// The longitude at this line can be given as either east or west.
var result = iD.dmsCoordinatePair([180, 0]);
expect(result).to.be.oneOf(['0°, 180°W', '0°, 180E°']);
});
it('formats value over 90°lat or 180°lng', function () {
var result = iD.dmsCoordinatePair([181, 91]);
expect(result).to.be.oneOf(['90°N, 179°W']);
});
});
});