-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d207749
Showing
14 changed files
with
656 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
phpunit.phar | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
*.project | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Jens Segers | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
经纬度选择器 | ||
====== | ||
|
||
这个扩展用来帮助你在form表单中选择经纬度,用来替代`Laravel-admin`中内置的`Form\Field\Map`组件, 组件支持的地图包括`Google map`、`百度地图`、`高德地图`、`腾讯地图`、`Yadex map`. | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require laravel-admin-ext/latlong -vvv | ||
``` | ||
|
||
## Configuration | ||
|
||
打开config/admin.php,按照你的情况在extensions部分加上如下的配置: | ||
|
||
```php | ||
|
||
'extensions' => [ | ||
|
||
'latlong' => [ | ||
|
||
// 是否开始这个组件,默认true | ||
'enable' => true, | ||
|
||
// 选择下面指定的provider | ||
'default' => 'yandex', | ||
|
||
// 根据上面的选择,填写相应地图的api_key,api_key需要到相应的平台去自行申请 | ||
'providers' => [ | ||
|
||
'google' => [ | ||
'api_key' => '', | ||
], | ||
|
||
'baidu' => [ | ||
'api_key' => 'xck5u2lga9n1bZkiaXIHtMufWXQnVhdx', | ||
], | ||
|
||
'tencent' => [ | ||
'api_key' => 'VVYBZ-HRJCX-NOJ4Z-ZO3PU-ZZA2J-QPBBT', | ||
], | ||
|
||
'amap' => [ | ||
'api_key' => '3693fe745aea0df8852739dac08a22fb', | ||
], | ||
] | ||
] | ||
] | ||
|
||
``` | ||
|
||
## Usage | ||
|
||
假设你的表中有两个字段`latitude`和`longitude`分别表示纬度和经度,那么在表单中使用如下: | ||
```php | ||
$form->latlong('latitude', 'longitude', '经纬度选择'); | ||
|
||
// 设置地图高度 | ||
$form->latlong('latitude', 'longitude', '经纬度')->height(500); | ||
|
||
// 设置默认值 | ||
$form->latlong('latitude', 'longitude', '经纬度')->default(['lat' => 90, 'lng' => 90]); | ||
``` | ||
|
||
## Donate | ||
|
||
如果觉得这个项目帮你节约了时间,不妨支持一下;) | ||
|
||
![-1](https://cloud.githubusercontent.com/assets/1479100/23287423/45c68202-fa78-11e6-8125-3e365101a313.jpg) | ||
|
||
License | ||
------------ | ||
Licensed under [The MIT License (MIT)](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "laravel-admin-ext/latlong", | ||
"description": "Latitude & Longitude selector", | ||
"type": "library", | ||
"keywords": ["laravel-admin", "extension"], | ||
"homepage": "https://github.com/laravel-admin-ext/latlong", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "z-song", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.0.0", | ||
"encore/laravel-admin": "~1.6" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~6.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Encore\\Admin\\Latlong\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Encore\\Admin\\Latlong\\LatlongServiceProvider" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div class="{{$viewClass['form-group']}} {!! !$errors->has($errorKey) ? '' : 'has-error' !!}"> | ||
|
||
<label for="{{$id['lat']}}" class="{{$viewClass['label']}} control-label">{{$label}}</label> | ||
|
||
<div class="{{$viewClass['field']}}"> | ||
|
||
@include('admin::form.error') | ||
|
||
<div class="row"> | ||
<div class="col-md-3"> | ||
<input id="{{$id['lat']}}" name="{{$name['lat']}}" class="form-control" value="{{ old($column['lat'], $value['lat']) }}" {!! $attributes !!} /> | ||
</div> | ||
<div class="col-md-3"> | ||
<input id="{{$id['lng']}}" name="{{$name['lng']}}" class="form-control" value="{{ old($column['lng'], $value['lng']) }}" {!! $attributes !!} /> | ||
</div> | ||
</div> | ||
|
||
<br> | ||
|
||
<div id="map_{{$id['lat'].$id['lng']}}" style="width: 100%;height: {{ $height }}px"></div> | ||
|
||
@include('admin::form.help-block') | ||
|
||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Encore\Admin\Latlong; | ||
|
||
use Encore\Admin\Extension as BaseExtension; | ||
|
||
class Extension extends BaseExtension | ||
{ | ||
public $name = 'latlong'; | ||
|
||
public $views = __DIR__.'/../resources/views'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace Encore\Admin\Latlong; | ||
|
||
use Encore\Admin\Form\Field; | ||
use Encore\Admin\Latlong\Map; | ||
|
||
class Latlong extends Field | ||
{ | ||
/** | ||
* Column name. | ||
* | ||
* @var array | ||
*/ | ||
protected $column = []; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected static $providers = [ | ||
'baidu' => Map\Baidu::class, | ||
'tencent' => Map\Tencent::class, | ||
'amap' => Map\Amap::class, | ||
'google' => Map\Google::class, | ||
'yandex' => Map\Yandex::class, | ||
]; | ||
|
||
/** | ||
* @var Map\AbstractMap | ||
*/ | ||
protected static $provider; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $view = 'laravel-admin-latlong::latlong'; | ||
|
||
/** | ||
* Map height. | ||
* | ||
* @var int | ||
*/ | ||
protected $height = 300; | ||
|
||
/** | ||
* Get assets required by this field. | ||
* | ||
* @return array | ||
*/ | ||
public static function getAssets() | ||
{ | ||
return ['js' => static::getProvider()->getAssets()]; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return Map\AbstractMap | ||
*/ | ||
public static function getProvider($name = '') | ||
{ | ||
if (static::$provider) { | ||
return static::$provider; | ||
} | ||
|
||
$name = Extension::config('default', $name); | ||
$args = Extension::config("providers.$name", []); | ||
|
||
return static::$provider = new static::$providers[$name](...array_values($args)); | ||
} | ||
|
||
/** | ||
* Latlong constructor. | ||
* | ||
* @param string $column | ||
* @param array $arguments | ||
*/ | ||
public function __construct($column, $arguments) | ||
{ | ||
$this->column['lat'] = (string)$column; | ||
$this->column['lng'] = (string)$arguments[0]; | ||
|
||
array_shift($arguments); | ||
|
||
$this->label = $this->formatLabel($arguments); | ||
$this->id = $this->formatId($this->column); | ||
} | ||
|
||
/** | ||
* Set map height. | ||
* | ||
* @param int $height | ||
* @return $this | ||
*/ | ||
public function height($height = 300) | ||
{ | ||
$this->height = $height; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string | ||
*/ | ||
public function render() | ||
{ | ||
$this->script = static::getProvider()->applyScript($this->id); | ||
|
||
return parent::render()->with(['height' => $this->height]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Encore\Admin\Latlong; | ||
|
||
use Encore\Admin\Admin; | ||
use Encore\Admin\Form; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class LatlongServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function boot(Extension $extension) | ||
{ | ||
if (! Extension::boot()) { | ||
return ; | ||
} | ||
|
||
$this->loadViewsFrom($extension->views(), 'laravel-admin-latlong'); | ||
|
||
Admin::booting(function () { | ||
Form::extend('latlong', Latlong::class); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Encore\Admin\Latlong\Map; | ||
|
||
abstract class AbstractMap | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $api; | ||
|
||
/** | ||
* Tencent constructor. | ||
* @param $key | ||
*/ | ||
public function __construct($key = '') | ||
{ | ||
if ($key) { | ||
$this->api = sprintf($this->api, $key); | ||
} | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAssets() | ||
{ | ||
return [$this->api]; | ||
} | ||
|
||
/** | ||
* @param array $id | ||
* @return string | ||
*/ | ||
abstract public function applyScript(array $id); | ||
} |
Oops, something went wrong.