@file-viewer/renderer-geo 2.1.2 → 2.1.3
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.d.ts +2 -2
- package/dist/geo.js +22 -21
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/geo.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type FileViewerRenderedInstance } from '@file-viewer/core';
|
|
2
|
-
export default function renderGeo(buffer: ArrayBuffer, target: HTMLDivElement, type?: string): Promise<FileViewerRenderedInstance>;
|
|
1
|
+
import { type FileRenderContext, type FileViewerRenderedInstance } from '@file-viewer/core';
|
|
2
|
+
export default function renderGeo(buffer: ArrayBuffer, target: HTMLDivElement, type?: string, context?: FileRenderContext): Promise<FileViewerRenderedInstance>;
|
package/dist/geo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileViewerText, } from '@file-viewer/core';
|
|
1
|
+
import { createFileViewerTranslator, readFileViewerText, } from '@file-viewer/core';
|
|
2
2
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
3
3
|
const GEO_WIDTH = 960;
|
|
4
4
|
const GEO_HEIGHT = 620;
|
|
@@ -27,7 +27,7 @@ const createStyle = () => {
|
|
|
27
27
|
const createSvgElement = (tag) => {
|
|
28
28
|
return document.createElementNS(SVG_NS, tag);
|
|
29
29
|
};
|
|
30
|
-
const normalizeGeoJson = (value) => {
|
|
30
|
+
const normalizeGeoJson = (value, t) => {
|
|
31
31
|
const candidate = value;
|
|
32
32
|
if ((candidate === null || candidate === void 0 ? void 0 : candidate.type) === 'FeatureCollection' && Array.isArray(candidate.features)) {
|
|
33
33
|
return candidate;
|
|
@@ -41,13 +41,13 @@ const normalizeGeoJson = (value) => {
|
|
|
41
41
|
features: [{ type: 'Feature', geometry: candidate, properties: {} }],
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
-
throw new Error('
|
|
44
|
+
throw new Error(t('geo.error.unrecognized'));
|
|
45
45
|
};
|
|
46
|
-
const parseXml = (text) => {
|
|
46
|
+
const parseXml = (text, t) => {
|
|
47
47
|
const doc = new DOMParser().parseFromString(text, 'application/xml');
|
|
48
48
|
const error = doc.querySelector('parsererror');
|
|
49
49
|
if (error) {
|
|
50
|
-
throw new Error(error.textContent || '
|
|
50
|
+
throw new Error(error.textContent || t('geo.error.xmlParseFailed'));
|
|
51
51
|
}
|
|
52
52
|
return doc;
|
|
53
53
|
};
|
|
@@ -61,20 +61,20 @@ const normalizeGeoType = (type) => {
|
|
|
61
61
|
}
|
|
62
62
|
return normalized;
|
|
63
63
|
};
|
|
64
|
-
const parseGeo = async (buffer, type) => {
|
|
64
|
+
const parseGeo = async (buffer, type, t) => {
|
|
65
65
|
if (type === 'geojson') {
|
|
66
|
-
return normalizeGeoJson(JSON.parse(await readFileViewerText(buffer)));
|
|
66
|
+
return normalizeGeoJson(JSON.parse(await readFileViewerText(buffer)), t);
|
|
67
67
|
}
|
|
68
68
|
if (type === 'kml' || type === 'gpx') {
|
|
69
69
|
const toGeoJSON = await import('@tmcw/togeojson');
|
|
70
|
-
const doc = parseXml(await readFileViewerText(buffer));
|
|
71
|
-
return normalizeGeoJson(type === 'kml' ? toGeoJSON.kml(doc) : toGeoJSON.gpx(doc));
|
|
70
|
+
const doc = parseXml(await readFileViewerText(buffer), t);
|
|
71
|
+
return normalizeGeoJson(type === 'kml' ? toGeoJSON.kml(doc) : toGeoJSON.gpx(doc), t);
|
|
72
72
|
}
|
|
73
73
|
if (type === 'shp') {
|
|
74
74
|
const { default: shp } = await import('shpjs');
|
|
75
|
-
return normalizeGeoJson(await shp(buffer));
|
|
75
|
+
return normalizeGeoJson(await shp(buffer), t);
|
|
76
76
|
}
|
|
77
|
-
throw new Error(
|
|
77
|
+
throw new Error(t('geo.error.unsupported', { type }));
|
|
78
78
|
};
|
|
79
79
|
const walkPositions = (geometry, visit) => {
|
|
80
80
|
if (!geometry) {
|
|
@@ -217,7 +217,7 @@ const appendDescriptionItem = (list, label, value) => {
|
|
|
217
217
|
row.append(term, detail);
|
|
218
218
|
list.appendChild(row);
|
|
219
219
|
};
|
|
220
|
-
const renderCollection = (collection, type) => {
|
|
220
|
+
const renderCollection = (collection, type, t) => {
|
|
221
221
|
const root = document.createElement('div');
|
|
222
222
|
root.className = 'geo-viewer';
|
|
223
223
|
const features = collection.features || [];
|
|
@@ -227,14 +227,14 @@ const renderCollection = (collection, type) => {
|
|
|
227
227
|
const badge = document.createElement('span');
|
|
228
228
|
badge.textContent = type.toUpperCase();
|
|
229
229
|
const heading = document.createElement('h2');
|
|
230
|
-
heading.textContent = '
|
|
230
|
+
heading.textContent = t('geo.title');
|
|
231
231
|
const description = document.createElement('dl');
|
|
232
|
-
appendDescriptionItem(description, '
|
|
233
|
-
appendDescriptionItem(description, '
|
|
232
|
+
appendDescriptionItem(description, t('geo.featureCount'), features.length);
|
|
233
|
+
appendDescriptionItem(description, t('geo.bounds'), formatBounds(bounds));
|
|
234
234
|
const counts = document.createElement('div');
|
|
235
235
|
counts.className = 'geo-counts';
|
|
236
236
|
const countsHeading = document.createElement('strong');
|
|
237
|
-
countsHeading.textContent = '
|
|
237
|
+
countsHeading.textContent = t('geo.geometryTypes');
|
|
238
238
|
counts.appendChild(countsHeading);
|
|
239
239
|
buildGeometryCounts(features).forEach(([name, count]) => {
|
|
240
240
|
const row = document.createElement('p');
|
|
@@ -247,7 +247,7 @@ const renderCollection = (collection, type) => {
|
|
|
247
247
|
const svg = createSvgElement('svg');
|
|
248
248
|
svg.setAttribute('viewBox', `0 0 ${GEO_WIDTH} ${GEO_HEIGHT}`);
|
|
249
249
|
svg.setAttribute('role', 'img');
|
|
250
|
-
svg.setAttribute('aria-label', '
|
|
250
|
+
svg.setAttribute('aria-label', t('geo.aria'));
|
|
251
251
|
const rect = createSvgElement('rect');
|
|
252
252
|
rect.setAttribute('width', String(GEO_WIDTH));
|
|
253
253
|
rect.setAttribute('height', String(GEO_HEIGHT));
|
|
@@ -259,16 +259,17 @@ const renderCollection = (collection, type) => {
|
|
|
259
259
|
root.append(panel, map);
|
|
260
260
|
return root;
|
|
261
261
|
};
|
|
262
|
-
export default async function renderGeo(buffer, target, type) {
|
|
262
|
+
export default async function renderGeo(buffer, target, type, context) {
|
|
263
263
|
const normalizedType = normalizeGeoType(type);
|
|
264
|
+
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
264
265
|
const style = createStyle();
|
|
265
266
|
const state = document.createElement('div');
|
|
266
267
|
state.className = 'geo-state';
|
|
267
|
-
state.textContent = '
|
|
268
|
+
state.textContent = t('geo.loading');
|
|
268
269
|
target.replaceChildren(style, state);
|
|
269
270
|
try {
|
|
270
|
-
const collection = await parseGeo(buffer, normalizedType);
|
|
271
|
-
target.replaceChildren(style, renderCollection(collection, normalizedType));
|
|
271
|
+
const collection = await parseGeo(buffer, normalizedType, t);
|
|
272
|
+
target.replaceChildren(style, renderCollection(collection, normalizedType, t));
|
|
272
273
|
}
|
|
273
274
|
catch (error) {
|
|
274
275
|
console.error(error);
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ if (!geoDefinition) {
|
|
|
4
4
|
throw new Error('@file-viewer/renderer-geo could not locate the core geospatial renderer definition.');
|
|
5
5
|
}
|
|
6
6
|
export const geoRendererDefinition = geoDefinition;
|
|
7
|
-
export const renderFileViewerGeo = (buffer, target, type) => import('./geo.js').then(({ default: renderGeo }) => renderGeo(buffer, target, type));
|
|
7
|
+
export const renderFileViewerGeo = (buffer, target, type, context) => import('./geo.js').then(({ default: renderGeo }) => renderGeo(buffer, target, type, context));
|
|
8
8
|
export const geoRenderer = {
|
|
9
9
|
id: 'file-viewer-renderer-geo',
|
|
10
10
|
label: 'Flyfish File Viewer geospatial renderer',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-geo",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone geospatial renderer plugin for Flyfish File Viewer with GeoJSON, KML, GPX, and SHP parsing, SVG map preview, and offline-friendly lazy loading.",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"LICENSE"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@file-viewer/core": "^2.1.
|
|
58
|
+
"@file-viewer/core": "^2.1.3",
|
|
59
59
|
"@tmcw/togeojson": "^7.1.2",
|
|
60
60
|
"shpjs": "^6.2.0"
|
|
61
61
|
},
|