Guest User

Untitled

a guest
Jan 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. <template>
  2. <section class="tip_map">
  3. <div class="tip_map-container" ref="map"></div>
  4. </section>
  5. </template>
  6.  
  7. <script lang="ts">
  8. import { Config } from '~/store';
  9. import { Vue, Prop, Watch } from 'vue-property-decorator';
  10. import Component from 'nuxt-class-component';
  11. import { Category } from '~/services/categories';
  12. import { ITipsService, Tip } from '~/services/tips';
  13. import { IMapService } from '~/services/map';
  14. import { Inject } from '~/core';
  15.  
  16. @Component
  17. export default class extends Vue {
  18. public map: any = null;
  19.  
  20. @Prop({ type: Object, required: false }) selectedTip: Tip | null;
  21. @Prop({ type: Object, required: true }) category: Category;
  22. @Inject() config: Config;
  23. @Inject() mapService: IMapService;
  24.  
  25. public async mounted(): Promise<any> {
  26. if (process.server) {
  27. return;
  28. }
  29.  
  30. this.map = await this.mapService.createMap(
  31. this.$refs.map as HTMLElement,
  32. {lat: this.selectedTip.latitude, lng: this.selectedTip.longitude}
  33. );
  34.  
  35. this.mapService.addPinsFromCategory(this.map, this.category);
  36.  
  37. if (this.$refs.map) {
  38. // this.fixMapSize();
  39. }
  40.  
  41. }
  42.  
  43. public destroyed(): void {
  44. if (this.map) {
  45. // this.map.remove();
  46. }
  47. }
  48.  
  49. private fixMapSize(): void {
  50. const $mapContainer = this.$refs.map as HTMLElement;
  51. const $mapCanvas = $mapContainer.querySelector(
  52. '.mapboxgl-canvas'
  53. ) as HTMLElement;
  54.  
  55. $mapContainer.style.height = $mapCanvas.style.height;
  56. }
  57.  
  58.  
  59. @Watch('selectedTip')
  60. watchTip() {
  61. //fly to location
  62. //create popup at location
  63. }
  64. }
  65. </script>
  66.  
  67. <style lang='scss' scoped>
  68. .tip_map {
  69. position: relative;
  70.  
  71. &-container {
  72. width:100%;
  73. height:600px;
  74. }
  75.  
  76. /deep/ .mapboxgl-marker {
  77. width: 1.5rem;
  78. height: 1.5rem;
  79. background-size: cover;
  80. cursor: pointer;
  81. border-radius: 50%;
  82. border: 1px solid gray;
  83. background-color: yellow;
  84. }
  85.  
  86. /deep/ .mapboxgl-popup {
  87. max-width: 12.5rem;
  88. }
  89.  
  90. /deep/ .mapboxgl-popup-content {
  91. text-align: center;
  92. font-family: 'Open Sans', sans-serif;
  93. }
  94. }
  95. </style>
Add Comment
Please, Sign In to add comment