72 lines
1.5 KiB
PHP
72 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Form;
|
|
|
|
use Dcat\Admin\Form\Field;
|
|
use Illuminate\Support\Arr;
|
|
|
|
/**
|
|
* 高德地图地址检索
|
|
* 1. 去开放平台(https://lbs.amap.com/)申请应用, 勾选 Web端(JS API), 得到 key 和 安全密钥
|
|
* 2. 一个页面只允许出现一个高德地图
|
|
*/
|
|
class Amap extends Field
|
|
{
|
|
protected $variables = [
|
|
// 高德地图应用 key
|
|
'key' => '',
|
|
// 高德地图应用 安全密钥
|
|
'security_code' => '',
|
|
'address' => '',
|
|
'lng' => '',
|
|
'lat' => '',
|
|
];
|
|
|
|
protected $view = 'admin.form.amap';
|
|
|
|
protected function formatFieldData($data)
|
|
{
|
|
// 获取到当前字段值
|
|
// $value = parent::formatFieldData($data);
|
|
|
|
$value = Arr::only($this->variables, ['address', 'lng', 'lat']);
|
|
|
|
return $value;
|
|
}
|
|
|
|
protected function prepareInputValue($value)
|
|
{
|
|
return json_decode($value);
|
|
}
|
|
|
|
public function config($options)
|
|
{
|
|
return $this->addVariables($options);
|
|
}
|
|
|
|
public function key($key)
|
|
{
|
|
return $this->addVariables(['key' => $key]);
|
|
}
|
|
|
|
public function code($code)
|
|
{
|
|
return $this->addVariables(['security_code' => $code]);
|
|
}
|
|
|
|
public function address($address)
|
|
{
|
|
return $this->addVariables(['address' => $address]);
|
|
}
|
|
|
|
public function lng($lng)
|
|
{
|
|
return $this->addVariables(['lng' => $lng]);
|
|
}
|
|
|
|
public function lat($lat)
|
|
{
|
|
return $this->addVariables(['lat' => $lat]);
|
|
}
|
|
}
|