Skip to content

Commit 8aee3d4

Browse files
Merge pull request #392 from PDOK/epsg-4258-bug
fix: EPSG:4258 didn't work in feature viewer (frontend)
2 parents 8637970 + 936249e commit 8aee3d4

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

viewer/cypress/shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpClientModule } from '@angular/common/http'
1+
import { provideHttpClient } from '@angular/common/http'
22
import { createOutputSpy } from 'cypress/angular'
33
import { Map as OLMap } from 'ol'
44
import { FeatureViewComponent } from 'src/app/feature-view/feature-view.component'
@@ -53,8 +53,8 @@ export function mountFeatureComponent(
5353
cy.log(JSON.stringify(allprop))
5454

5555
cy.mount(FeatureViewComponent, {
56+
providers: [provideHttpClient()],
5657
imports: [
57-
HttpClientModule,
5858
LoggerModule.forRoot({
5959
level: NgxLoggerLevel.DEBUG,
6060
}),

viewer/src/app/shared/model/map-projection.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,37 @@ export function initProj4() {
1818

1919
proj4.defs(
2020
'EPSG:4258',
21-
'GEOGCRS["ETRS89",ENSEMBLE["European Terrestrial Reference System 1989 ensemble", MEMBER["European Terrestrial Reference Frame 1989", ID["EPSG",1178]], MEMBER["European Terrestrial Reference Frame 1990", ID["EPSG",1179]], MEMBER["European Terrestrial Reference Frame 1991", ID["EPSG",1180]], MEMBER["European Terrestrial Reference Frame 1992", ID["EPSG",1181]], MEMBER["European Terrestrial Reference Frame 1993", ID["EPSG",1182]], MEMBER["European Terrestrial Reference Frame 1994", ID["EPSG",1183]], MEMBER["European Terrestrial Reference Frame 1996", ID["EPSG",1184]], MEMBER["European Terrestrial Reference Frame 1997", ID["EPSG",1185]], MEMBER["European Terrestrial Reference Frame 2000", ID["EPSG",1186]], MEMBER["European Terrestrial Reference Frame 2005", ID["EPSG",1204]], MEMBER["European Terrestrial Reference Frame 2014", ID["EPSG",1206]], MEMBER["European Terrestrial Reference Frame 2020", ID["EPSG",1382]], ELLIPSOID["GRS 1980",6378137,298.257222101,LENGTHUNIT["metre",1,ID["EPSG",9001]],ID["EPSG",7019]], ENSEMBLEACCURACY[0.1],ID["EPSG",6258]],CS[ellipsoidal,2,ID["EPSG",6422]],AXIS["Geodetic latitude (Lat)",north],AXIS["Geodetic longitude (Lon)",east],ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9102]],ID["EPSG",4258]]'
21+
`GEOGCRS["ETRS89",
22+
ENSEMBLE["European Terrestrial Reference System 1989 ensemble",
23+
MEMBER["European Terrestrial Reference Frame 1989"],
24+
MEMBER["European Terrestrial Reference Frame 1990"],
25+
MEMBER["European Terrestrial Reference Frame 1991"],
26+
MEMBER["European Terrestrial Reference Frame 1992"],
27+
MEMBER["European Terrestrial Reference Frame 1993"],
28+
MEMBER["European Terrestrial Reference Frame 1994"],
29+
MEMBER["European Terrestrial Reference Frame 1996"],
30+
MEMBER["European Terrestrial Reference Frame 1997"],
31+
MEMBER["European Terrestrial Reference Frame 2000"],
32+
MEMBER["European Terrestrial Reference Frame 2005"],
33+
MEMBER["European Terrestrial Reference Frame 2014"],
34+
MEMBER["European Terrestrial Reference Frame 2020"],
35+
ELLIPSOID["GRS 1980",6378137,298.257222101,
36+
LENGTHUNIT["metre",1]],
37+
ENSEMBLEACCURACY[0.1]],
38+
PRIMEM["Greenwich",0,
39+
ANGLEUNIT["degree",0.0174532925199433]],
40+
CS[ellipsoidal,2],
41+
AXIS["geodetic latitude (Lat)",north,
42+
ORDER[1],
43+
ANGLEUNIT["degree",0.0174532925199433]],
44+
AXIS["geodetic longitude (Lon)",east,
45+
ORDER[2],
46+
ANGLEUNIT["degree",0.0174532925199433]],
47+
USAGE[
48+
SCOPE["Spatial referencing."],
49+
AREA["Europe - onshore and offshore: Albania; Andorra; Austria; Belgium; Bosnia and Herzegovina; Bulgaria; Croatia; Czechia; Denmark; Estonia; Faroe Islands; Finland; France; Germany; Gibraltar; Greece; Hungary; Ireland; Italy; Kosovo; Latvia; Liechtenstein; Lithuania; Luxembourg; Malta; Moldova; Monaco; Montenegro; Netherlands; North Macedonia; Norway including Svalbard and Jan Mayen; Poland; Portugal - mainland; Romania; San Marino; Serbia; Slovakia; Slovenia; Spain - mainland and Balearic islands; Sweden; Switzerland; United Kingdom (UK) including Channel Islands and Isle of Man; Vatican City State."],
50+
BBOX[33.26,-16.1,84.73,38.01]],
51+
ID["EPSG",4258]]`
2252
)
2353

2454
proj4register(proj4)

viewer/src/app/shared/services/feature.service.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export type GeometryGeoJSON =
4646
| geometrycollectionGeoJSON
4747

4848
export type FeatureGeoJSON = {
49+
type: string
4950
geometry: GeometryGeoJSON
5051
id?: string | number
5152
links?: Array<Link>
@@ -54,6 +55,7 @@ export type FeatureGeoJSON = {
5455
}
5556

5657
export type FeatureCollectionGeoJSON = {
58+
type: string
5759
features: Array<FeatureGeoJSON>
5860
links?: Array<Link>
5961
numberReturned?: number
@@ -79,7 +81,9 @@ export class FeatureService {
7981
constructor(
8082
private logger: NGXLogger,
8183
private http: HttpClient
82-
) {}
84+
) {
85+
initProj4()
86+
}
8387

8488
queryFeatures(q: string, searchParams: { [key: string]: number }, crs?: string, bbox?: string): Observable<FeatureGeoJSON[]> {
8589
let params = new HttpParams().set('q', q)
@@ -125,17 +129,26 @@ export class FeatureService {
125129
return geom
126130
}
127131
if (url.url == '') return of([])
128-
return this.http.get<FeatureCollectionGeoJSON>(url.url).pipe(
132+
return this.http.get<FeatureCollectionGeoJSON | FeatureGeoJSON>(url.url).pipe(
129133
map(data => {
130134
let processedData = data
131135
if (url.dataMapping.swapAllowed && dataproj.getAxisOrientation() !== visualproj.getAxisOrientation()) {
132-
// Swap x/y in all features only if axis orientation differs
133-
processedData = {
134-
...data,
135-
features: data.features?.map(f => ({
136-
...f,
137-
geometry: swapXYCoords(f.geometry),
138-
})),
136+
if (data.type === 'FeatureCollection') {
137+
// Swap x/y in all features only if axis orientation differs
138+
const collection = data as FeatureCollectionGeoJSON
139+
processedData = {
140+
...collection,
141+
features: collection.features?.map(f => ({
142+
...f,
143+
geometry: swapXYCoords(f.geometry),
144+
})),
145+
} as FeatureCollectionGeoJSON
146+
} else {
147+
const feature = data as FeatureGeoJSON
148+
processedData = {
149+
...feature,
150+
geometry: swapXYCoords(feature.geometry),
151+
} as FeatureGeoJSON
139152
}
140153
}
141154
const features = new GeoJSON().readFeatures(processedData, {
@@ -149,7 +162,6 @@ export class FeatureService {
149162
}
150163

151164
getProjectionMapping(value: string = 'http://www.opengis.net/def/crs/OGC/1.3/CRS84'): ProjectionMapping {
152-
initProj4()
153165
if (value) {
154166
if (value.substring(value.lastIndexOf('/') + 1).toLocaleUpperCase() === 'CRS84') {
155167
//'EPSG:3857' Default the map is in Web Mercator(EPSG: 3857), the actual coordinates used are in lat-long (EPSG: 4326)

0 commit comments

Comments
 (0)