@swissgeo/coordinates 1.0.0-rc.1 → 1.0.1
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 +119 -0
- package/dist/index.cjs +7 -0
- package/dist/index.d.ts +1 -12
- package/dist/index.js +8012 -18103
- package/dist/ol.cjs +1 -0
- package/dist/ol.d.ts +11 -0
- package/dist/ol.js +4467 -0
- package/dist/registerProj4-BuUOcPpF.cjs +23 -0
- package/dist/registerProj4-CwR_kPOz.js +10172 -0
- package/eslint.config.mts +12 -0
- package/index.html +14 -0
- package/package.json +30 -23
- package/setup-vitest.ts +8 -0
- package/src/DevApp.vue +66 -0
- package/src/__test__/coordinatesUtils.spec.ts +178 -0
- package/src/__test__/extentUtils.spec.ts +92 -0
- package/src/coordinatesUtils.ts +188 -0
- package/src/dev.ts +6 -0
- package/src/extentUtils.ts +196 -0
- package/src/index.ts +29 -0
- package/src/ol.ts +53 -0
- package/src/proj/CoordinateSystem.ts +315 -0
- package/src/proj/CoordinateSystemBounds.ts +170 -0
- package/src/proj/CustomCoordinateSystem.ts +58 -0
- package/src/proj/LV03CoordinateSystem.ts +23 -0
- package/src/proj/LV95CoordinateSystem.ts +35 -0
- package/src/proj/StandardCoordinateSystem.ts +22 -0
- package/src/proj/SwissCoordinateSystem.ts +233 -0
- package/src/proj/WGS84CoordinateSystem.ts +97 -0
- package/src/proj/WebMercatorCoordinateSystem.ts +89 -0
- package/src/proj/__test__/CoordinateSystem.spec.ts +63 -0
- package/src/proj/__test__/CoordinateSystemBounds.spec.ts +252 -0
- package/src/proj/__test__/SwissCoordinateSystem.spec.ts +136 -0
- package/src/proj/index.ts +65 -0
- package/src/proj/types.ts +22 -0
- package/src/registerProj4.ts +38 -0
- package/tsconfig.json +4 -0
- package/vite.config.ts +46 -0
- package/dist/index.umd.cjs +0 -29
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
import proj4 from 'proj4'
|
|
93
|
+
|
|
94
|
+
// 1. Register projections in proj4 and OpenLayers
|
|
95
|
+
registerSwissGeoProjections(proj4)
|
|
96
|
+
|
|
97
|
+
// 2. Use helpers to create View and TileGrid
|
|
98
|
+
const map = new Map({
|
|
99
|
+
target: 'map',
|
|
100
|
+
view: getLV95View(),
|
|
101
|
+
layers: [
|
|
102
|
+
new TileLayer({
|
|
103
|
+
source: new XYZ({
|
|
104
|
+
url: 'https://wmts.geo.admin.ch/1.0.0/ch.swisstopo.pixelkarte-farbe/default/current/2056/{z}/{x}/{y}.jpeg'
|
|
105
|
+
projection: LV95.epsg,
|
|
106
|
+
tileGrid: getLV95TileGrid()
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
]
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
BSD-3-Clause
|
|
116
|
+
|
|
117
|
+
## Repository
|
|
118
|
+
|
|
119
|
+
[https://github.com/geoadmin/web-mapviewer](https://github.com/geoadmin/web-mapviewer)
|