-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.php
75 lines (60 loc) · 1.83 KB
/
Map.php
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
<?php
/**
* This file is part of the ProtezioneCivileBot package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace GP\ProtezioneCivileBot\Model;
/**
* @author Giovanni Pirrotta <giovanni.pirrotta@gmail.com>
*/
class Map
{
private $aree;
public function __construct()
{
$this->aree = [];
}
public function addArea(Area $area)
{
$this->aree[] = $area;
}
public function loadFromGeoJSONFilename($filename)
{
$json = file_get_contents($filename);
$json = json_decode($json);
foreach($json->features as $feature) {
$properties = $feature->properties;
$area = new Area();
if (property_exists($properties, 'name')) {
$area->setName($properties->name);
}
if (property_exists($properties, 'description')) {
$area->setDescription($properties->description);
}
foreach($feature->geometry->coordinates as $polygon) {
foreach($polygon as $point) {
$area->addVertex(new Vertex($point[1], $point[0]));
}
}
$this->addArea($area);
unset($area);
}
}
public function getNearestArea(Vertex $vertex)
{
$areaNearest = null;
$distanceNearest = PHP_INT_MAX;
foreach($this->aree as $areaAccoglienza) {
$areaAccoglienza->calculateVertexNearest($vertex);
$v = $areaAccoglienza->getVertexNearest();
if ($v->getDistance() < $distanceNearest) {
$distanceNearest = $v->getDistance();
$areaNearest = $areaAccoglienza;
}
}
return $areaNearest;
}
}