MapCity.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace common\widgets\map;
  3. use Yii;
  4. use yii\helpers\Html;
  5. use yii\widgets\InputWidget;
  6. use common\helpers\StringHelper;
  7. /**
  8. * Class MapCity
  9. * @package common\widgets\map
  10. * @author jianyan74 <751393839@qq.com>
  11. */
  12. class MapCity extends InputWidget
  13. {
  14. /**
  15. * 秘钥
  16. *
  17. * @var string
  18. */
  19. public $secret_key = '';
  20. /**
  21. * 申请的安全密钥(高德)
  22. *
  23. * @var string
  24. */
  25. public $secret_code = '';
  26. /**
  27. * 类型
  28. *
  29. * 默认高德
  30. *
  31. * amap 高德
  32. * tencent 腾讯
  33. * baidu 高德
  34. *
  35. * @var string
  36. */
  37. public $type = 'amap';
  38. /**
  39. * @return string
  40. * @throws \Exception
  41. */
  42. public function run()
  43. {
  44. $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
  45. $name = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->name;
  46. // 高德 code
  47. empty($this->secret_code) && $this->secret_code = Yii::$app->services->config->backendConfig('map_amap_code');
  48. empty($this->secret_key) && $this->secret_key = Yii::$app->services->config->backendConfig('map_amap_key');
  49. return $this->render('city/' . $this->type, [
  50. 'name' => $name,
  51. 'value' => $value,
  52. 'secret_key' => $this->secret_key,
  53. 'secret_code' => $this->secret_code,
  54. 'boxId' => StringHelper::uuid('uniqid')
  55. ]);
  56. }
  57. }
粤ICP备19079148号