2010-09-07 00:14:04 +08:00
|
|
|
describe('LatLng', function() {
|
2010-09-07 00:06:38 +08:00
|
|
|
describe('constructor', function() {
|
2013-02-20 04:41:48 +08:00
|
|
|
it("sets lat and lng", function() {
|
2010-09-07 00:06:38 +08:00
|
|
|
var a = new L.LatLng(25, 74);
|
|
|
|
expect(a.lat).toEqual(25);
|
|
|
|
expect(a.lng).toEqual(74);
|
2012-12-12 18:04:54 +08:00
|
|
|
|
2013-02-20 00:18:15 +08:00
|
|
|
var b = new L.LatLng(-25, -74);
|
|
|
|
expect(b.lat).toEqual(-25);
|
|
|
|
expect(b.lng).toEqual(-74);
|
2010-09-07 00:06:38 +08:00
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('throws an error if invalid lat or lng', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(function () {
|
|
|
|
var a = new L.LatLng(NaN, NaN);
|
|
|
|
}).toThrow();
|
|
|
|
});
|
2012-12-12 18:04:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#equals', function() {
|
2013-02-20 04:41:48 +08:00
|
|
|
it("returns true if compared objects are equal within a certain margin", function() {
|
2012-12-12 18:04:54 +08:00
|
|
|
var a = new L.LatLng(10, 20);
|
|
|
|
var b = new L.LatLng(10 + 1.0E-10, 20 - 1.0E-10);
|
|
|
|
expect(a.equals(b)).toBe(true);
|
2010-09-07 00:06:38 +08:00
|
|
|
});
|
2012-12-12 18:04:54 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it("returns false if compared objects are not equal within a certain margin", function() {
|
2012-12-12 18:04:54 +08:00
|
|
|
var a = new L.LatLng(10, 20);
|
|
|
|
var b = new L.LatLng(10, 23.3);
|
|
|
|
expect(a.equals(b)).toBe(false);
|
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns false if passed non-valid object', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var a = new L.LatLng(10, 20);
|
|
|
|
expect(a.equals(null)).toBe(false);
|
|
|
|
});
|
2012-12-12 18:04:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#wrap', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it("wraps longitude to lie between -180 and 180 by default", function() {
|
2012-12-12 18:04:54 +08:00
|
|
|
var a = new L.LatLng(0, 190).wrap().lng;
|
2010-09-07 00:06:38 +08:00
|
|
|
expect(a).toEqual(-170);
|
2011-12-21 21:22:07 +08:00
|
|
|
|
2012-12-12 18:04:54 +08:00
|
|
|
var b = new L.LatLng(0, 360).wrap().lng;
|
2010-09-07 00:06:38 +08:00
|
|
|
expect(b).toEqual(0);
|
2012-12-12 18:04:54 +08:00
|
|
|
|
|
|
|
var c = new L.LatLng(0, 380).wrap().lng;
|
2010-09-07 00:06:38 +08:00
|
|
|
expect(c).toEqual(20);
|
2012-12-12 18:04:54 +08:00
|
|
|
|
|
|
|
var d = new L.LatLng(0, -190).wrap().lng;
|
2010-09-07 00:06:38 +08:00
|
|
|
expect(d).toEqual(170);
|
2012-12-12 18:04:54 +08:00
|
|
|
|
|
|
|
var e = new L.LatLng(0, -360).wrap().lng;
|
2010-09-07 00:06:38 +08:00
|
|
|
expect(e).toEqual(0);
|
2012-12-12 18:04:54 +08:00
|
|
|
|
|
|
|
var f = new L.LatLng(0, -380).wrap().lng;
|
2010-09-07 00:06:38 +08:00
|
|
|
expect(f).toEqual(-20);
|
2011-12-21 21:22:07 +08:00
|
|
|
|
2012-12-12 18:04:54 +08:00
|
|
|
var g = new L.LatLng(0, 90).wrap().lng;
|
2011-12-21 21:22:07 +08:00
|
|
|
expect(g).toEqual(90);
|
|
|
|
|
2012-12-12 18:04:54 +08:00
|
|
|
var h = new L.LatLng(0, 180).wrap().lng;
|
2011-12-21 21:22:07 +08:00
|
|
|
expect(h).toEqual(180);
|
2010-09-07 00:06:38 +08:00
|
|
|
});
|
2012-12-12 18:04:54 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it("wraps longitude within the given range", function() {
|
2012-12-12 18:04:54 +08:00
|
|
|
var a = new L.LatLng(0, 190).wrap(-100, 100).lng;
|
|
|
|
expect(a).toEqual(-10);
|
2010-09-07 00:06:38 +08:00
|
|
|
});
|
2012-12-12 18:04:54 +08:00
|
|
|
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#toString', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('formats a string', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var a = new L.LatLng(10.333333333, 20.2222222);
|
|
|
|
expect(a.toString(3)).toEqual('LatLng(10.333, 20.222)');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#distanceTo', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('calculates distance in meters', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var a = new L.LatLng(50.5, 30.5);
|
|
|
|
var b = new L.LatLng(50, 1);
|
|
|
|
|
|
|
|
expect(Math.abs(Math.round(a.distanceTo(b) / 1000) - 2084) < 5).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('L.latLng factory', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns LatLng instance as is', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var a = new L.LatLng(50, 30);
|
|
|
|
|
|
|
|
expect(L.latLng(a)).toBe(a);
|
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('accepts an array of coordinates', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(L.latLng([50, 30])).toEqual(new L.LatLng(50, 30));
|
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('passes null or undefined as is', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(L.latLng(undefined)).toBe(undefined);
|
|
|
|
expect(L.latLng(null)).toBe(null);
|
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('creates a LatLng object from two coordinates', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(L.latLng(50, 30)).toEqual(new L.LatLng(50, 30));
|
|
|
|
});
|
2013-02-20 00:01:53 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('accepts an object with lat/lng', function () {
|
2013-02-20 00:01:53 +08:00
|
|
|
expect(L.latLng({lat: 50, lng: 30})).toEqual(new L.LatLng(50, 30));
|
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('accepts an object with lat/lon', function () {
|
2013-02-20 00:01:53 +08:00
|
|
|
expect(L.latLng({lat: 50, lon: 30})).toEqual(new L.LatLng(50, 30));
|
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
2010-09-07 00:06:38 +08:00
|
|
|
});
|
|
|
|
|