diff --git a/resources/views/latlong-yandex.blade.php b/resources/views/latlong-yandex.blade.php new file mode 100644 index 0000000..2348293 --- /dev/null +++ b/resources/views/latlong-yandex.blade.php @@ -0,0 +1,233 @@ + + +
+ + + +
+ + @include('admin::form.error') + +
+
+ +
+
+ +
+ +
+ +
+ + +
+ +
+ + + @if($provider != 'yandex') +
+
+ + + + +
+
+ @endif + +
+ +
+ +
+ + @include('admin::form.help-block') + +
+
+ + + + + + diff --git a/resources/views/latlong.blade.php b/resources/views/latlong.blade.php index d59716a..0e9b2b3 100644 --- a/resources/views/latlong.blade.php +++ b/resources/views/latlong.blade.php @@ -13,6 +13,16 @@
+ +
+ +
+ + +
+ +
+ @if($provider != 'yandex')
@@ -35,3 +45,82 @@
+ + + \ No newline at end of file diff --git a/src/Extension.php b/src/Extension.php index 483890d..1447121 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -48,20 +48,40 @@ public static function getProvider($name = '') */ public static function showField() { - return function ($lat, $lng, $height = 300, $zoom = 16) { + return function ($lat, $lng, $address, $zoom, $height = 300) { - return $this->unescape()->as(function () use ($lat, $lng, $height, $zoom) { + return $this->unescape()->as(function () use ($lat, $lng, $address, $zoom, $height) { $lat = $this->{$lat}; $lng = $this->{$lng}; - $id = ['lat' => 'lat', 'lng' => 'lng']; + $address = $this->{$address}; + $id = ['lat' => 'lat', 'lng' => 'lng', 'address' => 'address', 'zoom' => 'zoom']; Admin::script(Extension::getProvider() ->setParams([ 'zoom' => $zoom ]) ->applyScript($id)); - return << +
+ +
+
+ +
+
+ +
+ + +
+ +
+HTML; + } else { + return <<
@@ -75,6 +95,9 @@ public static function showField()
HTML; + } + + }); }; } diff --git a/src/Latlong.php b/src/Latlong.php index 447745b..680d102 100644 --- a/src/Latlong.php +++ b/src/Latlong.php @@ -53,11 +53,21 @@ public static function getAssets() * @param string $column * @param array $arguments */ - public function __construct($column, $arguments) + public function __construct($columns, $arguments) { - $this->column['lat'] = (string)$column; + $this->column['lat'] = (string)$columns; $this->column['lng'] = (string)$arguments[0]; + if (in_array('address', $arguments)) { + $this->column['address'] = 'address'; + array_shift($arguments); + } + + if (in_array('zoom', $arguments)) { + $this->column['zoom'] = 'zoom'; + array_shift($arguments); + } + array_shift($arguments); $this->label = $this->formatLabel($arguments); @@ -108,18 +118,23 @@ public function setAutoPosition($bool) { */ public function render() { - $this->script = Extension::getProvider() - ->setParams([ - 'zoom' => $this->zoom - ]) - ->setAutoPosition($this->autoPosition) - ->applyScript($this->id); +// $this->script = Extension::getProvider() +// ->setParams([ +// 'zoom' => $this->zoom +// ]) +// ->setAutoPosition($this->autoPosition) +// ->applyScript($this->id); $variables = [ 'height' => $this->height, 'provider' => Extension::config('default'), ]; + + $this->view = 'laravel-admin-latlong::latlong-yandex'; + + + $this->addVariables($variables); - return parent::render()->with($variables); + return parent::fieldRender(); } } diff --git a/src/LatlongServiceProvider.php b/src/LatlongServiceProvider.php index 2a47905..e303044 100644 --- a/src/LatlongServiceProvider.php +++ b/src/LatlongServiceProvider.php @@ -25,4 +25,4 @@ public function boot(Extension $extension) Show\Field::macro('latlong', Extension::showField()); }); } -} \ No newline at end of file +} diff --git a/src/Map/Yandex.php b/src/Map/Yandex.php index 88f0c96..711bf62 100644 --- a/src/Map/Yandex.php +++ b/src/Map/Yandex.php @@ -7,44 +7,189 @@ class Yandex extends AbstractMap /** * @var string */ - protected $api = '//api-maps.yandex.ru/2.1/?lang=ru_RU'; + protected $api = '//api-maps.yandex.ru/2.1/?apikey=%s&lang=ru_RU'; /** * {@inheritdoc} */ public function applyScript(array $id) { - return <<getParams('zoom')} - }); - - var myPlacemark = new ymaps.Placemark([lat.val(), lng.val()], { - }, { - preset: 'islands#redDotIcon', - draggable: true - }); - - myPlacemark.events.add(['dragend'], function (e) { - lat.val(myPlacemark.geometry.getCoordinates()[0]); - lng.val(myPlacemark.geometry.getCoordinates()[1]); - }); - - myMap.geoObjects.add(myPlacemark); - }); - - } - - init('{$id['lat']}{$id['lng']}'); - })(); -EOT; + if (isset($id['address'])) { + return <<