Skip to content

armgit / mapcn

Public Imported from GitHub
0

Beautiful map components. 100% Free, Zero config, one command setup.

TypeScript

docs(installation): document the maplibre web worker

Anmolaeb5cda424c1
diff --git a/src/app/(main)/docs/_components/code-block.tsx b/src/app/(main)/docs/_components/code-block.tsx
index 6a2d5e8..5bb9e33 100644
--- a/src/app/(main)/docs/_components/code-block.tsx
+++ b/src/app/(main)/docs/_components/code-block.tsx
@@ -1,3 +1,4 @@
+import { cn } from "@/lib/utils";
import { highlightCode } from "@/lib/highlight";
import { CodeSurface } from "@/components/code-surface";
import { CodeCopyButton } from "@/components/code-copy-button";
@@ -5,24 +6,43 @@ import { CodeCopyButton } from "@/components/code-copy-button";
interface CodeBlockProps {
code: string;
language?: string;
+ filename?: string;
showCopyButton?: boolean;
+ showLineNumbers?: boolean;
}
export async function CodeBlock({
code,
language = "tsx",
+ filename,
showCopyButton = true,
+ showLineNumbers = true,
}: CodeBlockProps) {
const highlighted = await highlightCode(code, language);
return (
<div className="relative w-full overflow-hidden rounded-lg">
- {showCopyButton && (
- <div className="absolute top-2 right-2 z-10">
- <CodeCopyButton text={code} />
+ {filename ? (
+ <div className="bg-code border-border/60 flex items-center justify-between gap-3 border-b py-1 pr-1.5 pl-4">
+ <span className="text-muted-foreground truncate font-mono text-xs">
+ {filename}
+ </span>
+ {showCopyButton && <CodeCopyButton text={code} />}
</div>
+ ) : (
+ showCopyButton && (
+ <div className="absolute top-2 right-2 z-10">
+ <CodeCopyButton text={code} />
+ </div>
+ )
)}
- <CodeSurface className="overflow-auto" html={highlighted} />
+ <CodeSurface
+ className={cn(
+ "overflow-auto",
+ !showLineNumbers && "no-line-numbers pl-4",
+ )}
+ html={highlighted}
+ />
</div>
);
}
diff --git a/src/app/(main)/docs/installation/page.tsx b/src/app/(main)/docs/installation/page.tsx
index e435770..c2a1405 100644
--- a/src/app/(main)/docs/installation/page.tsx
+++ b/src/app/(main)/docs/installation/page.tsx
@@ -11,6 +11,15 @@ import { Metadata } from "next";
import { Card } from "@/components/ui/card";
import { Map, MapControls } from "@/registry/map";
+const cspCode = `script-src 'self' https://unpkg.com;
+worker-src 'self' blob:;`;
+
+const selfHostWorkerCode = `cp node_modules/maplibre-gl/dist/maplibre-gl-worker.mjs \\
+ node_modules/maplibre-gl/dist/maplibre-gl-shared.mjs \\
+ public/`;
+
+const workerUrlCode = `MapLibreGL.setWorkerUrl("/maplibre-gl-worker.mjs");`;
+
const usageCode = `import { Map, MapControls } from "@/components/ui/map";
import { Card } from "@/components/ui/card";
@@ -39,6 +48,7 @@ export default function InstallationPage() {
{ title: "Prerequisites", slug: "prerequisites" },
{ title: "Installation", slug: "installation" },
{ title: "Usage", slug: "usage" },
+ { title: "Web Worker", slug: "web-worker" },
]}
>
<DocsSection title="Prerequisites">
@@ -72,12 +82,36 @@ export default function InstallationPage() {
<MapControls />
</Map>
</Card>
+ <DocsNote>
+ <strong>Note:</strong> The map uses free CARTO basemap tiles by
+ default. Tiles automatically switch between light and dark themes.
+ </DocsNote>
</DocsSection>
- <DocsNote>
- <strong>Note:</strong> The map uses free CARTO basemap tiles by default.
- Tiles automatically switch between light and dark themes.
- </DocsNote>
+ <DocsSection title="Web Worker">
+ <p>
+ MapLibre parses tiles in a Web Worker, which ships as a separate file,
+ so mapcn loads it from unpkg, pinned to your installed version. No
+ setup needed - under a strict CSP, the worker needs:
+ </p>
+ <CodeBlock code={cspCode} language="bash" showLineNumbers={false} />
+ <p>Your basemap host needs its own entries alongside these.</p>
+ <p>
+ To self-host it instead, copy both files into{" "}
+ <DocsCode>public/</DocsCode> - they must sit side by side:
+ </p>
+ <CodeBlock
+ code={selfHostWorkerCode}
+ language="bash"
+ showLineNumbers={false}
+ />
+ <p>Then replace the unpkg URL near the top of the component:</p>
+ <CodeBlock
+ code={workerUrlCode}
+ filename="components/ui/map.tsx"
+ showLineNumbers={false}
+ />
+ </DocsSection>
</DocsLayout>
);
}
diff --git a/src/styles/globals.css b/src/styles/globals.css
index 04f9782..30ea0dc 100644
--- a/src/styles/globals.css
+++ b/src/styles/globals.css
@@ -233,3 +233,7 @@ code .line::before {
position: sticky;
left: 0;
}
+
+.no-line-numbers code .line::before {
+ display: none;
+}