@opengeospatial/jsonld-ui-utils 0.3.0 → 0.4.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 +53 -1
- package/dist/crs.d.ts +25 -0
- package/dist/jsonld-ui-utils-leaflet.min.js +2 -2
- package/dist/jsonld-ui-utils-leaflet.min.js.map +1 -1
- package/dist/leaflet.cjs.js +201 -3
- package/dist/leaflet.cjs.js.map +1 -1
- package/dist/leaflet.d.ts +5 -1
- package/dist/leaflet.esm.js +201 -3
- package/dist/leaflet.esm.js.map +1 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -27,6 +27,12 @@ yarn add @opengeospatial/jsonld-ui-utils
|
|
|
27
27
|
npm install jsonld
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
[`proj4`](https://www.npmjs.com/package/proj4) is an optional peer dependency required only when using the Leaflet plugin with non-WGS84 data:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install proj4
|
|
34
|
+
```
|
|
35
|
+
|
|
30
36
|
### Browser (IIFE)
|
|
31
37
|
|
|
32
38
|
```html
|
|
@@ -178,6 +184,9 @@ import { createJsonLDGeoJSONLayer } from '@opengeospatial/jsonld-ui-utils/leafle
|
|
|
178
184
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
|
|
179
185
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@opengeospatial/jsonld-ui-utils@latest/dist/jsonld-ui-utils.css"/>
|
|
180
186
|
|
|
187
|
+
<!-- optional: required only for non-WGS84 data (must come before the plugin) -->
|
|
188
|
+
<script src="https://unpkg.com/proj4@latest/dist/proj4.js"></script>
|
|
189
|
+
|
|
181
190
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
|
182
191
|
<script src="https://cdn.jsdelivr.net/npm/@opengeospatial/jsonld-ui-utils@latest/dist/jsonld-ui-utils-leaflet.min.js"></script>
|
|
183
192
|
```
|
|
@@ -186,8 +195,10 @@ This exposes `jsonldUIUtilsLeaflet` as a global variable.
|
|
|
186
195
|
|
|
187
196
|
### Usage
|
|
188
197
|
|
|
198
|
+
`createJsonLDGeoJSONLayer` returns a `Promise<L.GeoJSON>`:
|
|
199
|
+
|
|
189
200
|
```javascript
|
|
190
|
-
const layer =
|
|
201
|
+
const layer = await createJsonLDGeoJSONLayer(L, geojsonData, {
|
|
191
202
|
ldContext: 'https://example.org/context.jsonld',
|
|
192
203
|
popupOptions: { maxWidth: 420 },
|
|
193
204
|
augmentOptions: {
|
|
@@ -198,11 +209,49 @@ const layer = jsonldUIUtilsLeaflet.createJsonLDGeoJSONLayer(L, geojsonData, {
|
|
|
198
209
|
layer.addTo(map);
|
|
199
210
|
```
|
|
200
211
|
|
|
212
|
+
Or with `.then()`:
|
|
213
|
+
|
|
214
|
+
```javascript
|
|
215
|
+
createJsonLDGeoJSONLayer(L, geojsonData, options).then(layer => {
|
|
216
|
+
layer.addTo(map);
|
|
217
|
+
map.fitBounds(layer.getBounds());
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
201
221
|
### Behaviour
|
|
202
222
|
|
|
203
223
|
- Each feature with a non-empty `properties` object gets a popup with a rendered table.
|
|
204
224
|
- If the feature has an `id`, it is shown as a hover tooltip automatically.
|
|
205
225
|
- The popup table is augmented with RDF labels/descriptions when `ldContext` is provided.
|
|
226
|
+
- For WGS84 data the function resolves immediately with no additional network requests.
|
|
227
|
+
|
|
228
|
+
### CRS support (beta)
|
|
229
|
+
|
|
230
|
+
The plugin can render data in coordinate reference systems other than WGS84 by transforming geometries to WGS84 before passing them to Leaflet.
|
|
231
|
+
|
|
232
|
+
The CRS is detected automatically from the input data in priority order:
|
|
233
|
+
|
|
234
|
+
1. **JSON-FG `coordRefSys`** — a URI string, a `{ "type": "Reference", "href": "...", "epoch": ... }` object, or an array of these (compound CRS; the first EPSG entry is used)
|
|
235
|
+
2. **Legacy GeoJSON `crs`** — `{ "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::XXXX" } }`
|
|
236
|
+
|
|
237
|
+
If the detected CRS is not already registered with proj4, the plugin fetches its definition from [epsg.io](https://epsg.io) on first use and caches it for the lifetime of the page.
|
|
238
|
+
|
|
239
|
+
**Requirements:** [proj4js](https://proj4js.org/) must be available. In ESM/CJS projects install it as a peer dependency (`npm install proj4`). In browser IIFE usage, load the proj4 script before the plugin (see snippet above) so that `window.proj4` is present.
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
// CRS is read automatically from data.crs or data.coordRefSys
|
|
243
|
+
const layer = await createJsonLDGeoJSONLayer(L, dataInEpsg5514, options);
|
|
244
|
+
|
|
245
|
+
// Or supply a CRS explicitly, bypassing auto-detection:
|
|
246
|
+
const layer = await createJsonLDGeoJSONLayer(L, data, {
|
|
247
|
+
...options,
|
|
248
|
+
coordRefSys: 'EPSG:5514',
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Per the JSON-FG scoping rules, a `coordRefSys` on an individual feature overrides the collection-level value for that feature's geometry.
|
|
253
|
+
|
|
254
|
+
> **Note:** Coordinate epochs (present on some dynamic CRS references) are not supported by proj4js and are silently ignored with a console warning.
|
|
206
255
|
|
|
207
256
|
### Options (`JsonLDGeoJSONOptions`)
|
|
208
257
|
|
|
@@ -212,6 +261,8 @@ layer.addTo(map);
|
|
|
212
261
|
| `popupOptions` | `object` | `{ maxWidth: 400 }` | Options passed to Leaflet's `bindPopup`. |
|
|
213
262
|
| `augmentOptions` | `object` | `{}` | Options passed to `augment()` (see above). |
|
|
214
263
|
| `onEachFeature` | `function` | — | Called for every feature before the plugin's own logic, matching Leaflet's `onEachFeature` signature. |
|
|
264
|
+
| `coordRefSys` | `string` | — | Override CRS detection with an explicit URI (e.g. `"EPSG:5514"`). |
|
|
265
|
+
| `proj4` | `object` | — | Inject a specific proj4 instance instead of using the auto-resolved one. |
|
|
215
266
|
|
|
216
267
|
Any other options are forwarded to `L.geoJSON`.
|
|
217
268
|
|
|
@@ -221,6 +272,7 @@ Any other options are forwarded to `L.geoJSON`.
|
|
|
221
272
|
|
|
222
273
|
- [Basic demo](https://ogcincubator.github.io/jsonld-ui-utils/demo/index.html) — renders a JSON-LD feature as an augmented properties table
|
|
223
274
|
- [Leaflet demo](https://ogcincubator.github.io/jsonld-ui-utils/demo/leaflet.html) — GeoJSON layer with popup tables and RDF augmentation
|
|
275
|
+
- [Leaflet CRS demo](https://ogcincubator.github.io/jsonld-ui-utils/demo/leaflet-crs.html) — GeoJSON layer in EPSG:5514 (Czech S-JTSK), auto-detected and reprojected to WGS84
|
|
224
276
|
|
|
225
277
|
## Building from source
|
|
226
278
|
|
package/dist/crs.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface CrsInfo {
|
|
2
|
+
epsgCode: number;
|
|
3
|
+
epoch?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Detects the CRS from a GeoJSON/JSON-FG object.
|
|
7
|
+
*
|
|
8
|
+
* Checks in priority order:
|
|
9
|
+
* 1. JSON-FG `coordRefSys` (URI string, Reference object, or compound array)
|
|
10
|
+
* 2. Legacy GeoJSON `crs` with type "name"
|
|
11
|
+
*
|
|
12
|
+
* Returns null if the CRS is WGS84 or cannot be determined (no transform needed).
|
|
13
|
+
*/
|
|
14
|
+
export declare function detectCrs(data: unknown): CrsInfo | null;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a proj4 converter from the given EPSG CRS to WGS84.
|
|
17
|
+
* Fetches the projection definition from epsg.io if not already registered.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getProjectionConverter(crsInfo: CrsInfo, proj4Instance: any): Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
* Deep-clones and transforms all geometries in a FeatureCollection or Feature
|
|
22
|
+
* from the given CRS to WGS84. Per the JSON-FG scoping rules, individual features
|
|
23
|
+
* may carry their own `coordRefSys` that overrides the collection-level one.
|
|
24
|
+
*/
|
|
25
|
+
export declare function transformFeatureCollection(data: any, collectionCrs: CrsInfo, proj4Instance: any): Promise<any>;
|