@seamos/map-preset 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # @seamos/map-preset
2
+
3
+ A lightweight MapLibre wrapper library for SeamOS, providing
4
+ **PMTiles-based vector & terrain maps** with environment-aware presets.
5
+
6
+ This library allows you to:
7
+ - Use **PMTiles (vector + raster-dem)** seamlessly with MapLibre
8
+ - Switch automatically between **development (S3)** and **production (device local server)** environments
9
+ - Reuse **predefined map style presets** (`basic`, `terrain`, etc.)
10
+ - Initialize a MapLibre map with a single function call
11
+
12
+ ---
13
+
14
+ ## Features
15
+
16
+ - ✅ MapLibre wrapper (browser-only)
17
+ - ✅ PMTiles protocol auto-registration
18
+ - ✅ Environment-based PMTiles base URL handling
19
+ - ✅ Built-in style presets (`STYLE_PRESETS`)
20
+ - ✅ Works with Vanilla JS, Vue, React, Next.js (client-side)
21
+
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ npm install @seamos/map-preset maplibre-gl pmtiles
28
+ ```
29
+
30
+ ## Environment Concept (Important)
31
+ This library supports two environments:
32
+ | Environment | Description | When to Use |
33
+ |------------|------------------|-------------|
34
+ | `dev` | Local / Web development environment with internet access | During local development and testing |
35
+ | `prod` | Device / Tablet deployment environment (offline or local static server) | Before app build and device deployment |
36
+
37
+ ### Recommended Usage
38
+ - Use `env: "dev"` while developing locally to load PMTiles from S3.
39
+ - Switch to `env: "prod"` before building or deploying the app so the device loads PMTiles from its local static server.
40
+
41
+ ## Basic Usage
42
+
43
+ ### 1. Import MapLibre CSS (required)
44
+ ```ts
45
+ import "maplibre-gl/dist/maplibre-gl.css";
46
+ ```
47
+
48
+ ### 2. Create a map
49
+ ```Typescript
50
+ import { createSeamOSMap } from "@seamos/map-preset";
51
+
52
+ const map = createSeamOSMap({
53
+ container: document.getElementById("map")!,
54
+ preset: "basic",
55
+ env: "dev",
56
+ maplibre: {
57
+ center: [127.0, 37.5],
58
+ zoom: 12,
59
+ maxZoom: 16,
60
+ pitch: 45
61
+ }
62
+ });
63
+
64
+ map.on("load", () => {
65
+ console.log("✅ Map loaded");
66
+ });
67
+
68
+ map.on("error", (e) => {
69
+ console.error("🧨 Map error", e?.error ?? e);
70
+ });
71
+ ```
72
+
73
+ ## Framework Examples
74
+ ### Vanilla JavaScript
75
+ ```html
76
+ <div id="map" style="width:100vw; height:100vh"></div>
77
+
78
+ <script type="module">
79
+ import "maplibre-gl/dist/maplibre-gl.css";
80
+ import { createSeamOSMap } from "@seamos/map-preset";
81
+
82
+ const map = createSeamOSMap({
83
+ container: document.getElementById("map"),
84
+ preset: "basic",
85
+ env: "dev"
86
+ });
87
+ </script>
88
+ ```
89
+
90
+ ### Vue3
91
+ ```typescript
92
+ <template>
93
+ <div ref="mapEl" class="map" id="map"></div>
94
+ </template>
95
+
96
+ <script setup lang="ts">
97
+ import { createSeamOSMap } from "@seamos/map-preset";
98
+ import 'maplibre-gl/dist/maplibre-gl.css';
99
+ import { onMounted, ref } from "vue";
100
+
101
+ const mapEl = ref<HTMLDivElement | null>(null);
102
+ let map: maplibregl.Map | null = null;
103
+
104
+ onMounted(async() => {
105
+ if (!mapEl.value) return;
106
+
107
+ try {
108
+ map = createSeamOSMap({
109
+ container: mapEl.value,
110
+ preset: "basic",
111
+ env: "dev",
112
+
113
+ maplibre: { center: [127, 37.5], zoom: 12, maxZoom: 16, pitch: 45 }
114
+ });
115
+
116
+ map.on("load", () => console.log("✅ map loaded"));
117
+ map.on("error", (e) => console.error("🧨 map error", e?.error || e));
118
+ } catch (err) {
119
+ console.error("🧨 createAgmoMap failed", err);
120
+ }
121
+ })
122
+ </script>
123
+
124
+ <style scoped>
125
+ .map {
126
+ width: 100vw;
127
+ height: 100vh;
128
+ background: #111;
129
+ }
130
+ </style>
131
+ ```
132
+
133
+ ### React / Next.js (Client Component)
134
+ ```typescript
135
+ "use client";
136
+
137
+ import { useEffect, useRef } from "react";
138
+ import { createSeamOSMap } from "@seamos/map-preset";
139
+ import "maplibre-gl/dist/maplibre-gl.css";
140
+
141
+ export default function MapView() {
142
+ const ref = useRef<HTMLDivElement>(null);
143
+
144
+ useEffect(() => {
145
+ if (!ref.current) return;
146
+
147
+ const map = createSeamOSMap({
148
+ container: ref.current,
149
+ preset: "basic",
150
+ env: "dev"
151
+ });
152
+
153
+ return () => map.remove();
154
+ }, []);
155
+
156
+ return <div ref={ref} style={{ width: "100vw", height: "100vh" }} />;
157
+ }
158
+ ```
159
+
160
+ ## Notes & Best Practices
161
+ - ❗ Browser-only library
162
+ - Do not call createSeamOSMap in SSR or Node.js environments.
163
+ - ❗ Always include MapLibre CSS
164
+ - ❗ PMTiles requires HTTP Range Requests (206)
165
+ - Ensure S3 / CDN / local device server supports range requests.
166
+ - ❗ Switch env to "prod" before app/device deployment
167
+
168
+ ## License
169
+
170
+ MIT © SeamOS