MapOverlayController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace common\widgets\map;
  3. use Yii;
  4. use yii\helpers\Json;
  5. use yii\web\Controller;
  6. /**
  7. * Class MapOverlayController
  8. * @package common\widgets\map
  9. * @author jianyan74 <751393839@qq.com>
  10. */
  11. class MapOverlayController extends Controller
  12. {
  13. /**
  14. * @param $type
  15. * @param $secret_key
  16. * @param string $lng
  17. * @param string $lat
  18. * @return string
  19. */
  20. public function actionIndex($type, $longitude = '', $latitude = '', $zoom = 12, $boxId = '', $overlay = '')
  21. {
  22. $this->layout = '@backend/views/layouts/blank';
  23. $secret_key = '';
  24. // 注册js
  25. $this->registerViewJs($type, $secret_key);
  26. // 高德 code
  27. $mapAMapCode = Yii::$app->services->config->backendConfig('map_amap_code');
  28. if (!empty($overlay)) {
  29. $overlay = base64_decode($overlay);
  30. $overlay = Json::decode($overlay);
  31. }
  32. empty($overlay) && $overlay = [];
  33. return $this->render('@common/widgets/map/views/overlay/' . $type, [
  34. 'longitude' => $longitude,
  35. 'latitude' => $latitude,
  36. 'label' => '',
  37. 'zoom' => $zoom,
  38. 'boxId' => $boxId,
  39. 'mapAMapCode' => $mapAMapCode,
  40. 'overlay' => $overlay,
  41. ]);
  42. }
  43. /**
  44. * @throws \yii\base\InvalidConfigException
  45. */
  46. public function registerViewJs($type, $secret_key)
  47. {
  48. $view = $this->view;
  49. switch ($type) {
  50. case 'amap' :
  51. empty($secret_key) && $secret_key = Yii::$app->services->config->backendConfig('map_amap_key');
  52. $view->registerJsFile('https://webapi.amap.com/maps?v=1.4.11&plugin=AMap.PolyEditor,AMap.CircleEditor,AMap.ToolBar,AMap.Autocomplete,AMap.Geocoder&key=' . $secret_key);
  53. $view->registerJsFile('https://webapi.amap.com/ui/1.0/main.js?v=1.0.11');
  54. break;
  55. }
  56. $view->registerCss(<<<Css
  57. #container {
  58. position: absolute;
  59. left: 0;
  60. top: 0;
  61. right: 0;
  62. bottom: 0;
  63. }
  64. Css
  65. );
  66. }
  67. }
粤ICP备19079148号