1var geoHelper = (function() 2{ 3 /** 4 * Calculate the distance between two coordinates 5 * @returns the spherical distance in meters 6 */ 7 var getDistance = function (co1, co2) 8 { 9 if (!co1.lat || !co2.lat || !co1.lon || !co2.lon) 10 return -1; 11 var R = 6.371e6; // average radius of the earth in m 12 var dLat = (co2.lat-co1.lat) * Math.PI/180; 13 var dLon = (co2.lon-co1.lon) * Math.PI/180; 14 var a = 15 0.5 - Math.cos(dLat)/2 + 16 (0.5 - Math.cos(dLon)/2) * 17 Math.cos(co1.lat * Math.PI/180) * 18 Math.cos(co2.lat * Math.PI/180); 19 return R * 2 * Math.asin(Math.sqrt(a)); // Distance in m 20 }; 21 22 /** 23 * Transform latitude, longitude and zoom to tile coordinates 24 */ 25 var latlonToTilenumber = function (lat, lon, zoom) 26 { 27 var n = Math.pow(2, zoom); 28 var lat_rad = lat * Math.PI / 180; 29 return { 30 "x": Math.floor(n * ((lon + 180) / 360)), 31 "y": Math.floor(n * (1 - (Math.log(Math.tan(lat_rad) + 1/Math.cos(lat_rad)) / Math.PI)) / 2) } 32 }; 33 34 var tilenumberToBbox = function (x, y, zoom) 35 { 36 var northWest = tilenumberToLatlon(x, y, zoom); 37 var southEast = tilenumberToLatlon(x + 1, y + 1, zoom); 38 return { 39 "t" : northWest.lat, 40 "b" : southEast.lat, 41 "l" : northWest.lon, 42 "r" : southEast.lon, 43 }; 44 }; 45 46 var tilenumberToLatlon = function(x, y, zoom) 47 { 48 var n = Math.PI - (2.0 * Math.PI * y) / Math.pow(2.0, zoom); 49 return { 50 "lat": Math.atan(Math.sinh(n)) *180 / Math.PI, 51 "lon": x / Math.pow(2, zoom) * 360.0 - 180 52 }; 53 }; 54 55 var padBbox = function (bbox, distance) 56 { 57 var corners = 58 { 59 "tl": {"lat": bbox.t, "lon": bbox.l}, 60 "tr": {"lat": bbox.t, "lon": bbox.r}, 61 "bl": {"lat": bbox.b, "lon": bbox.l}, 62 "br": {"lat": bbox.b, "lon": bbox.r}, 63 }; 64 var l = Math.max( 65 getDistance(corners.tl, corners.tr), 66 getDistance(corners.bl, corners.br), 67 getDistance(corners.tl, corners.bl), 68 getDistance(corners.tr, corners.br) 69 ); 70 var padding = distance / l; 71 bbox.t += (bbox.t - bbox.b) * padding; 72 bbox.b -= (bbox.t - bbox.b) * padding; 73 bbox.r += (bbox.r - bbox.l) * padding; 74 bbox.l -= (bbox.r - bbox.l) * padding; 75 }; 76 77 return { 78 "getDistance": getDistance, 79 "latlonToTilenumber": latlonToTilenumber, 80 "tilenumberToLatlon": tilenumberToLatlon, 81 "tilenumberToBbox": tilenumberToBbox, 82 "padBbox": padBbox, 83 }; 84})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.