Debian Codegraph @

dojox/geo/openlayers/GreatCircle.js

raw symbols SCIP
1 define([
2 "dojo/_base/lang",
3 "./_base",
4 "./GeometryFeature"
5 ], function(lang, openlayers, GeometryFeature){
6
7 var gc = openlayers.GreatCircle = {
8
9 toPointArray: function(p1, p2, increment){
10 // summary:
11 // Create a geodetic line as an array of OpenLayers.Point.
12 // description:
13 // Create a geodetic line as an array of OpenLayers.Point between the point p1
14 // and the point p2. Result is a polyline approximation for which a new point is
15 // calculated every <em>increment</em> degrees.
16 // p1: Point
17 // The first point of the geodetic line. x and y fields are longitude and
18 // latitude in decimal degrees.
19 // p2: Point
20 // The second point of the geodetic line. x and y fields are longitude and
21 // latitude in decimal degrees.
22 // increment: Float
23 // The value at which a new point is computed.
24 var startLon = p1.x;
25 var endLon = p2.x;
26 var sl = Math.min(startLon, endLon);
27 var el = Math.max(startLon, endLon);
28
29 var d2r = this.DEG2RAD;
30 var lat1 = p1.y * d2r;
31 var lon1 = p1.x * d2r;
32 var lat2 = p2.y * d2r;
33 var lon2 = p2.x * d2r;
34
35 if(Math.abs(lon1 - lon2) <= this.TOLERANCE){
36 var l = Math.min(lon1, lon2);
37 lon2 = l + Math.PI;
38 }
39
40 if(Math.abs(lon2 - lon1) == Math.PI){
41 if(lat1 + lat2 == 0.0){
42 lat2 += Math.PI / 180000000;
43 }
44 }
45
46 var lon = sl * d2r;
47 var elon = el * d2r;
48 var incr = increment * d2r;
49 var wp = [];
50 var k = 0;
51 var r2d = this.RAD2DEG;
52
53 while(lon <= elon){
54 lat = Math.atan((Math.sin(lat1) * Math.cos(lat2) * Math.sin(lon - lon2) - Math.sin(lat2) * Math.cos(lat1)
55 * Math.sin(lon - lon1))
56 / (Math.cos(lat1) * Math.cos(lat2) * Math.sin(lon1 - lon2)));
57 var p = {
58 x: lon * r2d,
59 y: lat * r2d
60 };
61 wp[k++] = p;
62 if(lon < elon && (lon + incr) >= elon){
63 lon = elon;
64 }else{
65 lon = lon + incr;
66 }
67 }
68 return wp;
69 },
70
71 toLineString: function(p1, p2, increment){
72 // summary:
73 // Create a geodetic line as an array of OpenLayers.Geometry.LineString.
74 // description:
75 // Create a geodetic line as a OpenLayers.Geometry.LineString between the point p1
76 // and the point p2. Result is a polyline approximation for which a new point is
77 // calculated every <em>increment</em> degrees.
78 // p1: Point
79 // The first point of the geodetic line. x and y fields are longitude and
80 // latitude in decimal degrees.
81 // p2: Point
82 // The second point of the geodetic line. x and y fields are longitude and
83 // latitude in decimal degrees.
84 // increment: Float
85 // The value at which a new point is computed.
86 var wp = this.toPointArray(p1, p2, increment);
87 var ls = new OpenLayers.Geometry.LineString(wp);
88 return ls;
89 },
90
91 toGeometryFeature: function(p1, p2, increment){
92 // summary:
93 // Create a geodetic line as an array of dojox.geo.openlayers.GeometryFeature.
94 // description:
95 // Create a geodetic line as a dojox.geo.openlayers.GeometryFeature between the point p1
96 // ant the point p2. Result is a polyline approximation for which a new point is
97 // calculated every <em>increment</em> degrees.
98 // p1: Point
99 // The first point of the geodetic line. x and y fields are longitude and
100 // latitude in decimal degrees.
101 // p2: Point
102 // The second point of the geodetic line. x and y fields are longitude and
103 // latitude in decimal degrees.
104 // increment: Float
105 // The value at which a new point is computed.
106 // returns:
107 // The geodetic line as a GeometryFeature
108
109 var ls = this.toLineString(p1, p2, increment);
110 return new GeometryFeature(ls); // GeometryFeature
111 },
112
113 DEG2RAD: Math.PI / 180,
114
115 RAD2DEG: 180 / Math.PI,
116
117 TOLERANCE: 0.00001
118 };
119
120 return gc;
121 });