-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath.js
More file actions
64 lines (58 loc) · 2.43 KB
/
math.js
File metadata and controls
64 lines (58 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/******************************************************************************************************/
/**
* converts degrees to radius
* @param degrees
* @returns {Number}
*/
function deg2rad(degrees) {
return Math.PI * (degrees / 180);
}
/******************************************************************************************************/
/**
* Calculates the total distance between objects
* @param latLng
* @param tempLatLng
* @returns {Number}
*/
function distances(aLon, aLat, bLon, bLat) {
var dlat = aLat - bLat,
dlon = aLon - bLon,
a = Math.pow(Math.sin(deg2rad(dlat / 2)), 2) + Math.cos(deg2rad(aLat)) * Math.cos(deg2rad(bLat)) * Math.pow(Math.sin(deg2rad(dlon / 2)), 2);
var totalDistance = RADIUS_OF_EARTH * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return Math.round((totalDistance/1000)*100)/100;
}
/******************************************************************************************************/
/**
*
* @param event
*/
function setBounds(event){
bbox = event.features[0].geometry.getBounds();
// var tbbox = event.features[0].geometry.getVertices();
// bbox.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
// var answer = "bottom: " + tbbox.bottom + "\n";
// answer += "left: " + tbbox.left + "\n";
// answer += "right: " + tbbox.right + "\n";
// answer += "top: " + tbbox.top + "\n";
// alert(answer);
// boxes = "&boxes=" + bounds.top + "_" + bounds.left + "_" + bounds.bottom + "_" + bounds.right;
}
/******************************************************************************************************/
function getBounds(){
return bbox;
}
/******************************************************************************************************/
function is_in_bb(north, east, south, west, lonlat){
//top-north, right-east, bottom-south, left-west
// lonlat.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
//alert(lonlat.lat);
if( north >= lonlat.lat && lonlat.lat >= south && east >= lonlat.lon && lonlat.lon >= west ){
return true; // Point is in bounding box
}
else{
return false;
}
// bb is the boundingbox, (ix,iy) (north,east) are its top-left coordinates,
// and (ax,ay) (south,west) its bottom-right coordinates. p is the point and (x,y) its coordinates.
}
/******************************************************************************************************/