@file-viewer/renderer-geo 2.2.4 → 2.2.5
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.en.md +15 -1
- package/README.md +15 -1
- package/dist/geo.js +76 -1
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -88,7 +88,21 @@ const options = {
|
|
|
88
88
|
}
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
Tianditu requires a token registered for the deployment's domain. Each built-in preset combines its base and annotation layers:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const options = {
|
|
95
|
+
renderers: [geoRenderer],
|
|
96
|
+
geo: {
|
|
97
|
+
basemap: 'tianditu-vector', // or tianditu-imagery / tianditu-terrain
|
|
98
|
+
tiandituToken: import.meta.env.VITE_TIANDITU_TOKEN,
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Use `basemap: { type: 'tianditu', token, mapStyle: 'imagery', labels: false }` to omit annotations. The viewer never bundles, stores, or proxies the token; a missing token safely falls back to the offline empty basemap.
|
|
104
|
+
|
|
105
|
+
Built-in presets include `openfreemap-liberty`, `openfreemap-bright`, `openfreemap-positron`, `openfreemap-dark`, `openfreemap-fiord`, explicit opt-in `osm-raster`, and the caller-token-based `tianditu-vector`, `tianditu-imagery`, and `tianditu-terrain` presets. Use `osm-raster` only for demos or low-volume traffic; production deployments should follow the official OpenStreetMap tile policy, keep the URL replaceable, cache correctly, and show attribution. OpenFreeMap / OpenMapTiles can also be self-hosted or mirrored to an intranet or domestic CDN and connected through `styleUrl` or `tileUrl`.
|
|
92
106
|
|
|
93
107
|
## Migration Note
|
|
94
108
|
|
package/README.md
CHANGED
|
@@ -86,7 +86,21 @@ const options = {
|
|
|
86
86
|
}
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
天地图需要使用在天地图控制台为部署域名申请的 token。内置 preset 会同时加载对应的底图和中文注记图层:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const options = {
|
|
93
|
+
renderers: [geoRenderer],
|
|
94
|
+
geo: {
|
|
95
|
+
basemap: 'tianditu-vector', // 也支持 tianditu-imagery / tianditu-terrain
|
|
96
|
+
tiandituToken: import.meta.env.VITE_TIANDITU_TOKEN,
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
需要隐藏注记时可使用对象形式:`basemap: { type: 'tianditu', token, mapStyle: 'imagery', labels: false }`。组件不会内置、保存或代理 token;未提供 token 时会安全回退到离线空底图。
|
|
102
|
+
|
|
103
|
+
内置 preset 包含 `openfreemap-liberty`、`openfreemap-bright`、`openfreemap-positron`、`openfreemap-dark`、`openfreemap-fiord`、显式 opt-in 的 `osm-raster`,以及需要调用方 token 的 `tianditu-vector`、`tianditu-imagery`、`tianditu-terrain`。`osm-raster` 只建议用于 demo 或低频访问,生产环境请遵守 OpenStreetMap 官方 tile policy,配置可替换 URL、缓存和正确 attribution。中国大陆也可以把 OpenFreeMap / OpenMapTiles 栈自托管到内网或国内 CDN,再通过 `styleUrl` 或 `tileUrl` 接入。
|
|
90
104
|
|
|
91
105
|
## 迁移说明
|
|
92
106
|
|
package/dist/geo.js
CHANGED
|
@@ -10,6 +10,13 @@ const MAX_MAP_ZOOM = 22;
|
|
|
10
10
|
const OPENFREEMAP_TILE_ORIGIN = 'https://tiles.openfreemap.org';
|
|
11
11
|
const OSM_RASTER_TILE_URL = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
|
|
12
12
|
const OSM_ATTRIBUTION = '© OpenStreetMap contributors';
|
|
13
|
+
const TIANDITU_ATTRIBUTION = '天地图';
|
|
14
|
+
const TIANDITU_SUBDOMAINS = Array.from({ length: 8 }, (_, index) => `t${index}`);
|
|
15
|
+
const TIANDITU_STYLE_PRESETS = {
|
|
16
|
+
'tianditu-vector': { mapStyle: 'vector', label: 'Tianditu Vector' },
|
|
17
|
+
'tianditu-imagery': { mapStyle: 'imagery', label: 'Tianditu Imagery' },
|
|
18
|
+
'tianditu-terrain': { mapStyle: 'terrain', label: 'Tianditu Terrain' },
|
|
19
|
+
};
|
|
13
20
|
const OPENFREEMAP_STYLE_PRESETS = {
|
|
14
21
|
openfreemap: { style: 'liberty', label: 'OpenFreeMap Liberty' },
|
|
15
22
|
'openfreemap-liberty': { style: 'liberty', label: 'OpenFreeMap Liberty' },
|
|
@@ -694,6 +701,66 @@ const createRasterBasemapStyle = (tileUrls, basemap) => {
|
|
|
694
701
|
],
|
|
695
702
|
};
|
|
696
703
|
};
|
|
704
|
+
const createTiandituTileUrls = (layer, token) => (TIANDITU_SUBDOMAINS.map(subdomain => (`https://${subdomain}.tianditu.gov.cn/DataServer?T=${layer}&x={x}&y={y}&l={z}&tk=${encodeURIComponent(token)}`)));
|
|
705
|
+
const createTiandituBasemapStyle = (token, mapStyle, labels) => {
|
|
706
|
+
const layerCodes = {
|
|
707
|
+
vector: ['vec_w', 'cva_w'],
|
|
708
|
+
imagery: ['img_w', 'cia_w'],
|
|
709
|
+
terrain: ['ter_w', 'cta_w'],
|
|
710
|
+
};
|
|
711
|
+
const [baseLayer, labelLayer] = layerCodes[mapStyle];
|
|
712
|
+
const sources = {
|
|
713
|
+
'geo-tianditu-base': {
|
|
714
|
+
type: 'raster',
|
|
715
|
+
tiles: createTiandituTileUrls(baseLayer, token),
|
|
716
|
+
tileSize: 256,
|
|
717
|
+
minzoom: 0,
|
|
718
|
+
maxzoom: 18,
|
|
719
|
+
attribution: TIANDITU_ATTRIBUTION,
|
|
720
|
+
},
|
|
721
|
+
};
|
|
722
|
+
const layers = [
|
|
723
|
+
{
|
|
724
|
+
id: 'geo-background',
|
|
725
|
+
type: 'background',
|
|
726
|
+
paint: { 'background-color': '#eef2f5' },
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
id: 'geo-tianditu-base',
|
|
730
|
+
type: 'raster',
|
|
731
|
+
source: 'geo-tianditu-base',
|
|
732
|
+
},
|
|
733
|
+
];
|
|
734
|
+
if (labels) {
|
|
735
|
+
sources['geo-tianditu-labels'] = {
|
|
736
|
+
type: 'raster',
|
|
737
|
+
tiles: createTiandituTileUrls(labelLayer, token),
|
|
738
|
+
tileSize: 256,
|
|
739
|
+
minzoom: 0,
|
|
740
|
+
maxzoom: 18,
|
|
741
|
+
attribution: TIANDITU_ATTRIBUTION,
|
|
742
|
+
};
|
|
743
|
+
layers.push({
|
|
744
|
+
id: 'geo-tianditu-labels',
|
|
745
|
+
type: 'raster',
|
|
746
|
+
source: 'geo-tianditu-labels',
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
return { version: 8, sources, layers };
|
|
750
|
+
};
|
|
751
|
+
const createTiandituBasemapConfig = (token, mapStyle, labels, label, t) => {
|
|
752
|
+
const normalizedToken = token === null || token === void 0 ? void 0 : token.trim();
|
|
753
|
+
if (!normalizedToken) {
|
|
754
|
+
console.warn('[file-viewer] Tianditu basemap requires options.geo.tiandituToken or basemap.token; using the offline basemap.');
|
|
755
|
+
return createOfflineBasemapConfig(t);
|
|
756
|
+
}
|
|
757
|
+
return {
|
|
758
|
+
kind: 'raster',
|
|
759
|
+
label,
|
|
760
|
+
style: createTiandituBasemapStyle(normalizedToken, mapStyle, labels),
|
|
761
|
+
attributionControl: true,
|
|
762
|
+
};
|
|
763
|
+
};
|
|
697
764
|
const createOfflineBasemapConfig = (t) => ({
|
|
698
765
|
kind: 'offline',
|
|
699
766
|
label: t('geo.basemap.offline'),
|
|
@@ -707,7 +774,7 @@ const createRasterBasemapConfig = (tileUrls, basemap, label) => ({
|
|
|
707
774
|
attributionControl: true,
|
|
708
775
|
});
|
|
709
776
|
export const resolveFileViewerGeoBasemapConfig = (options, t) => {
|
|
710
|
-
var _a;
|
|
777
|
+
var _a, _b;
|
|
711
778
|
const basemap = options === null || options === void 0 ? void 0 : options.basemap;
|
|
712
779
|
if (basemap === false || basemap === 'none' || basemap === 'offline') {
|
|
713
780
|
return createOfflineBasemapConfig(t);
|
|
@@ -725,10 +792,18 @@ export const resolveFileViewerGeoBasemapConfig = (options, t) => {
|
|
|
725
792
|
if (basemap === 'osm-raster') {
|
|
726
793
|
return createRasterBasemapConfig([OSM_RASTER_TILE_URL], { attribution: OSM_ATTRIBUTION }, 'OpenStreetMap Raster');
|
|
727
794
|
}
|
|
795
|
+
const tiandituPreset = TIANDITU_STYLE_PRESETS[basemap];
|
|
796
|
+
if (tiandituPreset) {
|
|
797
|
+
return createTiandituBasemapConfig(options === null || options === void 0 ? void 0 : options.tiandituToken, tiandituPreset.mapStyle, true, tiandituPreset.label, t);
|
|
798
|
+
}
|
|
728
799
|
}
|
|
729
800
|
if (isRecord(basemap)) {
|
|
730
801
|
const config = basemap;
|
|
731
802
|
const label = ((_a = config.label) === null || _a === void 0 ? void 0 : _a.trim()) || t('geo.basemap.custom');
|
|
803
|
+
if (config.type === 'tianditu') {
|
|
804
|
+
const mapStyle = config.mapStyle || 'vector';
|
|
805
|
+
return createTiandituBasemapConfig(config.token || (options === null || options === void 0 ? void 0 : options.tiandituToken), mapStyle, config.labels !== false, ((_b = config.label) === null || _b === void 0 ? void 0 : _b.trim()) || `Tianditu ${mapStyle[0].toUpperCase()}${mapStyle.slice(1)}`, t);
|
|
806
|
+
}
|
|
732
807
|
if ((config.type === 'vector-style' || config.styleUrl || config.style) && (config.styleUrl || config.style)) {
|
|
733
808
|
return {
|
|
734
809
|
kind: 'vector-style',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-geo",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone geospatial renderer plugin for File Viewer with GeoJSON, KML, GPX, SHP parsing, CRS normalization, MapLibre overlay rendering, SVG fallback, and offline-friendly lazy loading.",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"LICENSE"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@file-viewer/core": "2.2.
|
|
58
|
+
"@file-viewer/core": "2.2.5",
|
|
59
59
|
"@tmcw/togeojson": "^7.1.2",
|
|
60
60
|
"maplibre-gl": "^5.24.0",
|
|
61
61
|
"proj4": "^2.20.9",
|