-
Notifications
You must be signed in to change notification settings - Fork 0
/
geojson.js
87 lines (76 loc) · 1.85 KB
/
geojson.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* eslint-disable no-unused-vars */
var GeoJSON = function () {
'use strict';
var json = {
type: 'FeatureCollection',
features: []
};
this.addPoint = function (point) {
json.features.push(point.get());
};
this.addPoints = function (points) {
var nPoints = points.length,
i;
for (i = 0; i < nPoints; i += 1) {
this.addPoint(points[i]);
}
};
this.addRadius = function (Radius) {
json.features.push(Radius.get());
};
this.generate = function () {
return json;
};
};
var Point = function (latlng) {
'use strict';
this.latlng = latlng;
this.data = {icon: '',
title: ''};
this.get = function () {
var item = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: this.latlng
},
properties: this.data
};
return item;
};
};
var Radius = function (latlng, radiusKm, points) {
'use strict';
if (points === undefined) {
points = 128;
}
this.coords = {
longitude: latlng[0],
latitude: latlng[1]
};
var km = radiusKm,
ret = [],
distanceX = km / (111.320 * Math.cos(this.coords.latitude * Math.PI / 180)),
distanceY = km / 110.574,
theta,
x,
y,
i;
for (i = 0; i < points; i += 1) {
theta = ((i / points) * (2 * Math.PI));
x = distanceX * Math.cos(theta);
y = distanceY * Math.sin(theta);
ret.push([this.coords.longitude + x, this.coords.latitude + y]);
}
ret.push(ret[0]);
this.get = function () {
var item = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [ret]
}
};
return item;
};
};