Structures.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <LayoutContainer>
  3. <v-responsive :aspect-ratio="1" width="100%">
  4. <no-ssr>
  5. <l-map
  6. id="map"
  7. :zoom="zoom"
  8. :center="center"
  9. :bounds="bounds"
  10. :options="{scrollWheelZoom: false, zoomSnap: 0.25}"
  11. @ready="$emit('ready', $event, field)"
  12. @update="$emit('update', $event, field)"
  13. >
  14. <l-tile-layer
  15. url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"
  16. attribution="&copy; <a href='http://osm.org/copyright'>OpenStreetMap</a> contributors"
  17. />
  18. <v-marker-cluster>
  19. <l-marker
  20. v-for="structure in structures"
  21. :key="structure.id"
  22. :lat-lng="[structure.latitude, structure.longitude]">
  23. <l-popup>
  24. <b>{{ structure.name }}</b><br>
  25. {{ structure.postalCode }} {{ structure.addressCity }}<br>
  26. <a :href="structure.website" target="_blank">{{ structure.website }}</a>
  27. </l-popup>
  28. </l-marker>
  29. </v-marker-cluster>
  30. </l-map>
  31. </no-ssr>
  32. </v-responsive>
  33. <div class="advice">
  34. {{ $t("click_on_land_to_go_there") }}
  35. </div>
  36. <v-row class="map-shortcuts">
  37. <v-col v-for="shortcut in shortcuts" :key="shortcut.src" cols="2">
  38. <div @click="setMapBounds(shortcut.bounds)">
  39. <nuxt-img
  40. :src="shortcut.src"
  41. :alt="shortcut.alt"
  42. />
  43. </div>
  44. </v-col>
  45. </v-row>
  46. </LayoutContainer>
  47. </template>
  48. <script>
  49. export default {
  50. props: {
  51. structures: {
  52. type: Array,
  53. required: false,
  54. default: () => []
  55. }
  56. },
  57. data () {
  58. const defaultCenter = [46.71, 1.94]
  59. const defaultZoom = 5.75
  60. const defaultBounds = [[51.03, -5.78], [41.2, 9.70]]
  61. return {
  62. defaultCenter,
  63. defaultZoom,
  64. defaultBounds,
  65. center: defaultCenter,
  66. zoom: defaultZoom,
  67. bounds: defaultBounds,
  68. shortcuts: [
  69. { src: '/images/metropole.png', alt: 'Metropole', bounds: { x1: 51.03, y1: -5.78, x2: 41.2, y2: 9.70 } },
  70. { src: '/images/guadeloupe.png', alt: 'Guadeloupe', bounds: { x1: 16.62, y1: -62.03, x2: 15.74, y2: -60.97 } },
  71. { src: '/images/martinique.png', alt: 'Martinique', bounds: { x1: 14.95, y1: -61.43, x2: 14.28, y2: -60.60 } },
  72. { src: '/images/mayotte.png', alt: 'Mayotte', bounds: { x1: -12.51, y1: 44.86, x2: -13.19, y2: 45.45 } },
  73. { src: '/images/la_reunion.png', alt: 'La Réunion', bounds: { x1: -20.65, y1: 54.92, x2: -21.65, y2: 56.15 } },
  74. { src: '/images/guyane.png', alt: 'Guyane', bounds: { x1: 6.24, y1: -54.62, x2: 1.87, y2: -50.59 } }
  75. ]
  76. }
  77. },
  78. methods: {
  79. setMapBounds (bounds) {
  80. // const map = this.$el.querySelector('#map')
  81. // console.log(map)
  82. // map.$emit('boundsUpdated', [bounds.x1, bounds.y1, bounds.x2, bounds.y2])
  83. // this.bounds = latLngBounds([bounds.x1, bounds.y1], [bounds.x2, bounds.y2])
  84. this.bounds = [[bounds.x1, bounds.y1], [bounds.x2, bounds.y2]]
  85. }
  86. }
  87. }
  88. </script>
  89. <style scoped>
  90. #map {
  91. height: 100%;
  92. width: 100%;
  93. }
  94. .advice {
  95. margin: 1rem 0;
  96. color: #262626;
  97. font-weight: 750;
  98. text-align: center;
  99. font-size: 0.9rem;
  100. width: 100%;
  101. }
  102. .map-shortcuts .col {
  103. padding: 12px 6px;
  104. }
  105. .map-shortcuts img {
  106. border: solid 1px #000;
  107. width: 75px;
  108. height: 75px;
  109. }
  110. </style>