To add the fullscreen button to my leaflet map into nuxt i have installed leaflet.fullscreen package and i have edited my plugin leaflet.js like so:
    import Vue from "vue";
    import { LMap, LTileLayer, LMarker, LPolyline } from "vue2-leaflet";
    require("leaflet-routing-machine");
    require("lrm-graphhopper");
    require("leaflet.fullscreen");
So i can use it in my main template:
    <template>
     <div>
       <section class="search__page">
         <div id="map-wrap" class="map__wrapper"></div>
       </section>
      </div>
    </template>
    <script>
      import Tmap from "@/utils/TripMap.js";
      export default {
        mounted() {
          this.initTmap();
        },
        data() {
          return {
            mainMap: null,
          },
        methods: {
          initTmap() {
            this.mainMap = new Tmap();
            this.mainMap.load();
          }
        }
      }
    </script>
My class looks like that :
    export default class Tmap {
        constructor() {
            this.map = null;
        }
        load) {
            this.map = L.map("map-wrap", {
            fullscreenControl: true,
            fullscreenControlOptions: {
                position: "topleft"
            }).setView([46.7227062, 2.5046503], 6);
            L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", {
                maxZoom: 18,
                attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, ©TRIP'
            }).addTo(this.map);
        }
        addMarkerOnClick() {
            this.map.addEventListener("click", ev => {
                L.marker(ev.latlng).addTo(this.map);
            });
        }
        getBounds() {
            return this.map.getBounds();
        }
    }
So in my main component i don't know how to import the css associated to this fullscreen plugin. I tried :
    <style>
        @import "~/node_modules/leaflet.fullscreen/Control.FullScreen.css";
    </style>
That works but it's obviously not the good way to do that. Any idea how to that properly ?
From a quick web research i would say you should be able to access the styles like this:
@import "~leaflet/dist/leaflet.css";
When you register a global style in your nuxt.config.js the app will load it just once. I assume your build is taking more time than normal due to the node_modules path.
// nuxt.config.js
css: ['~/assets/styles/global.css'],
You could also give the nuxt resource loader a try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With