@file-viewer/renderer-geo 3.3.1 → 3.3.4
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/dist/geo.js +38 -18
- package/package.json +2 -2
package/dist/geo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createFileViewerTranslator, createFileViewerViewStateChange, createFileViewerViewStateChangeEmitter, createFileViewerZoomChangeEmitter, readFileViewerText, registerFileViewerViewStateProvider, registerFileViewerZoomProvider, unregisterFileViewerViewStateProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
1
|
+
import { createFileViewerTranslator, normalizeFileViewerErrorMessage, createFileViewerViewStateChange, createFileViewerViewStateChangeEmitter, createFileViewerZoomChangeEmitter, readFileViewerText, registerFileViewerViewStateProvider, registerFileViewerZoomProvider, unregisterFileViewerViewStateProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
2
2
|
import { configureMapLibreWorker } from './maplibre-worker.js';
|
|
3
3
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
4
4
|
const GEO_WIDTH = 960;
|
|
@@ -135,7 +135,7 @@ const normalizeGeoJson = (value, t) => {
|
|
|
135
135
|
features: [{ type: 'Feature', geometry: candidate, properties: {} }],
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
-
throw
|
|
138
|
+
throw t.error('geo.error.unrecognized');
|
|
139
139
|
};
|
|
140
140
|
const normalizeShapefileOutput = (value, t) => {
|
|
141
141
|
if (Array.isArray(value)) {
|
|
@@ -204,7 +204,7 @@ const parseGeo = async (buffer, type, t) => {
|
|
|
204
204
|
declaredProjection: 'EPSG:4326',
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
|
-
throw
|
|
207
|
+
throw t.error('geo.error.unsupported', { type });
|
|
208
208
|
};
|
|
209
209
|
const walkPositions = (geometry, visit) => {
|
|
210
210
|
if (!geometry) {
|
|
@@ -374,7 +374,7 @@ const createProjectionTransformer = async (projection, t) => {
|
|
|
374
374
|
};
|
|
375
375
|
}
|
|
376
376
|
catch (error) {
|
|
377
|
-
throw
|
|
377
|
+
throw t.error('geo.error.projection', { reason: normalizeError(error) });
|
|
378
378
|
}
|
|
379
379
|
};
|
|
380
380
|
const transformGeometry = (geometry, transform) => {
|
|
@@ -411,7 +411,7 @@ const validatePositionBounds = (bounds, t) => {
|
|
|
411
411
|
!Number.isFinite(bounds.maxY) ||
|
|
412
412
|
bounds.minY < -90.000001 ||
|
|
413
413
|
bounds.maxY > 90.000001) {
|
|
414
|
-
throw
|
|
414
|
+
throw t.error('geo.error.projection', { reason: 'coordinates are outside WGS84 longitude/latitude bounds' });
|
|
415
415
|
}
|
|
416
416
|
};
|
|
417
417
|
const resolveSourceProjection = (collection, declaredProjection, options) => {
|
|
@@ -565,7 +565,7 @@ const buildPanel = (parsed, type, engineLabel, basemapLabel, t) => {
|
|
|
565
565
|
const badge = document.createElement('span');
|
|
566
566
|
badge.textContent = type.toUpperCase();
|
|
567
567
|
const heading = document.createElement('h2');
|
|
568
|
-
heading
|
|
568
|
+
t.text(heading, 'geo.title');
|
|
569
569
|
const description = document.createElement('dl');
|
|
570
570
|
appendDescriptionItem(description, t('geo.featureCount'), parsed.collection.features.length);
|
|
571
571
|
appendDescriptionItem(description, t('geo.bounds'), formatBounds(parsed.bounds));
|
|
@@ -575,7 +575,7 @@ const buildPanel = (parsed, type, engineLabel, basemapLabel, t) => {
|
|
|
575
575
|
const counts = document.createElement('div');
|
|
576
576
|
counts.className = 'geo-counts';
|
|
577
577
|
const countsHeading = document.createElement('strong');
|
|
578
|
-
countsHeading
|
|
578
|
+
t.text(countsHeading, 'geo.geometryTypes');
|
|
579
579
|
counts.appendChild(countsHeading);
|
|
580
580
|
buildGeometryCounts(parsed.collection.features).forEach(([name, count]) => {
|
|
581
581
|
const row = document.createElement('p');
|
|
@@ -590,7 +590,7 @@ const buildSvgPreview = (parsed, t) => {
|
|
|
590
590
|
const svg = createSvgElement('svg');
|
|
591
591
|
svg.setAttribute('viewBox', `0 0 ${GEO_WIDTH} ${GEO_HEIGHT}`);
|
|
592
592
|
svg.setAttribute('role', 'img');
|
|
593
|
-
|
|
593
|
+
t.attr(svg, 'aria-label', 'geo.aria');
|
|
594
594
|
const rect = createSvgElement('rect');
|
|
595
595
|
rect.setAttribute('width', String(GEO_WIDTH));
|
|
596
596
|
rect.setAttribute('height', String(GEO_HEIGHT));
|
|
@@ -871,7 +871,7 @@ const waitForMapLoad = (map) => {
|
|
|
871
871
|
map.once('error', onError);
|
|
872
872
|
});
|
|
873
873
|
};
|
|
874
|
-
const createMapLibreMap = (maplibre, host, basemap) => {
|
|
874
|
+
const createMapLibreMap = (maplibre, host, basemap, t) => {
|
|
875
875
|
return new maplibre.Map({
|
|
876
876
|
container: host,
|
|
877
877
|
style: basemap.style,
|
|
@@ -880,6 +880,12 @@ const createMapLibreMap = (maplibre, host, basemap) => {
|
|
|
880
880
|
pitchWithRotate: false,
|
|
881
881
|
minZoom: MIN_MAP_ZOOM,
|
|
882
882
|
maxZoom: MAX_MAP_ZOOM,
|
|
883
|
+
locale: {
|
|
884
|
+
'NavigationControl.ZoomIn': t('toolbar.zoomIn'),
|
|
885
|
+
'NavigationControl.ZoomOut': t('toolbar.zoomOut'),
|
|
886
|
+
'AttributionControl.ToggleAttribution': t('geo.attribution'),
|
|
887
|
+
'Map.Title': t('geo.map'),
|
|
888
|
+
},
|
|
883
889
|
});
|
|
884
890
|
};
|
|
885
891
|
const mountMapLibre = async (host, root, parsed, options, basemap, t) => {
|
|
@@ -887,8 +893,22 @@ const mountMapLibre = async (host, root, parsed, options, basemap, t) => {
|
|
|
887
893
|
const maplibre = await import('maplibre-gl');
|
|
888
894
|
configureMapLibreWorker(maplibre);
|
|
889
895
|
let activeBasemap = basemap;
|
|
890
|
-
|
|
891
|
-
|
|
896
|
+
const addNavigation = (map) => {
|
|
897
|
+
map.addControl(new maplibre.NavigationControl({ showCompass: false, visualizePitch: false }), 'top-right');
|
|
898
|
+
const container = map.getContainer();
|
|
899
|
+
for (const [selector, key] of [
|
|
900
|
+
['.maplibregl-ctrl-zoom-in', 'toolbar.zoomIn'],
|
|
901
|
+
['.maplibregl-ctrl-zoom-out', 'toolbar.zoomOut'],
|
|
902
|
+
['.maplibregl-ctrl-attrib-button', 'geo.attribution'],
|
|
903
|
+
]) {
|
|
904
|
+
const button = container.querySelector(selector);
|
|
905
|
+
t.attr(button, 'title', key);
|
|
906
|
+
t.attr(button, 'aria-label', key);
|
|
907
|
+
}
|
|
908
|
+
t.attr(map.getCanvas(), 'aria-label', 'geo.map');
|
|
909
|
+
};
|
|
910
|
+
let map = createMapLibreMap(maplibre, host, activeBasemap, t);
|
|
911
|
+
addNavigation(map);
|
|
892
912
|
try {
|
|
893
913
|
await waitForMapLoad(map);
|
|
894
914
|
}
|
|
@@ -901,8 +921,8 @@ const mountMapLibre = async (host, root, parsed, options, basemap, t) => {
|
|
|
901
921
|
host.replaceChildren();
|
|
902
922
|
activeBasemap = createOfflineBasemapConfig(t);
|
|
903
923
|
updatePanelValue(root, 'basemap', activeBasemap.label);
|
|
904
|
-
map = createMapLibreMap(maplibre, host, activeBasemap);
|
|
905
|
-
map
|
|
924
|
+
map = createMapLibreMap(maplibre, host, activeBasemap, t);
|
|
925
|
+
addNavigation(map);
|
|
906
926
|
await waitForMapLoad(map);
|
|
907
927
|
}
|
|
908
928
|
const graticule = createGraticule(parsed.bounds);
|
|
@@ -1095,7 +1115,7 @@ const mountMapLibre = async (host, root, parsed, options, basemap, t) => {
|
|
|
1095
1115
|
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(host);
|
|
1096
1116
|
const fitButton = root.querySelector('[data-geo-action="fit"]');
|
|
1097
1117
|
fitButton === null || fitButton === void 0 ? void 0 : fitButton.addEventListener('click', fit);
|
|
1098
|
-
fitButton
|
|
1118
|
+
t.attr(fitButton, 'title', 'geo.action.fit');
|
|
1099
1119
|
return {
|
|
1100
1120
|
map,
|
|
1101
1121
|
cleanup() {
|
|
@@ -1113,7 +1133,7 @@ const buildMapShell = (parsed, type, engineLabel, basemapLabel, t) => {
|
|
|
1113
1133
|
const root = createElement('div', 'geo-viewer');
|
|
1114
1134
|
const stage = createElement('main', 'geo-stage');
|
|
1115
1135
|
const toolbar = createElement('div', 'geo-toolbar');
|
|
1116
|
-
const fitButton = createElement('button', undefined,
|
|
1136
|
+
const fitButton = t.text(createElement('button', undefined), 'geo.action.fit');
|
|
1117
1137
|
fitButton.dataset.geoAction = 'fit';
|
|
1118
1138
|
const frame = createElement('div', 'geo-map-frame');
|
|
1119
1139
|
const mapHost = createElement('div', 'geo-map-engine');
|
|
@@ -1140,12 +1160,12 @@ const renderSvgView = (parsed, type, t) => {
|
|
|
1140
1160
|
export default async function renderGeo(buffer, target, type, context) {
|
|
1141
1161
|
var _a;
|
|
1142
1162
|
const normalizedType = normalizeGeoType(type);
|
|
1143
|
-
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
1163
|
+
const t = createFileViewerTranslator((context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options));
|
|
1144
1164
|
const options = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.geo;
|
|
1145
1165
|
const style = createStyle();
|
|
1146
1166
|
const state = document.createElement('div');
|
|
1147
1167
|
state.className = 'geo-state';
|
|
1148
|
-
state
|
|
1168
|
+
t.text(state, 'geo.loading');
|
|
1149
1169
|
let cleanup;
|
|
1150
1170
|
target.replaceChildren(style, state);
|
|
1151
1171
|
try {
|
|
@@ -1168,7 +1188,7 @@ export default async function renderGeo(buffer, target, type, context) {
|
|
|
1168
1188
|
catch (error) {
|
|
1169
1189
|
console.error(error);
|
|
1170
1190
|
state.classList.add('error');
|
|
1171
|
-
state.textContent = error
|
|
1191
|
+
t.bind(state, node => { node.textContent = normalizeFileViewerErrorMessage(error, context === null || context === void 0 ? void 0 : context.options); });
|
|
1172
1192
|
}
|
|
1173
1193
|
return {
|
|
1174
1194
|
$el: target,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-geo",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.4",
|
|
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.",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"README.zh-CN.md"
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@file-viewer/core": "3.3.
|
|
66
|
+
"@file-viewer/core": "3.3.4",
|
|
67
67
|
"@tmcw/togeojson": "^7.1.3",
|
|
68
68
|
"maplibre-gl": "6.16.0",
|
|
69
69
|
"proj4": "^2.22.0",
|