Merge pull request #1 from coolaj86/patch-2

Make the code work!
This commit is contained in:
AJ ONeal 2016-07-25 22:58:46 -04:00 committed by GitHub
commit ce2e39a090
1 changed files with 37 additions and 5 deletions

View File

@ -23,12 +23,12 @@
// (so GetSizeIJ for a cell is always 1)
(function() {
'use strict';
window.S2 = {};
var LatLngToXYZ = function(latLng) {
var d2r = L.LatLng.DEG_TO_RAD;
var d2r = S2.L.LatLng.DEG_TO_RAD;
var phi = latLng.lat*d2r;
var theta = latLng.lng*d2r;
@ -39,12 +39,12 @@ var LatLngToXYZ = function(latLng) {
};
var XYZToLatLng = function(xyz) {
var r2d = L.LatLng.RAD_TO_DEG;
var r2d = S2.L.LatLng.RAD_TO_DEG;
var lat = Math.atan2(xyz[2], Math.sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]));
var lng = Math.atan2(xyz[1], xyz[0]);
return L.latLng(lat*r2d, lng*r2d);
return S2.L.LatLng(lat*r2d, lng*r2d);
};
var largestAbsComponent = function(xyz) {
@ -92,7 +92,7 @@ var XYZToFaceUV = function(xyz) {
face += 3;
}
uv = faceXYZToUV (face,xyz);
var uv = faceXYZToUV (face,xyz);
return [face, uv];
};
@ -305,3 +305,35 @@ S2.S2Cell.prototype.getNeighbors = function() {
})();
(function () {
'use strict';
// Adapted from Leafletjs https://searchcode.com/codesearch/view/42525008/
var L = {};
L.LatLng = function (/*Number*/ rawLat, /*Number*/ rawLng, /*Boolean*/ noWrap) {
var lat = parseFloat(rawLat, 10);
var lng = parseFloat(rawLng, 10);
if (isNaN(lat) || isNaN(lng)) {
throw new Error('Invalid LatLng object: (' + rawLat + ', ' + rawLng + ')');
}
if (noWrap !== true) {
lat = Math.max(Math.min(lat, 90), -90); // clamp latitude into -90..90
lng = (lng + 180) % 360 + ((lng < -180 || lng === 180) ? 180 : -180); // wrap longtitude into -180..180
}
return { lat: lat, lng: lng };
};
L.LatLng.DEG_TO_RAD = Math.PI / 180;
L.LatLng.RAD_TO_DEG = 180 / Math.PI;
if (!window.L) {
window.L = L;
}
S2.L = L;
})();