How do I make a dotted world map in Vue or Nuxt?
Draw the map in the <script setup> of a single-file component with @setkernel/dotted-map-next, and render the SVG string that getSVG() returns with v-html. The same component works in Nuxt, which renders it on the server, so the map is in the HTML of the page.
npm install @setkernel/dotted-map-next
The single-file component
v-html inserts the string as HTML. That is safe here: the library
escapes every text it writes and throws on a colour or a number it cannot
draw.
app/components/WorldMap.vue<script setup>
import { DottedMap } from '@setkernel/dotted-map-next';
const map = new DottedMap({ height: 40 });
map.addPin({ lat: 52.52, lng: 13.405 });
const svg = map.getSVG({ title: 'Berlin on a world map' });
</script>
<template>
<div v-html="svg" />
</template>
app/components/WorldMap.vue when this page was built.In Nuxt
The paths above and below are those of a Nuxt 4 app, whose code is in
app/. Nuxt renders the component on the server, and
nuxt generate writes the map into the HTML of the page.
app/app.vue<script setup>
import WorldMap from './components/WorldMap.vue';
</script>
<template>
<main>
<WorldMap />
</main>
</template>