├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── resources └── views │ └── map.blade.php └── src ├── Extension.php ├── TencentMap.php └── TencentMapServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | phpunit.phar 3 | /vendor 4 | composer.phar 5 | composer.lock 6 | *.project 7 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 jxlwqq 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tencent Map with search for Laravel-admin 2 | 3 | 4 | 这个扩展用来帮助你在 form 表单中通过使用腾讯地图搜索地址和点击地图来获取经纬度。 5 | 6 | 7 | ## 截图 8 | 9 | 搜索地址 10 | 11 | ## 安装 12 | 13 | ```bash 14 | composer require jxlwqq/tencent-map 15 | ``` 16 | 17 | ## 配置 18 | 19 | 打开config/admin.php,按照你的情况在extensions部分加上如下的配置: 20 | 21 | ``` 22 | 'extensions' => [ 23 | 'tencent-map' => [ 24 | 'enable' => true, 25 | 'api_key' => env('TENCENT_MAP_API_KEY') 26 | ] 27 | ] 28 | ``` 29 | 30 | api_key 在 [腾讯位置服务控制台 -> key管理](https://lbs.qq.com/dev/console/key/manage) 创建。 31 | 32 | ## 使用 33 | 34 | 假设你的表中有两个字段`latitude`和`longitude`分别表示纬度和经度,那么在表单中使用如下: 35 | 36 | ```php 37 | $form->tencentMap('latitude', 'longitude', '经纬度'); 38 | 39 | // 设置地图高度 40 | $form->tencentMap('latitude', 'longitude', '经纬度')->height(500); 41 | 42 | // 设置地图缩放 43 | $form->tencentMap('latitude', 'longitude', '经纬度')->zoom(13); 44 | 45 | // 设置默认值 46 | $form->tencentMap('latitude', 'longitude', '经纬度')->default(['lat' => 90, 'lng' => 90]); 47 | ``` 48 | 49 | ## License 50 | 51 | Licensed under [The MIT License (MIT)](LICENSE). 52 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jxlwqq/tencent-map", 3 | "description": "Tencent Map with search for Laravel-admin", 4 | "type": "library", 5 | "keywords": ["laravel-admin", "extension"], 6 | "homepage": "https://github.com/jxlwqq/tencent-map", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "jxlwqq", 11 | "email": "jxlwqq@gmail.com" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=7.0.0", 16 | "encore/laravel-admin": "~1.6" 17 | }, 18 | "require-dev": { 19 | "phpunit/phpunit": "~6.0" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "Jxlwqq\\TencentMap\\": "src/" 24 | } 25 | }, 26 | "extra": { 27 | "laravel": { 28 | "providers": [ 29 | "Jxlwqq\\TencentMap\\TencentMapServiceProvider" 30 | ] 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /resources/views/map.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 |
6 | 7 | @include('admin::form.error') 8 | 9 |
10 | 11 |
12 | 13 |
14 |
15 | 16 |
17 |
18 | 20 |
21 |
22 | 24 |
25 |
26 |
27 | 28 |
29 |
30 |
31 | 32 | @include('admin::form.help-block') 33 | 34 |
35 |
36 | -------------------------------------------------------------------------------- /src/Extension.php: -------------------------------------------------------------------------------- 1 | sprintf('//map.qq.com/api/js?v=2.exp&key=%s', config('admin.extensions.tencent-map.api_key'))]; 42 | } 43 | 44 | /** 45 | * TencentMap constructor. 46 | * 47 | * @param string $column 48 | * @param array $arguments 49 | */ 50 | public function __construct($column, $arguments) 51 | { 52 | $this->column['lat'] = (string)$column; 53 | $this->column['lng'] = (string)$arguments[0]; 54 | 55 | array_shift($arguments); 56 | 57 | $this->label = $this->formatLabel($arguments); 58 | $this->id = $this->formatId($this->column); 59 | } 60 | 61 | /** 62 | * Set map height. 63 | * 64 | * @param int $height 65 | * @return $this 66 | */ 67 | public function height($height = 300) 68 | { 69 | $this->height = $height; 70 | 71 | return $this; 72 | } 73 | 74 | public function zoom($zoom = 13) 75 | { 76 | $this->zoom = $zoom; 77 | 78 | return $this; 79 | } 80 | 81 | /** 82 | * {@inheritdoc} 83 | * 84 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string 85 | */ 86 | public function render() 87 | { 88 | $this->script = $this->applyScript($this->id, $this->zoom); 89 | 90 | return parent::render()->with(['height' => $this->height]); 91 | 92 | 93 | } 94 | 95 | public function applyScript(array $id, int $zoom) 96 | { 97 | return <<loadViewsFrom($extension->views(), 'laravel-admin-tencent-map'); 21 | 22 | Admin::booting(function () { 23 | Form::extend('tencentMap', TencentMap::class); 24 | }); 25 | } 26 | } 27 | --------------------------------------------------------------------------------