Newer
Older
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
/* $Id$ */
/**
* GPolyLine / GPolygon manager
*/
Drupal.gmap.map.prototype.poly = {};
/**
* Distance in pixels between 2 points.
*/
Drupal.gmap.map.prototype.poly.distance = function(point1,point2) {
return Math.sqrt(Math.pow(point2.x - point1.x,2)+Math.pow(point2.y - point1.y,2));
};
/**
* Circle -- Following projection.
*/
Drupal.gmap.map.prototype.poly.computeCircle = function(obj,center,point2) {
var numSides = 36;
var sideInc = 10; // 360 / 20 = 18 degrees
var convFactor = Math.PI/180;
var points = [];
var radius = obj.poly.distance(center,point2);
// 36 sided poly ~= circle
for (var i = 0; i <= numSides; i++) {
var rad = i*sideInc*convFactor;
var x = center.x + radius * Math.cos(rad);
var y = center.y + radius * Math.sin(rad);
//points.push(obj.map.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(x,y),obj.map.getZoom()));
points.push(new GPoint(x,y));
}
return points;
};
Drupal.gmap.map.prototype.poly.calcPolyPoints = function(center, radM, numPoints, sAngle) {
if(!numPoints) {numPoints = 32;}
if(!sAngle) {sAngle = 0;}
var d2r = Math.PI / 180.0;
var r2d = 180.0 / Math.PI;
var angleRad = sAngle * d2r;
// earth semi major axis is about 6378137 m
var latScale = radM / 6378137 * r2d;
var lngScale = latScale / Math.cos(center.latRadians());
var angInc = 2 * Math.PI / numPoints;
var points = [];
for (var i = 0; i < numPoints; i++) {
var lat = parseFloat(center.lat()) + latScale * Math.sin(angleRad);
var lng = parseFloat(center.lng()) + lngScale * Math.cos(angleRad);
points.push(new GLatLng(lat, lng));
angleRad += angInc;
}
// close the shape and return it
points.push(points[0]);
return points;
};