index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div class="content">
  3. <div id="container">门店地图</div>
  4. </div>
  5. </template>
  6. <script>
  7. import shop_icon from "@/assets/img/shop_icon.png";
  8. var searchService,
  9. markers = [],
  10. that;
  11. export default {
  12. data() {
  13. return {
  14. searchValue: ""
  15. };
  16. },
  17. mounted() {
  18. this.init();
  19. that = this;
  20. },
  21. methods: {
  22. async init() {
  23. //步骤:定义map变量 调用 TMap.Map() 构造函数 获取地图显示容器
  24. //设置地图中心点
  25. var myLatlng = new TMap.LatLng(31.169083, 121.432358);
  26. //定义工厂模式函数
  27. var myOptions = {
  28. zoom: 12, //设置地图缩放级别
  29. center: myLatlng //设置中心点样式
  30. // mapTypeId: TMap.MapTypeId.ROADMAP //设置地图样式详情参见MapType
  31. };
  32. //获取dom元素添加地图信息
  33. var map = new TMap.Map(document.getElementById("container"), myOptions);
  34. // new TMap.MarkerImage(shop_icon);
  35. let res = await this.getData();
  36. let geometries = [];
  37. res.forEach(v => {
  38. if (v.gdlat) {
  39. geometries.push({
  40. styleId: "circle",
  41. center: new TMap.LatLng(v.gdlat, v.gdlng),
  42. // position: new TMap.LatLng(v.lat, v.lng),
  43. radius: 3000
  44. });
  45. }
  46. });
  47. var circle = new TMap.MultiCircle({
  48. map,
  49. styles: {
  50. // 设置圆形样式
  51. circle: new TMap.CircleStyle({
  52. color: "rgba(41,91,255,0.16)",
  53. showBorder: true,
  54. borderColor: "rgba(41,91,255,1)",
  55. borderWidth: 1
  56. })
  57. },
  58. geometries
  59. });
  60. },
  61. getData() {
  62. return new Promise(resolve => {
  63. fetch("https://talk.cirray.cn/api/shops")
  64. .then(function(response) {
  65. return response.json();
  66. })
  67. .then(function(myJson) {
  68. resolve(myJson);
  69. });
  70. });
  71. }
  72. }
  73. };
  74. </script>
  75. <style scoped>
  76. .content {
  77. padding: 20px;
  78. }
  79. #container {
  80. width: 100%;
  81. height: 90vh;
  82. }
  83. .search-row {
  84. padding-bottom: 20px;
  85. }
  86. .search-row button {
  87. margin: 0 10px;
  88. }
  89. </style>