2013-03-02 05:49:20 +08:00
|
|
|
describe("Projection.Mercator", function() {
|
2010-09-07 16:59:58 +08:00
|
|
|
var p = L.Projection.Mercator;
|
2013-02-20 00:18:15 +08:00
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect.Assertion.prototype.near = function(expected, delta) {
|
2013-03-02 07:27:16 +08:00
|
|
|
delta = delta || 1;
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(this.obj.x).to
|
2013-03-02 06:14:14 +08:00
|
|
|
.be.within(expected.x - delta, expected.x + delta);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(this.obj.y).to
|
2013-03-02 06:14:14 +08:00
|
|
|
.be.within(expected.y - delta, expected.y + delta);
|
2013-03-02 05:49:20 +08:00
|
|
|
};
|
2010-09-07 16:59:58 +08:00
|
|
|
|
|
|
|
describe("#project", function() {
|
2013-03-02 06:14:14 +08:00
|
|
|
it("projects a center point", function() {
|
2010-09-07 16:59:58 +08:00
|
|
|
//edge cases
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(p.project(new L.LatLng(0, 0))).near(new L.Point(0, 0));
|
2013-03-02 06:14:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("projects the northeast corner of the world", function() {
|
|
|
|
expect(p.project(new L.LatLng(90, 180))).near(new L.Point(20037508.342789244, 19970326.50745906));
|
|
|
|
});
|
2013-02-20 00:18:15 +08:00
|
|
|
|
2013-03-02 06:14:14 +08:00
|
|
|
it("projects the southwest corner of the world", function() {
|
|
|
|
expect(p.project(new L.LatLng(-90, -180))).near(new L.Point(-20037508, -19970326));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("projects 50, 30", function() {
|
|
|
|
expect(p.project(new L.LatLng(50, 30))).near(new L.Point(3339584, 6392021));
|
2010-09-07 16:59:58 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#unproject", function() {
|
2013-03-02 06:14:14 +08:00
|
|
|
function pr(point) {
|
|
|
|
return p.project(p.unproject(point));
|
|
|
|
}
|
2013-02-20 00:18:15 +08:00
|
|
|
|
2013-03-02 06:14:14 +08:00
|
|
|
it("unprojects a center point", function() {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(pr(new L.Point(0, 0))).near(new L.Point(0, 0));
|
2013-03-02 06:14:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("pi points", function() {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(pr(new L.Point(-Math.PI, Math.PI))).near(new L.Point(-Math.PI, Math.PI));
|
|
|
|
expect(pr(new L.Point(-Math.PI, -Math.PI))).near(new L.Point(-Math.PI, -Math.PI));
|
2013-02-20 00:18:15 +08:00
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(pr(new L.Point(0.523598775598, 1.010683188683))).near(new L.Point(0.523598775598, 1.010683188683));
|
2010-09-07 16:59:58 +08:00
|
|
|
});
|
2010-09-07 00:17:27 +08:00
|
|
|
});
|
2013-02-20 00:18:15 +08:00
|
|
|
});
|