Guest User

Untitled

a guest
Mar 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <template>
  2. <div class="google-map" :id="mapName"></div>
  3. </template>
  4.  
  5. <script>
  6. export default {
  7. name: 'google-map',
  8. props: ['name'],
  9. data: function () {
  10. return {
  11. mapName: this.name + "-map",
  12. markerCoordinates: [{
  13. latitude: 41.3850639,
  14. longitude: 2.1734035
  15. }, {
  16. latitude: 41.4023337,
  17. longitude: 2.2015487
  18. }, {
  19. latitude: 41.3947209,
  20. longitude: 2.1761431
  21. }],
  22. map: null,
  23. bounds: null,
  24. markers: [],
  25. label: {text:'A', color: "white"}
  26. }
  27. },
  28. mounted: function () {
  29. this.bounds = new google.maps.LatLngBounds();
  30. const element = document.getElementById(this.mapName)
  31. const mapCentre = this.markerCoordinates[0]
  32. const options = {
  33. center: new google.maps.LatLng(mapCentre.latitude, mapCentre.longitude)
  34. }
  35. this.map = new google.maps.Map(element, options);
  36. this.markerCoordinates.forEach((coord) => {
  37. const position = new google.maps.LatLng(coord.latitude, coord.longitude);
  38. const marker = new google.maps.Marker({
  39. position,
  40. map: this.map,
  41. label: this.label
  42. });
  43. this.markers.push(marker)
  44. this.map.fitBounds(this.bounds.extend(position))
  45. });
  46. }
  47. }
  48. </script>
  49.  
  50. <style scoped>
  51. .google-map {
  52. width: auto;
  53. height: 450px;
  54. margin: 0 auto;
  55. background: gray;
  56. border-radius: 4px;
  57. }
  58. </style>
  59.  
  60. google.maps.event.addListener(name, 'mouseover', function() {
  61. //FUNCION
  62. });
  63.  
  64. <template>
  65. ...
  66. <google-map></google-map>
  67. ...
  68. </template>
  69. <script>
  70. import GoogleMap from './GoogleMap';
  71.  
  72. export default{
  73. name: 'ListDetail',
  74. components: {
  75. GoogleMap,
  76. }
  77. </script>
Add Comment
Please, Sign In to add comment