MapOverlay.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace common\widgets\map;
  3. use yii\helpers\Html;
  4. use yii\widgets\InputWidget;
  5. use common\helpers\StringHelper;
  6. /**
  7. * 地图范围选择(门店可配送范围)
  8. *
  9. * Class MapOverlay
  10. * @package common\widgets\map
  11. * @author jianyan74 <751393839@qq.com>
  12. */
  13. class MapOverlay extends InputWidget
  14. {
  15. /**
  16. * @var string
  17. */
  18. public $longitude = '116.456270';
  19. /**
  20. * @var string
  21. */
  22. public $latitude = '39.919990';
  23. /**
  24. * 秘钥
  25. *
  26. * @var string
  27. */
  28. public $secret_key = '';
  29. /**
  30. * 申请的安全密钥(高德)
  31. *
  32. * @var string
  33. */
  34. public $secret_code = '';
  35. /**
  36. * 类型
  37. *
  38. * 默认高德
  39. *
  40. * amap 高德
  41. * tencent 腾讯
  42. * baidu 高德
  43. *
  44. * @var string
  45. */
  46. public $type = 'amap';
  47. /**
  48. * @return string
  49. * @throws \Exception
  50. */
  51. public function run()
  52. {
  53. $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
  54. $name = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->name;
  55. try {
  56. if ($value && !is_array($value)) {
  57. $value = json_decode($value, true);
  58. empty($value) && $value = unserialize($value);
  59. }
  60. } catch (\Exception $e) {
  61. $value = [];
  62. }
  63. empty($value) && $value = [];
  64. $this->view->registerJsFile('@baseResources/plugins/jquery-base64/jquery.base64.js');
  65. return $this->render('overlay/index', [
  66. 'name' => $name,
  67. 'value' => $value,
  68. 'type' => $this->type,
  69. 'longitude' => $this->longitude,
  70. 'latitude' => $this->latitude,
  71. 'secret_key' => $this->secret_key,
  72. 'secret_code' => $this->secret_code,
  73. 'boxId' => StringHelper::uuid('uniqid')
  74. ]);
  75. }
  76. }
粤ICP备19079148号