@swissgeo/coordinates 1.0.0-rc.1 → 1.0.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.
Files changed (39) hide show
  1. package/README.md +118 -0
  2. package/dist/index.cjs +7 -0
  3. package/dist/index.d.ts +1 -12
  4. package/dist/index.js +8012 -18103
  5. package/dist/ol.cjs +1 -0
  6. package/dist/ol.d.ts +10 -0
  7. package/dist/ol.js +4467 -0
  8. package/dist/registerProj4-BuUOcPpF.cjs +23 -0
  9. package/dist/registerProj4-CwR_kPOz.js +10172 -0
  10. package/eslint.config.mts +12 -0
  11. package/index.html +14 -0
  12. package/package.json +30 -23
  13. package/setup-vitest.ts +8 -0
  14. package/src/DevApp.vue +65 -0
  15. package/src/__test__/coordinatesUtils.spec.ts +178 -0
  16. package/src/__test__/extentUtils.spec.ts +92 -0
  17. package/src/coordinatesUtils.ts +188 -0
  18. package/src/dev.ts +6 -0
  19. package/src/extentUtils.ts +196 -0
  20. package/src/index.ts +29 -0
  21. package/src/ol.ts +52 -0
  22. package/src/proj/CoordinateSystem.ts +315 -0
  23. package/src/proj/CoordinateSystemBounds.ts +170 -0
  24. package/src/proj/CustomCoordinateSystem.ts +58 -0
  25. package/src/proj/LV03CoordinateSystem.ts +23 -0
  26. package/src/proj/LV95CoordinateSystem.ts +35 -0
  27. package/src/proj/StandardCoordinateSystem.ts +22 -0
  28. package/src/proj/SwissCoordinateSystem.ts +233 -0
  29. package/src/proj/WGS84CoordinateSystem.ts +97 -0
  30. package/src/proj/WebMercatorCoordinateSystem.ts +89 -0
  31. package/src/proj/__test__/CoordinateSystem.spec.ts +63 -0
  32. package/src/proj/__test__/CoordinateSystemBounds.spec.ts +252 -0
  33. package/src/proj/__test__/SwissCoordinateSystem.spec.ts +136 -0
  34. package/src/proj/index.ts +65 -0
  35. package/src/proj/types.ts +22 -0
  36. package/src/registerProj4.ts +38 -0
  37. package/tsconfig.json +4 -0
  38. package/vite.config.ts +46 -0
  39. package/dist/index.umd.cjs +0 -29
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # @swissgeo/coordinates
2
+
3
+ Projection definitions and coordinate utilities for SWISSGEO projects, with utilities to set up an OpenLayers map in LV95.
4
+
5
+ ## Overview
6
+
7
+ This package provides a comprehensive set of tools for working with geographic coordinates and map extents, with a focus on Swiss coordinate systems (LV95, LV03) and standard systems (WGS84, Web Mercator).
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @swissgeo/coordinates
13
+ ```
14
+
15
+ Note: This package has `proj4` as a peer dependency.
16
+
17
+ Note: If you intend to use the OpenLayers utilities, you will also need to install `ol` (optional dependency).
18
+
19
+ ## Features
20
+
21
+ - **Projection Definitions**: Built-in support for:
22
+ - **LV95** (EPSG:2056) - Swiss CH1903+ / LV95
23
+ - **LV03** (EPSG:21781) - Swiss CH1903 / LV03
24
+ - **WGS84** (EPSG:4326) - World Geodetic System 1984
25
+ - **Web Mercator** (EPSG:3857) - WGS 84 / Pseudo-Mercator
26
+ - **Coordinate Utilities**: Formatting, reprojection, rounding, and validation.
27
+ - **Extent Utilities**: Normalization, reprojection, intersection, and center calculation.
28
+ - **OpenLayers Integration**: Helper functions for OpenLayers in regard to Swiss projection systems (TileGrids, Views).
29
+
30
+ ## Usage
31
+
32
+ ### Basic Usage
33
+
34
+ The default export provides access to all coordinate systems and utility modules.
35
+
36
+ ```typescript
37
+ import { LV95, WGS84, coordinatesUtils } from '@swissgeo/coordinates'
38
+
39
+ // Reproject a coordinate
40
+ const pointLV95 = [2600000, 1200000]
41
+ const pointWGS84 = coordinatesUtils.reprojectAndRound(LV95, WGS84, pointLV95)
42
+ ```
43
+
44
+ ### Projections and Constants
45
+
46
+ You can import specific coordinate systems and constants:
47
+
48
+ ```typescript
49
+ import { LV95, constants } from '@swissgeo/coordinates'
50
+
51
+ console.log(LV95.epsg) // "EPSG:2056"
52
+ console.log(constants.LV95_RESOLUTIONS) // Array of resolutions for LV95
53
+ ```
54
+
55
+ ### Coordinate Utilities
56
+
57
+ ```typescript
58
+ import { coordinatesUtils } from '@swissgeo/coordinates'
59
+
60
+ // Format coordinates for display
61
+ const formatted = coordinatesUtils.toRoundedString([2600000, 1200000], 2)
62
+ // => "2'600'000.00, 1'200'000.00"
63
+
64
+ // Parse CRS string to CoordinateSystem object
65
+ const crs = coordinatesUtils.parseCRS('EPSG:2056')
66
+ // => LV95
67
+ ```
68
+
69
+ ### Extent Utilities
70
+
71
+ ```typescript
72
+ import { extentUtils, LV95, WGS84 } from '@swissgeo/coordinates'
73
+
74
+ const extentLV95 = [2485000, 1075000, 2837000, 1296000]
75
+
76
+ // Reproject an extent
77
+ const extentWGS84 = extentUtils.projExtent(LV95, WGS84, extentLV95)
78
+
79
+ // Get center of an extent
80
+ const center = extentUtils.getExtentCenter(extentLV95)
81
+ ```
82
+
83
+ ### OpenLayers Integration
84
+
85
+ The package provides specialized helpers for OpenLayers in `@swissgeo/coordinates/ol`.
86
+
87
+ ```typescript
88
+ import { getLV95View, getLV95TileGrid, registerSwissGeoProjections } from '@swissgeo/coordinates/ol'
89
+ import TileLayer from 'ol/layer/Tile'
90
+ import Map from 'ol/Map'
91
+ import XYZ from 'ol/source/XYZ'
92
+
93
+ // 1. Register projections in proj4 and OpenLayers
94
+ registerSwissGeoProjections()
95
+
96
+ // 2. Use helpers to create View and TileGrid
97
+ const map = new Map({
98
+ target: 'map',
99
+ view: getLV95View(),
100
+ layers: [
101
+ new TileLayer({
102
+ source: new XYZ({
103
+ url: 'https://wmts.geo.admin.ch/1.0.0/ch.swisstopo.pixelkarte-farbe/default/current/2056/{z}/{x}/{y}.jpeg'
104
+ projection: LV95.epsg,
105
+ tileGrid: getLV95TileGrid()
106
+ })
107
+ })
108
+ ]
109
+ })
110
+ ```
111
+
112
+ ## License
113
+
114
+ BSD-3-Clause
115
+
116
+ ## Repository
117
+
118
+ [https://github.com/geoadmin/web-mapviewer](https://github.com/geoadmin/web-mapviewer)