@caoguo/maplibre 0.0.1

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.
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+
3
+ // src/sources/tianditu.ts
4
+ var LAYER_MAP = {
5
+ vector: { base: "vec", label: "cva" },
6
+ satellite: { base: "img", label: "cia" },
7
+ terrain: { base: "ter", label: "cta" }
8
+ };
9
+ var LAYER_LABEL_EN = {
10
+ cva: "eva",
11
+ cia: "eia",
12
+ cta: "eta"
13
+ };
14
+ function tiandituTileUrls(layer, opts) {
15
+ const sub = opts.subdomains ?? [0, 1, 2, 3, 4, 5, 6, 7];
16
+ const labelLayer = opts.lang === "en" ? LAYER_LABEL_EN[layer] ?? layer : layer;
17
+ return sub.map(
18
+ (s) => `https://t${s}.tianditu.gov.cn/${labelLayer}_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=${labelLayer}&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${encodeURIComponent(opts.token)}`
19
+ );
20
+ }
21
+ function buildTiandituSources(type, opts) {
22
+ const { base, label } = LAYER_MAP[type];
23
+ const tileSize = opts.tileSize ?? 256;
24
+ const maxzoom = opts.maxzoom ?? 18;
25
+ const attr = "\xA9 \u5929\u5730\u56FE GS(2023)3295\u53F7";
26
+ return [
27
+ {
28
+ id: `tianditu-${base}`,
29
+ isLabel: false,
30
+ source: {
31
+ type: "raster",
32
+ tiles: tiandituTileUrls(base, opts),
33
+ tileSize,
34
+ maxzoom,
35
+ attribution: attr
36
+ }
37
+ },
38
+ {
39
+ id: `tianditu-${label}`,
40
+ isLabel: true,
41
+ source: {
42
+ type: "raster",
43
+ tiles: tiandituTileUrls(label, opts),
44
+ tileSize,
45
+ maxzoom,
46
+ attribution: attr
47
+ }
48
+ }
49
+ ];
50
+ }
51
+ var MissingTokenError = class extends Error {
52
+ constructor() {
53
+ super("\u5929\u5730\u56FE token \u7F3A\u5931\uFF1A\u8C03\u7528 addTiandituBaseMap \u5FC5\u987B\u4F20\u5165 tianditu: { token } \u9009\u9879\u3002");
54
+ this.name = "MissingTokenError";
55
+ }
56
+ };
57
+
58
+ // src/sources/addTianditu.ts
59
+ function tiandituStyle(type, opts) {
60
+ if (!opts.token) throw new MissingTokenError();
61
+ const sources = buildTiandituSources(type, opts);
62
+ return {
63
+ version: 8,
64
+ glyphs: "https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf",
65
+ sources: Object.fromEntries(
66
+ sources.map((s) => [s.id, s.source])
67
+ ),
68
+ layers: sources.map((s) => ({
69
+ id: s.id,
70
+ type: "raster",
71
+ source: s.id,
72
+ // 注记层置于底图之上
73
+ ...s.isLabel ? { minzoom: 0 } : {}
74
+ }))
75
+ };
76
+ }
77
+ function addTiandituBaseMap(opts) {
78
+ if (!opts.token) throw new MissingTokenError();
79
+ const type = opts.type ?? "vector";
80
+ const sources = buildTiandituSources(type, opts);
81
+ const map = opts.map;
82
+ for (const s of sources) {
83
+ if (!map.getSource(s.id)) {
84
+ map.addSource(s.id, s.source);
85
+ }
86
+ if (!map.getLayer(s.id)) {
87
+ map.addLayer({
88
+ id: s.id,
89
+ type: "raster",
90
+ source: s.id
91
+ });
92
+ }
93
+ }
94
+ }
95
+
96
+ exports.MissingTokenError = MissingTokenError;
97
+ exports.addTiandituBaseMap = addTiandituBaseMap;
98
+ exports.buildTiandituSources = buildTiandituSources;
99
+ exports.tiandituStyle = tiandituStyle;
100
+ exports.tiandituTileUrls = tiandituTileUrls;
101
+ //# sourceMappingURL=index.cjs.map
102
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/sources/tianditu.ts","../../src/sources/addTianditu.ts"],"names":[],"mappings":";;;AA4CA,IAAM,SAAA,GAAiF;AAAA,EACrF,MAAA,EAAQ,EAAE,IAAA,EAAM,KAAA,EAAO,OAAO,KAAA,EAAM;A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CAAE;AAAA,GACJ;AACF;AAGO,SAAS,mBAAmB,IAAA,EAAgC;AACjE,EAAA,IAAI,CAAC,IAAA,CAAK,KAAA,EAAO,MAAM,IAAI,iBAAA,EAAkB;AAC7C,EAAA,MAAM,IAAA,GAAO,KAAK,IAAA,IAAQ,QAAA;AAC1B,EAAA,MAAM,OAAA,GAAU,oBAAA,CAAqB,IAAA,EAAM,IAAI,CAAA;AAC/C,EAAA,MAAM,MAAM,IAAA,CAAK,GAAA;AACjB,EAAA,KAAA,MAAW,KAAK,OAAA,EAAS;AACvB,IAAA,IAAI,CAAC,GAAA,CAAI,SAAA,CAAU,CAAA,CAAE,EAAE,CAAA,EAAG;AACxB,MAAA,GAAA,CAAI,SAAA,CAAU,CAAA,CAAE,EAAA,EAAI,CAAA,CAAE,MAAe,CAAA;AAAA,IACvC;AACA,IAAA,IAAI,CAAC,GAAA,CAAI,QAAA,CAAS,CAAA,CAAE,EAAE,CAAA,EAAG;AACvB,MAAA,GAAA,CAAI,QAAA,CAAS;AAAA,QACX,IAAI,CAAA,CAAE,EAAA;AAAA,QACN,IAAA,EAAM,QAAA;AAAA,QACN,QAAQ,CAAA,CAAE;AAAA,OACF,CAAA;AAAA,IACZ;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["/**\n * 天地图(Tianditu)WMTS 底图源(F-1.2)。\n *\n * 天地图为国内权威底图,坐标系为 CGCS2000 / Web Mercator(显示尺度等价于 WGS84)。\n * token 必须由调用方在运行时注入,**绝不硬编码**;缺失时抛出明确错误。\n *\n * 文档:https://lbs.tianditu.gov.cn/server/MapService.html\n */\n\nexport type TiandituLayer =\n /** 矢量底图(含道路/注记基础) */\n | 'vec'\n /** 影像底图 */\n | 'img'\n /** 地形底图 */\n | 'ter'\n /** 矢量注记(道路/地名) */\n | 'cva'\n /** 影像注记 */\n | 'cia'\n /** 地形注记 */\n | 'cta'\n /** 矢量注记(英文) */\n | 'eva'\n /** 影像注记(英文) */\n | 'eia'\n /** 地形注记(英文) */\n | 'eta';\n\nexport type TiandituType = 'vector' | 'satellite' | 'terrain';\n\nexport interface TiandituOptions {\n /** 天地图授权 token(必填,运行时注入) */\n token: string;\n /** 语言:中文 cva/cia/cta 或英文 eva/eia/eta */\n lang?: 'zh' | 'en';\n /** 瓦片服务子域,默认 0-7 */\n subdomains?: number[];\n /** 瓦片尺寸,默认 256 */\n tileSize?: number;\n /** 最大层级,默认 18 */\n maxzoom?: number;\n}\n\nconst LAYER_MAP: Record<TiandituType, { base: TiandituLayer; label: TiandituLayer }> = {\n vector: { base: 'vec', label: 'cva' },\n satellite: { base: 'img', label: 'cia' },\n terrain: { base: 'ter', label: 'cta' },\n};\n\nconst LAYER_LABEL_EN: Partial<Record<TiandituLayer, TiandituLayer>> = {\n cva: 'eva',\n cia: 'eia',\n cta: 'eta',\n};\n\n/** 构建单张 WMTS 栅格源的 tiles URL 列表(含子域与 token) */\nexport function tiandituTileUrls(\n layer: TiandituLayer,\n opts: TiandituOptions\n): string[] {\n const sub = opts.subdomains ?? [0, 1, 2, 3, 4, 5, 6, 7];\n const labelLayer = opts.lang === 'en' ? LAYER_LABEL_EN[layer] ?? layer : layer;\n return sub.map(\n (s) =>\n `https://t${s}.tianditu.gov.cn/${labelLayer}_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=${labelLayer}&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${encodeURIComponent(opts.token)}`\n );\n}\n\nexport interface TiandituSourceSpec {\n id: string;\n source: {\n type: 'raster';\n tiles: string[];\n tileSize: number;\n maxzoom: number;\n attribution: string;\n };\n /** 是否注记层(绘制于底图之上) */\n isLabel: boolean;\n}\n\n/** 生成一组天地图源(底图 + 注记) */\nexport function buildTiandituSources(\n type: TiandituType,\n opts: TiandituOptions\n): TiandituSourceSpec[] {\n const { base, label } = LAYER_MAP[type];\n const tileSize = opts.tileSize ?? 256;\n const maxzoom = opts.maxzoom ?? 18;\n const attr = '© 天地图 GS(2023)3295号';\n return [\n {\n id: `tianditu-${base}`,\n isLabel: false,\n source: {\n type: 'raster',\n tiles: tiandituTileUrls(base, opts),\n tileSize,\n maxzoom,\n attribution: attr,\n },\n },\n {\n id: `tianditu-${label}`,\n isLabel: true,\n source: {\n type: 'raster',\n tiles: tiandituTileUrls(label, opts),\n tileSize,\n maxzoom,\n attribution: attr,\n },\n },\n ];\n}\n\nexport class MissingTokenError extends Error {\n constructor() {\n super('天地图 token 缺失:调用 addTiandituBaseMap 必须传入 tianditu: { token } 选项。');\n this.name = 'MissingTokenError';\n }\n}\n","/**\n * 把天地图底图(底图 + 注记)作为源/图层添加到 MapLibre 地图实例。\n *\n * 由于天地图为栅格底图,推荐作为「无 style 背景」的地图底层:\n * 直接通过 setStyle 注入最小 style,或先 addSource + addLayer。\n * 这里提供低侵入的「注入已有 map」方式,业务可叠加自有矢量图层。\n */\n\nimport type { Map as MlMap, StyleSpecification } from 'maplibre-gl';\nimport {\n buildTiandituSources,\n MissingTokenError,\n type TiandituOptions,\n type TiandituType,\n} from './tianditu';\n\nexport interface AddTiandituOptions extends TiandituOptions {\n type?: TiandituType;\n /** 添加到指定地图实例 */\n map: MlMap;\n /** 注入为 style 的源/图层还是 addSource(默认 addSource + addLayer) */\n asStyle?: false;\n}\n\n/** 生成可直接作为 Map style 的天地图 Style JSON(含底图+注记两层) */\nexport function tiandituStyle(\n type: TiandituType,\n opts: TiandituOptions\n): StyleSpecification {\n if (!opts.token) throw new MissingTokenError();\n const sources = buildTiandituSources(type, opts);\n return {\n version: 8,\n glyphs: 'https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf',\n sources: Object.fromEntries(\n sources.map((s) => [s.id, s.source])\n ) as StyleSpecification['sources'],\n layers: sources.map((s) => ({\n id: s.id,\n type: 'raster' as const,\n source: s.id,\n // 注记层置于底图之上\n ...(s.isLabel ? { minzoom: 0 } : {}),\n })),\n };\n}\n\n/** 向已存在的地图实例注入天地图底图(底图 + 注记) */\nexport function addTiandituBaseMap(opts: AddTiandituOptions): void {\n if (!opts.token) throw new MissingTokenError();\n const type = opts.type ?? 'vector';\n const sources = buildTiandituSources(type, opts);\n const map = opts.map;\n for (const s of sources) {\n if (!map.getSource(s.id)) {\n map.addSource(s.id, s.source as never);\n }\n if (!map.getLayer(s.id)) {\n map.addLayer({\n id: s.id,\n type: 'raster',\n source: s.id,\n } as never);\n }\n }\n}\n"]}
@@ -0,0 +1,83 @@
1
+ import { Map, StyleSpecification } from 'maplibre-gl';
2
+
3
+ /**
4
+ * 天地图(Tianditu)WMTS 底图源(F-1.2)。
5
+ *
6
+ * 天地图为国内权威底图,坐标系为 CGCS2000 / Web Mercator(显示尺度等价于 WGS84)。
7
+ * token 必须由调用方在运行时注入,**绝不硬编码**;缺失时抛出明确错误。
8
+ *
9
+ * 文档:https://lbs.tianditu.gov.cn/server/MapService.html
10
+ */
11
+ type TiandituLayer =
12
+ /** 矢量底图(含道路/注记基础) */
13
+ 'vec'
14
+ /** 影像底图 */
15
+ | 'img'
16
+ /** 地形底图 */
17
+ | 'ter'
18
+ /** 矢量注记(道路/地名) */
19
+ | 'cva'
20
+ /** 影像注记 */
21
+ | 'cia'
22
+ /** 地形注记 */
23
+ | 'cta'
24
+ /** 矢量注记(英文) */
25
+ | 'eva'
26
+ /** 影像注记(英文) */
27
+ | 'eia'
28
+ /** 地形注记(英文) */
29
+ | 'eta';
30
+ type TiandituType = 'vector' | 'satellite' | 'terrain';
31
+ interface TiandituOptions {
32
+ /** 天地图授权 token(必填,运行时注入) */
33
+ token: string;
34
+ /** 语言:中文 cva/cia/cta 或英文 eva/eia/eta */
35
+ lang?: 'zh' | 'en';
36
+ /** 瓦片服务子域,默认 0-7 */
37
+ subdomains?: number[];
38
+ /** 瓦片尺寸,默认 256 */
39
+ tileSize?: number;
40
+ /** 最大层级,默认 18 */
41
+ maxzoom?: number;
42
+ }
43
+ /** 构建单张 WMTS 栅格源的 tiles URL 列表(含子域与 token) */
44
+ declare function tiandituTileUrls(layer: TiandituLayer, opts: TiandituOptions): string[];
45
+ interface TiandituSourceSpec {
46
+ id: string;
47
+ source: {
48
+ type: 'raster';
49
+ tiles: string[];
50
+ tileSize: number;
51
+ maxzoom: number;
52
+ attribution: string;
53
+ };
54
+ /** 是否注记层(绘制于底图之上) */
55
+ isLabel: boolean;
56
+ }
57
+ /** 生成一组天地图源(底图 + 注记) */
58
+ declare function buildTiandituSources(type: TiandituType, opts: TiandituOptions): TiandituSourceSpec[];
59
+ declare class MissingTokenError extends Error {
60
+ constructor();
61
+ }
62
+
63
+ /**
64
+ * 把天地图底图(底图 + 注记)作为源/图层添加到 MapLibre 地图实例。
65
+ *
66
+ * 由于天地图为栅格底图,推荐作为「无 style 背景」的地图底层:
67
+ * 直接通过 setStyle 注入最小 style,或先 addSource + addLayer。
68
+ * 这里提供低侵入的「注入已有 map」方式,业务可叠加自有矢量图层。
69
+ */
70
+
71
+ interface AddTiandituOptions extends TiandituOptions {
72
+ type?: TiandituType;
73
+ /** 添加到指定地图实例 */
74
+ map: Map;
75
+ /** 注入为 style 的源/图层还是 addSource(默认 addSource + addLayer) */
76
+ asStyle?: false;
77
+ }
78
+ /** 生成可直接作为 Map style 的天地图 Style JSON(含底图+注记两层) */
79
+ declare function tiandituStyle(type: TiandituType, opts: TiandituOptions): StyleSpecification;
80
+ /** 向已存在的地图实例注入天地图底图(底图 + 注记) */
81
+ declare function addTiandituBaseMap(opts: AddTiandituOptions): void;
82
+
83
+ export { type AddTiandituOptions, MissingTokenError, type TiandituLayer, type TiandituOptions, type TiandituSourceSpec, type TiandituType, addTiandituBaseMap, buildTiandituSources, tiandituStyle, tiandituTileUrls };
@@ -0,0 +1,83 @@
1
+ import { Map, StyleSpecification } from 'maplibre-gl';
2
+
3
+ /**
4
+ * 天地图(Tianditu)WMTS 底图源(F-1.2)。
5
+ *
6
+ * 天地图为国内权威底图,坐标系为 CGCS2000 / Web Mercator(显示尺度等价于 WGS84)。
7
+ * token 必须由调用方在运行时注入,**绝不硬编码**;缺失时抛出明确错误。
8
+ *
9
+ * 文档:https://lbs.tianditu.gov.cn/server/MapService.html
10
+ */
11
+ type TiandituLayer =
12
+ /** 矢量底图(含道路/注记基础) */
13
+ 'vec'
14
+ /** 影像底图 */
15
+ | 'img'
16
+ /** 地形底图 */
17
+ | 'ter'
18
+ /** 矢量注记(道路/地名) */
19
+ | 'cva'
20
+ /** 影像注记 */
21
+ | 'cia'
22
+ /** 地形注记 */
23
+ | 'cta'
24
+ /** 矢量注记(英文) */
25
+ | 'eva'
26
+ /** 影像注记(英文) */
27
+ | 'eia'
28
+ /** 地形注记(英文) */
29
+ | 'eta';
30
+ type TiandituType = 'vector' | 'satellite' | 'terrain';
31
+ interface TiandituOptions {
32
+ /** 天地图授权 token(必填,运行时注入) */
33
+ token: string;
34
+ /** 语言:中文 cva/cia/cta 或英文 eva/eia/eta */
35
+ lang?: 'zh' | 'en';
36
+ /** 瓦片服务子域,默认 0-7 */
37
+ subdomains?: number[];
38
+ /** 瓦片尺寸,默认 256 */
39
+ tileSize?: number;
40
+ /** 最大层级,默认 18 */
41
+ maxzoom?: number;
42
+ }
43
+ /** 构建单张 WMTS 栅格源的 tiles URL 列表(含子域与 token) */
44
+ declare function tiandituTileUrls(layer: TiandituLayer, opts: TiandituOptions): string[];
45
+ interface TiandituSourceSpec {
46
+ id: string;
47
+ source: {
48
+ type: 'raster';
49
+ tiles: string[];
50
+ tileSize: number;
51
+ maxzoom: number;
52
+ attribution: string;
53
+ };
54
+ /** 是否注记层(绘制于底图之上) */
55
+ isLabel: boolean;
56
+ }
57
+ /** 生成一组天地图源(底图 + 注记) */
58
+ declare function buildTiandituSources(type: TiandituType, opts: TiandituOptions): TiandituSourceSpec[];
59
+ declare class MissingTokenError extends Error {
60
+ constructor();
61
+ }
62
+
63
+ /**
64
+ * 把天地图底图(底图 + 注记)作为源/图层添加到 MapLibre 地图实例。
65
+ *
66
+ * 由于天地图为栅格底图,推荐作为「无 style 背景」的地图底层:
67
+ * 直接通过 setStyle 注入最小 style,或先 addSource + addLayer。
68
+ * 这里提供低侵入的「注入已有 map」方式,业务可叠加自有矢量图层。
69
+ */
70
+
71
+ interface AddTiandituOptions extends TiandituOptions {
72
+ type?: TiandituType;
73
+ /** 添加到指定地图实例 */
74
+ map: Map;
75
+ /** 注入为 style 的源/图层还是 addSource(默认 addSource + addLayer) */
76
+ asStyle?: false;
77
+ }
78
+ /** 生成可直接作为 Map style 的天地图 Style JSON(含底图+注记两层) */
79
+ declare function tiandituStyle(type: TiandituType, opts: TiandituOptions): StyleSpecification;
80
+ /** 向已存在的地图实例注入天地图底图(底图 + 注记) */
81
+ declare function addTiandituBaseMap(opts: AddTiandituOptions): void;
82
+
83
+ export { type AddTiandituOptions, MissingTokenError, type TiandituLayer, type TiandituOptions, type TiandituSourceSpec, type TiandituType, addTiandituBaseMap, buildTiandituSources, tiandituStyle, tiandituTileUrls };
@@ -0,0 +1,3 @@
1
+ export { MissingTokenError, addTiandituBaseMap, buildTiandituSources, tiandituStyle, tiandituTileUrls } from '../chunk-EZOV5O2M.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var theme = require('@caoguo/theme');
4
+
5
+ // src/styles.ts
6
+ var WUHAN_CENTER = [114.3055, 30.5928];
7
+ var WUHAN_ZOOM = 11;
8
+ function caoguoStyle(theme$1 = "caoguo-dark") {
9
+ return theme.buildStyle(theme$1);
10
+ }
11
+ function osmRasterStyle() {
12
+ return {
13
+ version: 8,
14
+ glyphs: "https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf",
15
+ sources: {
16
+ "osm-raster": {
17
+ type: "raster",
18
+ tiles: [
19
+ "https://a.tile.openstreetmap.org/{z}/{x}/{y}.png",
20
+ "https://b.tile.openstreetmap.org/{z}/{x}/{y}.png",
21
+ "https://c.tile.openstreetmap.org/{z}/{x}/{y}.png"
22
+ ],
23
+ tileSize: 256,
24
+ attribution: "\xA9 OpenStreetMap contributors"
25
+ }
26
+ },
27
+ layers: [
28
+ {
29
+ id: "background",
30
+ type: "background",
31
+ paint: { "background-color": "#0a0f1e" }
32
+ },
33
+ {
34
+ id: "osm-raster",
35
+ type: "raster",
36
+ source: "osm-raster",
37
+ paint: {
38
+ "raster-opacity": 0.85,
39
+ "raster-saturation": -0.6,
40
+ "raster-brightness-max": 0.7,
41
+ "raster-contrast": 0.1
42
+ }
43
+ }
44
+ ]
45
+ };
46
+ }
47
+
48
+ exports.WUHAN_CENTER = WUHAN_CENTER;
49
+ exports.WUHAN_ZOOM = WUHAN_ZOOM;
50
+ exports.caoguoStyle = caoguoStyle;
51
+ exports.osmRasterStyle = osmRasterStyle;
52
+ //# sourceMappingURL=styles.cjs.map
53
+ //# sourceMappingURL=styles.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/styles.ts"],"names":["theme","buildStyle"],"mappings":";;;;;AAWO,IAAM,YAAA,GAAiC,CAAC,QAAA,EAAU,OAAO;AACzD,IAAM,UAAA,GAAa;AAGnB,SAAS,WAAA,CAAYA,UAAmB,aAAA,EAAmC;AAChF,EAAA,OAAOC,iBAAWD,OAAK,CAAA;AACzB;AAGO,SAAS,cAAA,GAAqC;AACnD,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,6DAAA;AAAA,IACR,OAAA,EAAS;AAAA,MACP,YAAA,EAAc;AAAA,QACZ,IAAA,EAAM,QAAA;AAAA,QACN,KAAA,EAAO;AAAA,UACL,kDAAA;AAAA,UACA,kDAAA;AAAA,UACA;AAAA,SACF;AAAA,QACA,QAAA,EAAU,GAAA;AAAA,QACV,WAAA,EAAa;AAAA;AACf,KACF;AAAA,IACA,MAAA,EAAQ;AAAA,MACN;AAAA,QACE,EAAA,EAAI,YAAA;AAAA,QACJ,IAAA,EAAM,YAAA;AAAA,QACN,KAAA,EAAO,EAAE,kBAAA,EAAoB,SAAA;AAAU,OACzC;AAAA,MACA;AAAA,QACE,EAAA,EAAI,YAAA;AAAA,QACJ,IAAA,EAAM,QAAA;AAAA,QACN,MAAA,EAAQ,YAAA;AAAA,QACR,KAAA,EAAO;AAAA,UACL,gBAAA,EAAkB,IAAA;AAAA,UAClB,mBAAA,EAAqB,IAAA;AAAA,UACrB,uBAAA,EAAyB,GAAA;AAAA,UACzB,iBAAA,EAAmB;AAAA;AACrB;AACF;AACF,GACF;AACF","file":"styles.cjs","sourcesContent":["/**\n * 草果地图内置样式。\n *\n * - `caoguoStyle()`:官方矢量主题(caoguo-dark / caoguo-light),\n * 由 @caoguo/theme 生成,底层使用 MapLibre 免费 demo 矢量瓦片,无需 token。\n * - `osmRasterStyle()`:OSM 栅格兜底样式,矢量主题加载失败时使用。\n */\n\nimport type { StyleSpecification } from 'maplibre-gl';\nimport { buildStyle, type ThemeName } from '@caoguo/theme';\n\nexport const WUHAN_CENTER: [number, number] = [114.3055, 30.5928];\nexport const WUHAN_ZOOM = 11;\n\n/** 草果官方矢量主题(默认暗色)。 */\nexport function caoguoStyle(theme: ThemeName = 'caoguo-dark'): StyleSpecification {\n return buildStyle(theme);\n}\n\n/** 暗色 OSM 栅格兜底底图(无需 key)。 */\nexport function osmRasterStyle(): StyleSpecification {\n return {\n version: 8,\n glyphs: 'https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf',\n sources: {\n 'osm-raster': {\n type: 'raster',\n tiles: [\n 'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',\n 'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png',\n 'https://c.tile.openstreetmap.org/{z}/{x}/{y}.png',\n ],\n tileSize: 256,\n attribution: '© OpenStreetMap contributors',\n },\n },\n layers: [\n {\n id: 'background',\n type: 'background',\n paint: { 'background-color': '#0a0f1e' },\n },\n {\n id: 'osm-raster',\n type: 'raster',\n source: 'osm-raster',\n paint: {\n 'raster-opacity': 0.85,\n 'raster-saturation': -0.6,\n 'raster-brightness-max': 0.7,\n 'raster-contrast': 0.1,\n },\n },\n ],\n };\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { StyleSpecification } from 'maplibre-gl';
2
+ import { ThemeName } from '@caoguo/theme';
3
+
4
+ /**
5
+ * 草果地图内置样式。
6
+ *
7
+ * - `caoguoStyle()`:官方矢量主题(caoguo-dark / caoguo-light),
8
+ * 由 @caoguo/theme 生成,底层使用 MapLibre 免费 demo 矢量瓦片,无需 token。
9
+ * - `osmRasterStyle()`:OSM 栅格兜底样式,矢量主题加载失败时使用。
10
+ */
11
+
12
+ declare const WUHAN_CENTER: [number, number];
13
+ declare const WUHAN_ZOOM = 11;
14
+ /** 草果官方矢量主题(默认暗色)。 */
15
+ declare function caoguoStyle(theme?: ThemeName): StyleSpecification;
16
+ /** 暗色 OSM 栅格兜底底图(无需 key)。 */
17
+ declare function osmRasterStyle(): StyleSpecification;
18
+
19
+ export { WUHAN_CENTER, WUHAN_ZOOM, caoguoStyle, osmRasterStyle };
@@ -0,0 +1,19 @@
1
+ import { StyleSpecification } from 'maplibre-gl';
2
+ import { ThemeName } from '@caoguo/theme';
3
+
4
+ /**
5
+ * 草果地图内置样式。
6
+ *
7
+ * - `caoguoStyle()`:官方矢量主题(caoguo-dark / caoguo-light),
8
+ * 由 @caoguo/theme 生成,底层使用 MapLibre 免费 demo 矢量瓦片,无需 token。
9
+ * - `osmRasterStyle()`:OSM 栅格兜底样式,矢量主题加载失败时使用。
10
+ */
11
+
12
+ declare const WUHAN_CENTER: [number, number];
13
+ declare const WUHAN_ZOOM = 11;
14
+ /** 草果官方矢量主题(默认暗色)。 */
15
+ declare function caoguoStyle(theme?: ThemeName): StyleSpecification;
16
+ /** 暗色 OSM 栅格兜底底图(无需 key)。 */
17
+ declare function osmRasterStyle(): StyleSpecification;
18
+
19
+ export { WUHAN_CENTER, WUHAN_ZOOM, caoguoStyle, osmRasterStyle };
package/dist/styles.js ADDED
@@ -0,0 +1,3 @@
1
+ export { WUHAN_CENTER, WUHAN_ZOOM, caoguoStyle, osmRasterStyle } from './chunk-DNEF4DHG.js';
2
+ //# sourceMappingURL=styles.js.map
3
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"styles.js"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@caoguo/maplibre",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "scripts": {
6
+ "build": "tsup",
7
+ "test": "vitest run",
8
+ "test:watch": "vitest"
9
+ },
10
+ "main": "./dist/index.cjs",
11
+ "module": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
18
+ },
19
+ "./styles": {
20
+ "types": "./dist/styles.d.ts",
21
+ "import": "./dist/styles.js",
22
+ "require": "./dist/styles.cjs"
23
+ },
24
+ "./sources": {
25
+ "types": "./dist/sources/index.d.ts",
26
+ "import": "./dist/sources/index.js",
27
+ "require": "./dist/sources/index.cjs"
28
+ },
29
+ "./offline": {
30
+ "types": "./dist/offline/index.d.ts",
31
+ "import": "./dist/offline/index.js",
32
+ "require": "./dist/offline/index.cjs"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "dependencies": {
39
+ "@caoguo/theme": "workspace:*",
40
+ "idb": "^8.0.0",
41
+ "maplibre-gl": "^4.7.1"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public",
45
+ "registry": "https://registry.npmjs.org/"
46
+ },
47
+ "devDependencies": {
48
+ "jsdom": "^25.0.1",
49
+ "tsup": "^8.3.5",
50
+ "vitest": "^2.1.8"
51
+ }
52
+ }