map.vue 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div id="container"></div>
  3. </template>
  4. <script>
  5. import Vue from 'vue';
  6. export default {
  7. data() {
  8. return {
  9. }
  10. },
  11. methods: {
  12. },
  13. mounted() {
  14. let height = window.innerHeight;
  15. height = height - 100;
  16. this.$el.style.height = height + "px";
  17. var map = new AMap.Map('container', {
  18. resizeEnable: true,
  19. zoom: 5
  20. });
  21. map.clearMap();
  22. var markers = [] ,
  23. infoWindow ,
  24. data=[{"fLong":'112.00003','fLati':'30.2345'},{"fLong":'115.00003','fLati':'18.2345'},{"fLong":'114.00003','fLati':'38.2345'},{"fLong":'116.00003','fLati':'38.2345'}];
  25. var marker;
  26. for(var i in data){
  27. var jfong=[ data[i].fLong , data[i].fLati ];
  28. marker = new AMap.Marker({
  29. position: jfong,
  30. zIndex: 101,
  31. map:map
  32. });
  33. marker.setMap(map);
  34. marker.orderON=data[i].orderON;
  35. marker.tranOFID=data[i].tranOFID;
  36. marker.fhadd=data[i].fhadd;
  37. marker.sAdd=data[i].sAdd;
  38. marker.status=data[i].status;
  39. marker.on('click', function(data){
  40. var MyComponent = Vue.extend({
  41. template: "<div class='window'>" +
  42. "<div class='info-top'><div>方恒假日酒店<span>价格:318</span></div><i class='el-icon-close' @click='closeInfoWindow()'></i></div>" +
  43. "<div class='info-middle'>" +
  44. "地址:北京市朝阳区阜通东大街6号院3号楼东北8.3公里<br>" +
  45. "电话:010-64733333<br>" +
  46. "经度:" + data.lnglat.lng + "<br>" +
  47. "纬度:" + data.lnglat.lat + "<br>" +
  48. "<a href='https://ditu.amap.com/detail/B000A8URXB?citycode=110105'>详细信息</a>" +
  49. "</div>" +
  50. "</div>",
  51. methods:{
  52. closeInfoWindow:function() {
  53. map.clearInfoWindow();
  54. }
  55. }
  56. });
  57. var component= new MyComponent().$mount();
  58. infoWindow.setContent(component.$el);
  59. infoWindow.open(map, data.lnglat);
  60. });
  61. }
  62. infoWindow = new AMap.InfoWindow({
  63. isCustom: true,
  64. draggable: true, //是否可拖动
  65. showShadow: true,
  66. autoMove: true,
  67. offset: new AMap.Pixel(0, -31),
  68. content:""
  69. });
  70. marker.setMap(map);
  71. }
  72. }
  73. </script>
  74. <style scoped lang="scss">
  75. #container {
  76. width: 100%;
  77. margin-top: 10px;
  78. }
  79. </style>