Full code cleanup
This commit is contained in:
parent
3a4a2a2016
commit
fa971ffbbf
300 changed files with 16352 additions and 19284 deletions
|
@ -11,7 +11,7 @@ export default class ChangeLocationAction extends OsmChangeAction {
|
|||
theme: string,
|
||||
reason: string
|
||||
}) {
|
||||
super(id,true);
|
||||
super(id, true);
|
||||
if (!id.startsWith("node/")) {
|
||||
throw "Invalid ID: only 'node/number' is accepted"
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ export default class ChangeLocationAction extends OsmChangeAction {
|
|||
this._newLonLat = newLonLat;
|
||||
this._meta = meta;
|
||||
}
|
||||
|
||||
|
||||
protected async CreateChangeDescriptions(changes: Changes): Promise<ChangeDescription[]> {
|
||||
|
||||
const d: ChangeDescription = {
|
||||
|
|
|
@ -19,7 +19,7 @@ export default class ChangeTagAction extends OsmChangeAction {
|
|||
this._currentTags = currentTags;
|
||||
this._meta = meta;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Doublechecks that no stupid values are added
|
||||
*/
|
||||
|
|
|
@ -14,35 +14,36 @@ import {TagUtils} from "../../Tags/TagUtils";
|
|||
* More or less the same as 'CreateNewWay', except that it'll try to reuse already existing points
|
||||
*/
|
||||
export default class CreateMultiPolygonWithPointReuseAction extends OsmCreateAction {
|
||||
private readonly _tags: Tag[];
|
||||
public newElementId: string = undefined;
|
||||
public newElementIdNumber: number = undefined;
|
||||
public newElementIdNumber: number = undefined;
|
||||
private readonly _tags: Tag[];
|
||||
private readonly createOuterWay: CreateWayWithPointReuseAction
|
||||
private readonly createInnerWays : CreateNewWayAction[]
|
||||
private readonly geojsonPreview: any;
|
||||
private readonly createInnerWays: CreateNewWayAction[]
|
||||
private readonly geojsonPreview: any;
|
||||
private readonly theme: string;
|
||||
private readonly changeType: "import" | "create" | string;
|
||||
|
||||
constructor(tags: Tag[],
|
||||
outerRingCoordinates: [number, number][],
|
||||
innerRingsCoordinates: [number, number][][],
|
||||
innerRingsCoordinates: [number, number][][],
|
||||
state: FeaturePipelineState,
|
||||
config: MergePointConfig[],
|
||||
changeType: "import" | "create" | string
|
||||
) {
|
||||
super(null,true);
|
||||
this._tags = [...tags, new Tag("type","multipolygon")];
|
||||
super(null, true);
|
||||
this._tags = [...tags, new Tag("type", "multipolygon")];
|
||||
this.changeType = changeType;
|
||||
this.theme = state.layoutToUse.id
|
||||
this. createOuterWay = new CreateWayWithPointReuseAction([], outerRingCoordinates, state, config)
|
||||
this. createInnerWays = innerRingsCoordinates.map(ringCoordinates =>
|
||||
new CreateNewWayAction([],
|
||||
ringCoordinates.map(([lon, lat] )=> ({lat, lon})),
|
||||
{theme: state.layoutToUse.id}))
|
||||
|
||||
this.geojsonPreview = {
|
||||
this.createOuterWay = new CreateWayWithPointReuseAction([], outerRingCoordinates, state, config)
|
||||
this.createInnerWays = innerRingsCoordinates.map(ringCoordinates =>
|
||||
new CreateNewWayAction([],
|
||||
ringCoordinates.map(([lon, lat]) => ({lat, lon})),
|
||||
{theme: state.layoutToUse.id}))
|
||||
|
||||
this.geojsonPreview = {
|
||||
type: "Feature",
|
||||
properties: TagUtils.changeAsProperties(new And(this._tags).asChange({})),
|
||||
geometry:{
|
||||
geometry: {
|
||||
type: "Polygon",
|
||||
coordinates: [
|
||||
outerRingCoordinates,
|
||||
|
@ -59,7 +60,7 @@ private readonly geojsonPreview: any;
|
|||
freshness: new Date(),
|
||||
feature: this.geojsonPreview
|
||||
})
|
||||
return outerPreview
|
||||
return outerPreview
|
||||
}
|
||||
|
||||
protected async CreateChangeDescriptions(changes: Changes): Promise<ChangeDescription[]> {
|
||||
|
@ -72,14 +73,14 @@ private readonly geojsonPreview: any;
|
|||
|
||||
|
||||
this.newElementIdNumber = changes.getNewID();
|
||||
this.newElementId = "relation/"+this.newElementIdNumber
|
||||
this.newElementId = "relation/" + this.newElementIdNumber
|
||||
descriptions.push({
|
||||
type:"relation",
|
||||
type: "relation",
|
||||
id: this.newElementIdNumber,
|
||||
tags: new And(this._tags).asChange({}),
|
||||
meta: {
|
||||
theme: this.theme,
|
||||
changeType:this.changeType
|
||||
changeType: this.changeType
|
||||
},
|
||||
changes: {
|
||||
members: [
|
||||
|
@ -93,8 +94,8 @@ private readonly geojsonPreview: any;
|
|||
]
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
return descriptions
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ export default class CreateNewNodeAction extends OsmCreateAction {
|
|||
changeType: "create" | "import" | null,
|
||||
specialMotivation?: string
|
||||
}) {
|
||||
super(null,basicTags !== undefined && basicTags.length > 0)
|
||||
super(null, basicTags !== undefined && basicTags.length > 0)
|
||||
this._basicTags = basicTags;
|
||||
this._lat = lat;
|
||||
this._lon = lon;
|
||||
|
@ -46,7 +46,7 @@ export default class CreateNewNodeAction extends OsmCreateAction {
|
|||
this.meta = {
|
||||
theme: options.theme,
|
||||
changeType: options.changeType,
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ export default class CreateNewWayAction extends OsmCreateAction {
|
|||
options: {
|
||||
theme: string
|
||||
}) {
|
||||
super(null,true)
|
||||
super(null, true)
|
||||
this.coordinates = coordinates;
|
||||
this.tags = tags;
|
||||
this._options = options;
|
||||
|
@ -56,7 +56,7 @@ export default class CreateNewWayAction extends OsmCreateAction {
|
|||
|
||||
|
||||
const id = changes.getNewID()
|
||||
this.newElementIdNumber = id
|
||||
this.newElementIdNumber = id
|
||||
const newWay = <ChangeDescription>{
|
||||
id,
|
||||
type: "way",
|
||||
|
|
|
@ -20,14 +20,14 @@ export interface MergePointConfig {
|
|||
|
||||
/**
|
||||
* CreateWayWithPointreuse will create a 'CoordinateInfo' for _every_ point in the way to be created.
|
||||
*
|
||||
*
|
||||
* The CoordinateInfo indicates the action to take, e.g.:
|
||||
*
|
||||
*
|
||||
* - Create a new point
|
||||
* - Reuse an existing OSM point (and don't move it)
|
||||
* - Reuse an existing OSM point (and leave it where it is)
|
||||
* - Reuse another Coordinate info (and don't do anything else with it)
|
||||
*
|
||||
*
|
||||
*/
|
||||
interface CoordinateInfo {
|
||||
/**
|
||||
|
@ -56,6 +56,8 @@ interface CoordinateInfo {
|
|||
* More or less the same as 'CreateNewWay', except that it'll try to reuse already existing points
|
||||
*/
|
||||
export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
||||
public newElementId: string = undefined;
|
||||
public newElementIdNumber: number = undefined
|
||||
private readonly _tags: Tag[];
|
||||
/**
|
||||
* lngLat-coordinates
|
||||
|
@ -64,20 +66,17 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
private _coordinateInfo: CoordinateInfo[];
|
||||
private _state: FeaturePipelineState;
|
||||
private _config: MergePointConfig[];
|
||||
|
||||
public newElementId: string = undefined;
|
||||
public newElementIdNumber: number = undefined
|
||||
|
||||
constructor(tags: Tag[],
|
||||
coordinates: [number, number][],
|
||||
state: FeaturePipelineState,
|
||||
config: MergePointConfig[]
|
||||
) {
|
||||
super(null,true);
|
||||
super(null, true);
|
||||
this._tags = tags;
|
||||
this._state = state;
|
||||
this._config = config;
|
||||
|
||||
|
||||
// The main logic of this class: the coordinateInfo contains all the changes
|
||||
this._coordinateInfo = this.CalculateClosebyNodes(coordinates);
|
||||
|
||||
|
@ -117,7 +116,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
"move": "yes",
|
||||
"osm-id": reusedPoint.node.properties.id,
|
||||
"id": "new-geometry-move-existing" + i,
|
||||
"distance":GeoOperations.distanceBetween(coordinateInfo.lngLat, reusedPoint.node.geometry.coordinates)
|
||||
"distance": GeoOperations.distanceBetween(coordinateInfo.lngLat, reusedPoint.node.geometry.coordinates)
|
||||
},
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
|
@ -136,7 +135,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
"move": "no",
|
||||
"osm-id": reusedPoint.node.properties.id,
|
||||
"id": "new-geometry-reuse-existing" + i,
|
||||
"distance":GeoOperations.distanceBetween(coordinateInfo.lngLat, reusedPoint.node.geometry.coordinates)
|
||||
"distance": GeoOperations.distanceBetween(coordinateInfo.lngLat, reusedPoint.node.geometry.coordinates)
|
||||
},
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
|
@ -238,7 +237,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
const newWay = new CreateNewWayAction(this._tags, nodeIdsToUse, {
|
||||
theme
|
||||
})
|
||||
|
||||
|
||||
allChanges.push(...(await newWay.CreateChangeDescriptions(changes)))
|
||||
this.newElementId = newWay.newElementId
|
||||
this.newElementIdNumber = newWay.newElementIdNumber
|
||||
|
@ -266,7 +265,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
}[]
|
||||
}[] = coordinates.map(_ => undefined)
|
||||
|
||||
|
||||
|
||||
// First loop: gather all information...
|
||||
for (let i = 0; i < coordinates.length; i++) {
|
||||
|
||||
|
@ -328,7 +327,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Second loop: figure out which point moves where without creating conflicts
|
||||
let conflictFree = true;
|
||||
do {
|
||||
|
@ -348,8 +347,8 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
if (other.closebyNodes === undefined || other.closebyNodes[0] === undefined) {
|
||||
continue
|
||||
}
|
||||
|
||||
if(coorInfo.closebyNodes[0] === undefined){
|
||||
|
||||
if (coorInfo.closebyNodes[0] === undefined) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ export default class DeleteAction extends OsmChangeAction {
|
|||
specialMotivation: string
|
||||
},
|
||||
hardDelete: boolean) {
|
||||
super(id,true)
|
||||
super(id, true)
|
||||
this._id = id;
|
||||
this._hardDelete = hardDelete;
|
||||
this.meta = {...meta, changeType: "deletion"};
|
||||
|
@ -51,7 +51,7 @@ export default class DeleteAction extends OsmChangeAction {
|
|||
return await new ChangeTagAction(
|
||||
this._id, this._softDeletionTags, osmObject.tags,
|
||||
{
|
||||
... this.meta,
|
||||
...this.meta,
|
||||
changeType: "soft-delete"
|
||||
}
|
||||
).CreateChangeDescriptions(changes)
|
||||
|
|
|
@ -7,7 +7,6 @@ import {ChangeDescription} from "./ChangeDescription";
|
|||
|
||||
export default abstract class OsmChangeAction {
|
||||
|
||||
private isUsed = false
|
||||
public readonly trackStatistics: boolean;
|
||||
/**
|
||||
* The ID of the object that is the center of this change.
|
||||
|
@ -15,7 +14,8 @@ export default abstract class OsmChangeAction {
|
|||
* Undefined if such an id does not make sense
|
||||
*/
|
||||
public readonly mainObjectId: string;
|
||||
|
||||
private isUsed = false
|
||||
|
||||
constructor(mainObjectId: string, trackStatistics: boolean = true) {
|
||||
this.trackStatistics = trackStatistics;
|
||||
this.mainObjectId = mainObjectId
|
||||
|
@ -32,9 +32,9 @@ export default abstract class OsmChangeAction {
|
|||
protected abstract CreateChangeDescriptions(changes: Changes): Promise<ChangeDescription[]>
|
||||
}
|
||||
|
||||
export abstract class OsmCreateAction extends OsmChangeAction{
|
||||
export abstract class OsmCreateAction extends OsmChangeAction {
|
||||
|
||||
public newElementId : string
|
||||
public newElementId: string
|
||||
public newElementIdNumber: number
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,11 @@ abstract class AbstractRelationSplitHandler extends OsmChangeAction {
|
|||
protected readonly _theme: string;
|
||||
|
||||
constructor(input: RelationSplitInput, theme: string) {
|
||||
super("relation/"+input.relation.id, false)
|
||||
super("relation/" + input.relation.id, false)
|
||||
this._input = input;
|
||||
this._theme = theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns which node should border the member at the given index
|
||||
*/
|
||||
|
|
|
@ -468,12 +468,12 @@ export default class ReplaceGeometryAction extends OsmChangeAction {
|
|||
proj.sort((a, b) => {
|
||||
// Sort descending
|
||||
const diff = b.projectAfterIndex - a.projectAfterIndex;
|
||||
if(diff !== 0){
|
||||
if (diff !== 0) {
|
||||
return diff
|
||||
}
|
||||
return b.distance - a.distance;
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
for (const reprojectedNode of proj) {
|
||||
|
|
|
@ -26,7 +26,7 @@ export default class SplitAction extends OsmChangeAction {
|
|||
* @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 }, toleranceInMeters = 5) {
|
||||
super(wayId,true)
|
||||
super(wayId, true)
|
||||
this.wayId = wayId;
|
||||
this._splitPointsCoordinates = splitPointCoordinates
|
||||
this._toleranceInMeters = toleranceInMeters;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue