AlexLavoie42 / Nuxt-Mapbox

Elegant Mapbox integration with Nuxt
81 stars 11 forks source link

MapBoxSource high CPU usage when moving the map #112

Closed KingGeorgeDev closed 1 month ago

KingGeorgeDev commented 2 months ago

If I move or zoom the map when a source is added, my CPU usage spikes to +100% and the map moves really slow. The problem only occurs on my localhost, and not in the playground. It also doesn't matter if the source contains data or not. So I'm not sure what the problem could be.

My package.json

{
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "mapbox-gl": "^3.2.0",
    "vue": "^3.4.21"
  },
  "devDependencies": {
    "nuxt": "3.10.3",
    "nuxt-mapbox": "^1.5.9"
  }
}

My app.vue

<template>
    <div>
        <MapboxMap
            map-id="map2"
            style="position: relative; width: 100%; height: 580px;"
            :options="{
                style: 'mapbox://styles/mapbox/light-v11',
                center: [4.404762261901873, 51.22847670765199],
                zoom: 7
            }"
        >
            <MapboxSource
                source-id="dots"
                :source="{
                    type: 'geojson',
                    data: 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_ports.geojson'
                }"
            />

            <MapboxLayer
                source-id="dots"
                :layer="{
                    id: 'unclustered-point',
                    type: 'circle',
                    source: 'dots',
                }"
            />
        </MapboxMap>
    </div>
</template>
AlexLavoie42 commented 2 months ago

If you have devtools enabled it will cause performance issues currently. https://github.com/AlexLavoie42/Nuxt-Mapbox/issues/92

I have a fix for this that is in the works, and will also greatly improve performance in general. It is currently available in preview under the dev tag (1.6.0-dev.2).