Skip to content

Commit

Permalink
Merge pull request #1018 from geoadmin/bug-PB-800-profile-discrepancy
Browse files Browse the repository at this point in the history
PB-800 : simplify GPXs geometry - #patch
  • Loading branch information
pakb authored Aug 5, 2024
2 parents 1428f4f + 27f8854 commit e51c69c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,14 @@ export const DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION = 50
* @type {Number}
*/
export const MAX_WIDTH_SHOW_FLOATING_TOOLTIP = 400

/**
* 12.5 meters is what was used in the old viewer, see
* https://github.com/geoadmin/mf-geoadmin3/blob/ce24a27b0ca8192a0f78f7b8cc07f4e231031304/src/components/GeomUtilsService.js#L207
*
* I tried lowering the value, but with the test GPX that were attached to the ticket PB-800 I get
* worst hiking time estimation when using something like 5m than if I use this 12.5 meters.
*
* @type {Number}
*/
export const GPX_GEOMETRY_SIMPLIFICATION_TOLERANCE = 12.5 // meters
6 changes: 5 additions & 1 deletion src/utils/gpxUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import bbox from '@turf/bbox'
import { isEmpty as isExtentEmpty } from 'ol/extent'
import GPX from 'ol/format/GPX'

import { GPX_GEOMETRY_SIMPLIFICATION_TOLERANCE } from '@/config'
import CoordinateSystem from '@/utils/coordinates/CoordinateSystem.class'
import { WGS84 } from '@/utils/coordinates/coordinateSystems'
import { gpxStyles } from '@/utils/styleUtils'
Expand Down Expand Up @@ -44,7 +45,10 @@ export function parseGpx(gpxData, projection) {
featureProjection: projection.epsg,
})
features.forEach((feature) => {
feature.setStyle(gpxStyles[feature.getGeometry().getType()])
const geom = feature.getGeometry()
// PB-800 : to avoid a coastline paradox we simplify the geometry of GPXs
feature.setGeometry(geom.simplify(GPX_GEOMETRY_SIMPLIFICATION_TOLERANCE))
feature.setStyle(gpxStyles[geom.getType()])
})
return features
}
Expand Down

0 comments on commit e51c69c

Please sign in to comment.