forked from locationestimatr/locationestimatr.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeoMap.js
46 lines (36 loc) · 1.23 KB
/
GeoMap.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
class GeoMap {
constructor(polygon, minimumDistanceForPoints, name) {
console.log(minimumDistanceForPoints);
this.minimumDistanceForPoints = minimumDistanceForPoints;
this.maxScore = 5000;
this.name = name;
this.polygon = polygon;
}
getBounds() {
const bounds = new google.maps.LatLngBounds();
this.polygon.getPaths().forEach(path => {
path.forEach(pos => {
bounds.extend(pos);
});
});
return bounds;
}
isInMap(lat, lon) {
return google.maps.geometry.poly.containsLocation({lat: () => lat, lng: () => lon}, this.polygon);
}
scoreCalculation(distance) {
if(distance < 7.5)
return 5000;
let score = (this.minimumDistanceForPoints - distance) / (this.minimumDistanceForPoints / this.maxScore);
let scoreDifficulty = 2;
console.log("1", score);
if (score < 0)
return 0;
score = score ** scoreDifficulty / this.maxScore ** (scoreDifficulty - 1);
console.log("2", score);
score = Math.max(0, score);
score = Math.min(this.maxScore, score);
console.log("3", score);
return Math.round(score);
}
}