amap.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <style type="text/css">
  2. .info {
  3. padding: .75rem 1.25rem;
  4. margin-bottom: 1rem;
  5. border-radius: .25rem;
  6. background-color: white;
  7. width: auto;
  8. border-width: 0;
  9. position: relative;
  10. top: 0;
  11. right: 0;
  12. min-width: 0;
  13. box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
  14. }
  15. html, body, #container {
  16. height: 100%;
  17. width: 100%;
  18. }
  19. .amap-icon img {
  20. width: 25px;
  21. height: 34px;
  22. }
  23. .amap-marker-label{
  24. border: 0;
  25. background-color: transparent;
  26. }
  27. </style>
  28. <div class="row">
  29. <div id="container"></div>
  30. </div>
  31. <script type="text/javascript">
  32. $(function () {
  33. var label = "<?= $label; ?>";
  34. var as, x, y, address, map, lat, lng, geocoder;
  35. var init = function () {
  36. AMapUI.loadUI(['misc/PositionPicker', 'misc/PoiPicker'], function (PositionPicker, PoiPicker) {
  37. //加载PositionPicker,loadUI的路径参数为模块名中 'ui/' 之后的部分
  38. map = new AMap.Map('container', {
  39. zoom: parseInt('<?= $zoom ?>'),
  40. center: [<?= $lng ?>, <?= $lat ?>], //初始地图中心点
  41. });
  42. geocoder = new AMap.Geocoder({
  43. radius: 1000 //范围,默认:500
  44. });
  45. var marker = new AMap.Marker({
  46. position: map.getCenter(),
  47. icon: 'https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
  48. offset: new AMap.Pixel(-13, -30)
  49. });
  50. marker.setMap(map);
  51. // 设置label标签
  52. // label默认蓝框白底左上角显示,样式className为:amap-marker-label
  53. if (label) {
  54. marker.setLabel({
  55. offset: new AMap.Pixel(5, 5), //设置文本标注偏移量
  56. content: "<div class='info'>" + label + "</div>", //设置文本标注内容
  57. direction: 'right' //设置文本标注方位
  58. });
  59. }
  60. //加载工具条
  61. var tool = new AMap.ToolBar();
  62. map.addControl(tool);
  63. });
  64. };
  65. init();
  66. });
  67. </script>
粤ICP备19079148号