Changed web samples' name and updated snapshots
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / ModelloNavigation / project / js / v3_epoly.js
1 /*global google*/
2
3 // The first support methods that don't (yet) exist in v3
4 google.maps.LatLng.prototype.distanceFrom = function (newLatLng) {
5         "use strict";
6         var EarthRadiusMeters = 6378137.0; // meters
7         var lat1 = this.lat();
8         var lon1 = this.lng();
9         var lat2 = newLatLng.lat();
10         var lon2 = newLatLng.lng();
11         var dLat = (lat2 - lat1) * Math.PI / 180;
12         var dLon = (lon2 - lon1) * Math.PI / 180;
13         var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
14         var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
15         var d = EarthRadiusMeters * c;
16         return d;
17 };
18
19 google.maps.LatLng.prototype.latRadians = function () {
20         "use strict";
21         return this.lat() * Math.PI / 180;
22 };
23
24 google.maps.LatLng.prototype.lngRadians = function () {
25         "use strict";
26         return this.lng() * Math.PI / 180;
27 };
28
29 /**
30  * Returns the length of a path in metres.
31  * @method Distance
32  */
33 google.maps.Polygon.prototype.Distance = function () {
34         "use strict";
35         var dist = 0, i = 0;
36         for (i = 1; i < this.getPath().getLength(); i++) {
37                 dist += this.getPath().getAt(i).distanceFrom(this.getPath().getAt(i - 1));
38         }
39         return dist;
40 };
41
42 /**
43  * Returns GLatLng of the point at the given distance along the path. Returns null if the path is shorter than the specified distance.
44  * @method GetPointAtDistance
45  * @param metres {Integer} distance in metres
46  */
47 google.maps.Polygon.prototype.GetPointAtDistance = function (metres) {
48         "use strict";
49         // some awkward special cases
50         if (metres === 0) {
51                 return this.getPath().getAt(0);
52         }
53         if (metres < 0) {
54                 return null;
55         }
56         if (this.getPath().getLength() < 2) {
57                 return null;
58         }
59
60         var dist = 0, olddist = 0, i = 0;
61
62         for (i = 1; (i < this.getPath().getLength() && dist < metres); i++) {
63                 olddist = dist;
64                 dist += this.getPath().getAt(i).distanceFrom(this.getPath().getAt(i - 1));
65         }
66         if (dist < metres) {
67                 return null;
68         }
69         var p1 = this.getPath().getAt(i - 2);
70         var p2 = this.getPath().getAt(i - 1);
71         var m = (metres - olddist) / (dist - olddist);
72         return new google.maps.LatLng(p1.lat() + (p2.lat() - p1.lat()) * m, p1.lng() + (p2.lng() - p1.lng()) * m);
73 };
74
75 /**
76  * Returns the Vertex number at the given distance along the path. Returns null if the path is shorter than the specified distance.
77  * @method GetIndexAtDistance
78  * @param metres {Integer} distance in metres
79  */
80 google.maps.Polygon.prototype.GetIndexAtDistance = function (metres) {
81         "use strict";
82         // some awkward special cases
83         if (metres === 0) {
84                 return this.getPath().getAt(0);
85         }
86         if (metres < 0) {
87                 return null;
88         }
89         var dist = 0, i = 0;
90         for (i = 1; (i < this.getPath().getLength() && dist < metres); i++) {
91                 dist += this.getPath().getAt(i).distanceFrom(this.getPath().getAt(i - 1));
92         }
93         if (dist < metres) {
94                 return null;
95         }
96         return i;
97 };
98
99 // Copy all the above functions to GPolyline
100 google.maps.Polyline.prototype.Distance             = google.maps.Polygon.prototype.Distance;
101 google.maps.Polyline.prototype.GetPointAtDistance   = google.maps.Polygon.prototype.GetPointAtDistance;
102 google.maps.Polyline.prototype.GetIndexAtDistance   = google.maps.Polygon.prototype.GetIndexAtDistance;
103
104
105
106
107