Fix split way action, add decent tests for them (fix #171), enable split road on cyclestreets theme

This commit is contained in:
Pieter Vander Vennet 2021-10-16 02:54:22 +02:00
parent affe8237dc
commit a2aa26aafc
12 changed files with 1908 additions and 60 deletions

View file

@ -48,6 +48,7 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
if(whitelist !== undefined){
const isWhiteListed = whitelist.get(zxy[1])?.has(zxy[2])
if(!isWhiteListed){
console.log("Not downloading tile", ...zxy, "as it is not on the whitelist")
return undefined;
}
}

View file

@ -109,6 +109,8 @@ export default class OsmFeatureSource {
geojson.features = geojson.features.filter(feature => this.allowedTags.matchesProperties(feature.properties))
geojson.features.forEach(f => f.properties["_backend"] = this._backend)
console.log("Tile geojson:", z, x, y, "is", geojson)
const index = Tiles.tile_index(z, x, y);
new PerLayerFeatureSourceSplitter(this.filteredLayers,

View file

@ -230,7 +230,7 @@ export class GeoOperations {
* The properties object will contain three values:
// - `index`: closest point was found on nth line part,
// - `dist`: distance between pt and the closest point (in kilometer),
// `location`: distance along the line between start and the closest point.
// `location`: distance along the line between start (of the line) and the closest point.
* @param way The road on which you want to find a point
* @param point Point defined as [lon, lat]
*/

View file

@ -15,17 +15,21 @@ export default class SplitAction extends OsmChangeAction {
private readonly wayId: string;
private readonly _splitPointsCoordinates: [number, number] []// lon, lat
private _meta: { theme: string, changeType: "split" };
private _toleranceInMeters: number;
/**
*
* Create a changedescription for splitting a point.
* Will attempt to reuse existing points
* @param wayId
* @param splitPointCoordinates: lon, lat
* @param meta
* @param toleranceInMeters: if a splitpoint closer then this amount of meters to an existing point, the existing point will be used to split the line instead of a new point
*/
constructor(wayId: string, splitPointCoordinates: [number, number][], meta: {theme: string}) {
constructor(wayId: string, splitPointCoordinates: [number, number][], meta: {theme: string}, toleranceInMeters = 5) {
super()
this.wayId = wayId;
this._splitPointsCoordinates = splitPointCoordinates
this._toleranceInMeters = toleranceInMeters;
this._meta = {...meta, changeType: "split"};
}
@ -51,7 +55,7 @@ export default class SplitAction extends OsmChangeAction {
const originalNodes = originalElement.nodes;
// First, calculate splitpoints and remove points close to one another
const splitInfo = this.CalculateSplitCoordinates(originalElement)
const splitInfo = this.CalculateSplitCoordinates(originalElement, this._toleranceInMeters)
// Now we have a list with e.g.
// [ { originalIndex: 0}, {originalIndex: 1, doSplit: true}, {originalIndex: 2}, {originalIndex: undefined, doSplit: true}, {originalIndex: 3}]
@ -230,17 +234,19 @@ export default class SplitAction extends OsmChangeAction {
// We keep the original points
continue
}
if (point.dist * 1000 >= toleranceInM) {
// No need to remove this one
continue
}
// At this point, 'dist' told us the point is pretty close to an already existing point.
// Lets see which (already existing) point is closer and mark it as splitpoint
const nextPoint = allPoints[i + 1]
const prevPoint = allPoints[i - 1]
const distToNext = nextPoint.location - point.location
const distToPrev = prevPoint.location - point.location
const distToPrev = point.location - prevPoint.location
if(distToNext * 1000 > toleranceInM && distToPrev * 1000 > toleranceInM){
// Both are too far away to mark them as the split point
continue;
}
let closest = nextPoint
if (distToNext > distToPrev) {
closest = prevPoint

View file

@ -25,7 +25,8 @@ export default class SimpleMetaTagger {
"_last_edit:contributor:uid",
"_last_edit:changeset",
"_last_edit:timestamp",
"_version_number"],
"_version_number",
"_backend"],
doc: "Information about the last edit of this object."
},
(feature) => {/*Note: also called by 'UpdateTagsFromOsmAPI'*/