source: Dev/branches/rest-dojo-ui/client/dojox/geo/openlayers/GreatCircle.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 3.9 KB
Line 
1define(["dojo/_base/lang",
2                                "dojox/geo/openlayers/GeometryFeature",
3                                "dojox/geo/openlayers/Point",
4                                "dojox/geo/openlayers/LineString"], function(lang, GeometryFeature, Point, lineString){
5
6        lang.getObject("geo.openlayers", true, dojox);
7
8        dojox.geo.openlayers.GreatCircle = {
9
10                toPointArray : function(p1, p2, increment){
11                        //      summary:
12                        //              Create a geodetic line as an array of OpenLayers.Point.
13                        //      descritpion:
14                        //              Create a geodetic line as an array of OpenLayers.Point between the point p1
15                        //      and the point p2. Result is a polyline approximation for which a new point is
16                        //      calculated every <em>increment</em> degrees.
17                        //      p1: Point
18                        //              The first point of the geodetic line. x and y fields are longitude and
19                        //              latitude in decimal degrees.
20                        //      p2: Point
21                        //              The second point of the geodetic line. x and y fields are longitude and
22                        //              latitude in decimal degrees.
23                        //      increment: Float
24                        //              The value at which a new point is computed.
25                        var startLon = p1.x;
26                        var endLon = p2.x;
27                        var sl = Math.min(startLon, endLon);
28                        var el = Math.max(startLon, endLon);
29
30                        var d2r = this.DEG2RAD;
31                        var lat1 = p1.y * d2r;
32                        var lon1 = p1.x * d2r;
33                        var lat2 = p2.y * d2r;
34                        var lon2 = p2.x * d2r;
35
36                        if (Math.abs(lon1 - lon2) <= this.TOLERANCE) {
37                                var l = Math.min(lon1, lon2);
38                                lon2 = l + Math.PI;
39                        }
40
41                        if (Math.abs(lon2 - lon1) == Math.PI) {
42                                if (lat1 + lat2 == 0.0) {
43                                        lat2 += Math.PI / 180000000;
44                                }
45                        }
46
47                        var lon = sl * d2r;
48                        var elon = el * d2r;
49                        var incr = increment * d2r;
50                        var wp = [];
51                        var k = 0;
52                        var r2d = this.RAD2DEG;
53
54                        while (lon <= elon) {
55                                lat = Math.atan((Math.sin(lat1) * Math.cos(lat2) * Math.sin(lon - lon2) - Math.sin(lat2) * Math.cos(lat1)
56                                                                                                                                                                                                                                                                                                                                        * Math.sin(lon - lon1))
57                                                                                                / (Math.cos(lat1) * Math.cos(lat2) * Math.sin(lon1 - lon2)));
58                                var p = {
59                                        x : lon * r2d,
60                                        y : lat * r2d
61                                };
62                                wp[k++] = p;
63                                if (lon < elon && (lon + incr) >= elon)
64                                        lon = elon;
65                                else
66                                        lon = lon + incr;
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                        //      descritpion:
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: GeometryFeature
107                        //              The geodetic line as a GeometryFeature
108
109                        var ls = this.toLineString(p1, p2, increment);
110                        return new GeometryFeature(ls);
111                },
112
113                DEG2RAD : Math.PI / 180,
114
115                RAD2DEG : 180 / Math.PI,
116
117                TOLERANCE : 0.00001
118        };
119
120        return dojox.geo.openlayers.GreatCircle;
121});
Note: See TracBrowser for help on using the repository browser.