Added Yandex Maps
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Interfaces;
|
||||
|
||||
interface IController
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function indexAction();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?PHP
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ORM\Place;
|
||||
|
||||
class MapController extends Controller
|
||||
{
|
||||
/**
|
||||
* https://api-maps.yandex.ru/2.1/?lang=ru_RU&apikey=<ваш API-ключ>
|
||||
*/
|
||||
private string $yandex_url = "https://api-maps.yandex.ru/2.1";
|
||||
private string $yandex_key = "9ea0bde8-b886-4620-9eab-c354727b634c";
|
||||
|
||||
private array $apiParams;
|
||||
|
||||
|
||||
public function index(int $id)
|
||||
{
|
||||
$this->apiParams = array(
|
||||
"apikey" => $this->yandex_key,
|
||||
"lang" =>"ru_RU",
|
||||
);
|
||||
|
||||
$apiCall = $this->createApiCall();
|
||||
|
||||
return $this->render('yandex_map')
|
||||
->with('apiCall', $apiCall)
|
||||
->with('yandex_maps_id', $id);
|
||||
}
|
||||
|
||||
public function getPlace(int $id)
|
||||
{
|
||||
$place = Place::find($id);
|
||||
[ $x, $y ] = explode("|",$place->Gps);
|
||||
|
||||
return response()->json([
|
||||
'x' => $x, 'y' => $y
|
||||
]);
|
||||
}
|
||||
|
||||
private function createApiCall(): string
|
||||
{
|
||||
$tmp = [];
|
||||
|
||||
foreach($this->apiParams as $k => $v) {
|
||||
$tmp[] = sprintf("%s=%s", $k, $v);
|
||||
}
|
||||
|
||||
return sprintf("%s/?%s", $this->yandex_url, implode("&", $tmp));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\ORM;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Place extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
const CREATED_AT = 'DateOfCreation';
|
||||
const UPDATED_AT = 'UpdateDate';
|
||||
const DELETED_AT = 'DeleteDate';
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
protected $table = 'Place';
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Yandex Maps</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<script src="{{ $apiCall }}" type="text/javascript"></script>
|
||||
<script type="text/javascript">var map_id = {{ $yandex_maps_id }};</script>
|
||||
<script src="/js/yandex_maps.js" type="text/javascript"></script>
|
||||
<style>
|
||||
html, body, #map {
|
||||
width: 100%; height: 100%; padding: 0; margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
</body>
|
||||
</html>
|
||||
+4
-3
@@ -8,6 +8,7 @@ use App\Http\Controllers\BandController;
|
||||
use App\Http\Controllers\GigsController;
|
||||
use App\Http\Controllers\NewsController;
|
||||
use App\Http\Controllers\ContactsController;
|
||||
use App\Http\Controllers\MapController;
|
||||
|
||||
Route::get('/', [MainController::class, 'index']);
|
||||
Route::get('/rider', [RiderController::class, 'index']);
|
||||
@@ -17,7 +18,7 @@ Route::get('/gigs', [GigsController::class, 'index']);
|
||||
Route::get('/news', [NewsController::class, 'index']);
|
||||
Route::get('/contacts', [ContactsController::class, 'index']);
|
||||
|
||||
/** Yandex Maps */
|
||||
Route::get('/map/index/id/{id}', [ MapController::class, 'index' ]);
|
||||
Route::get('/api/getplace/id/{id}', [ MapController::class, 'getPlace' ]);
|
||||
|
||||
/**
|
||||
* Доделать остальные маршруты..
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user