N
Nuxt3mo ago
Pablo

Nuxt + leaflet + leaflet-contour plugin

I just want to be able to use the leaflet library with this leaflet-contour plugin in Nuxt 3. I know there is a Leaflet Nuxt module available, but it does not support the leaflet-contour plugin. I was able to get the Leaflet Nuxt moduleu to work out of the box, but I cannot get the leaflet-contour plugin to work with it. Any suggestions for how to proceed?
Leaflet — an open-source JavaScript library for interactive maps
Leaflet is a modern, lightweight open-source JavaScript library for mobile-friendly interactive maps.
GitHub
GitHub - JamesRunnalls/leaflet-contour: A customisable Leaflet cont...
A customisable Leaflet contour plugin. Uses d3-contour under the hood. - JamesRunnalls/leaflet-contour
Nuxt Leaflet
Documentation for the Nuxt Leaflet module
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Pablo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the provided knowledge sources, there is no explicit information about integrating the leaflet-contour plugin with Leaflet in a Nuxt 3 project. However, there are relevant discussions about common issues when using Leaflet and its plugins in Nuxt 3, especially regarding asset handling and plugin compatibility. Key points from the sources: - When using Leaflet (or vue-leaflet) in Nuxt 3, you may encounter errors like "Unexpected character '�'" when importing non-JS assets (such as PNGs). This is typically resolved by adding the relevant packages to the transpile array in your nuxt.config.ts:
export default defineNuxtConfig({
transpile: ['leaflet', '@vue-leaflet/vue-leaflet'],
// ...other config
})

export default defineNuxtConfig({
transpile: ['leaflet', '@vue-leaflet/vue-leaflet'],
// ...other config
})

vue-Leaflet (Nuxt) produce error Unexpected character '�' when using PNG tiles - If a Leaflet component causes build/runtime issues, wrapping it in <client-only> can help, as Leaflet depends on browser APIs not available during SSR:
<client-only>
<LMap ...> </LMap>
</client-only>

<client-only>
<LMap ...> </LMap>
</client-only>

RollupError: Unexpected character '�' - There is no mention of the leaflet-contour plugin specifically, nor any Nuxt or Nuxt module that directly supports it. What you can try: 1. Manual Plugin Import:
Since the Nuxt Leaflet module does not support leaflet-contour, you can try importing and initializing the plugin manually in a Nuxt 3 plugin file (e.g., plugins/leaflet-contour.client.ts). Make sure to only run this client-side, as Leaflet and its plugins require the DOM. 2. Transpile if Needed:
If leaflet-contour includes non-JS assets, add it to the transpile array in your Nuxt config as shown above. 3. Client-Only Usage:
Use <client-only> for any component that uses Leaflet and leaflet-contour to avoid SSR issues. Limitations:
I'm sorry, but there is no explicit, step-by-step guide or confirmation in the knowledge sources about integrating leaflet-contour with Nuxt 3 or the Nuxt Leaflet module. The above suggestions are based on general patterns for integrating Leaflet plugins in Nuxt 3, as inferred from the provided sources. If you encounter specific errors during this process, reviewing the error messages and applying the asset handling/transpilation strategies mentioned above may help. If you need more detailed guidance, you may need to consult the official documentation for leaflet-contour or seek community support. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@264260915296337931> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?