|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Maps; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use Illuminate\Validation\ValidationException; |
|
8
|
|
|
use Illuminate\Support\Facades\Input; |
|
9
|
|
|
|
|
10
|
|
|
class AreaController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Get Area is in charge of returning the buildings |
|
14
|
|
|
* on the map within a specific view envelope. |
|
15
|
|
|
* |
|
16
|
|
|
* It requires the following passed in the post request. |
|
17
|
|
|
* |
|
18
|
|
|
* Location X, Location Co-ordinate (x_location) |
|
19
|
|
|
* Location Y, Location Co-ordinate (y_location) |
|
20
|
|
|
* Tile X, Tile width |
|
21
|
|
|
* Tile Y, Tile Height |
|
22
|
|
|
* Envelope W, View envelope width |
|
23
|
|
|
* Envelope H, View envelope height |
|
24
|
|
|
* |
|
25
|
|
|
* @param Request $request |
|
26
|
|
|
* @throws ValidationException |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getArea(Request $request) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->validate($request, [ |
|
31
|
|
|
'map_id' => 'required|integer|exists:maps,id', |
|
32
|
|
|
'location_x' => 'required|integer', |
|
33
|
|
|
'location_y' => 'required|integer', |
|
34
|
|
|
'tile_x' => 'required|integer', |
|
35
|
|
|
'tile_y' => 'required|integer', |
|
36
|
|
|
'envelope_w' => 'required|integer', |
|
37
|
|
|
'envelope_h' => 'required|integer', |
|
38
|
|
|
]); |
|
39
|
|
|
|
|
40
|
|
|
// Lets handle the calculation in two parts one for x and one for y |
|
41
|
|
|
|
|
42
|
|
|
//x |
|
43
|
|
|
$startX = Input::get('location_x'); |
|
44
|
|
|
$tileX = Input::get('tile_x'); |
|
45
|
|
|
$envelopeW = Input::get('envelope_w'); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
// If our starting x is not divisible by our tile x we need to fix |
|
48
|
|
|
if ($startX % $tileX != 0) { |
|
49
|
|
|
//We fix by rounding down |
|
50
|
|
|
$offset = $startX % $tileX; |
|
51
|
|
|
//$offset now contains the difference |
|
52
|
|
|
$startX -= $offset; |
|
53
|
|
|
// now we should be starting at a valid tile starting block |
|
54
|
|
|
|
|
55
|
|
|
dd($startX); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
private function getLocationStartPoints($startX, $endX, $tileX) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
for ($number = $startX; $number <= $endX; $tileX++) { |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|