Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik committed Jan 20, 2025
1 parent c4c6c57 commit 76c2d54
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/services/osm/osmApiAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,35 @@ const getNewNodeXml = async (
return buildXmlString(xml);
};

const getNewRelationXml = async (changesetId: string, newTags: FeatureTags) => {
const xml = await parseToXml2Js('<osm><relation /></osm>');
xml.relation.$.changeset = changesetId;
xml.relation.tag = getXmlTags(newTags);
return buildXmlString(xml);
};

const saveChange = async (
changesetId: string,
{ shortId, version, tags, toBeDeleted, nodeLonLat, members }: EditDataItem,
): Promise<OsmId> => {
// TODO don't save changes if no change detected

console.log('___', changesetId, nodeLonLat, tags);
let apiId = getApiId(shortId);
if (apiId.id < 0) {
if (apiId.type !== 'node') {
throw new Error('We can only add new nodes so far.');
if (apiId.type === 'way') {
throw new Error('We can only add new nodes and relations so far.');
}
if (apiId.type === 'node') {
const content = await getNewNodeXml(changesetId, nodeLonLat, tags);
const newNodeId = await createItem(content);
return { type: 'node', id: parseInt(newNodeId, 10) };
}
if (apiId.type === 'relation') {
const content = await getNewRelationXml(changesetId, tags);
console.log('___2', content);
const newRelationId = await createItem(content);
return { type: 'relation', id: parseInt(newRelationId, 10) };
}
const content = await getNewNodeXml(changesetId, nodeLonLat, tags);
const newNodeId = await createItem(content);
return { type: 'node', id: parseInt(newNodeId, 10) };
}

const freshItem = await getItem(apiId);
Expand Down Expand Up @@ -362,6 +377,7 @@ export const saveChanges = async (

const changesRelations = changes.filter(({ shortId }) => shortId[0] === 'r');

console.log('___1');
const changesRelationsWithNewNodeIds = changesRelations.map((change) => {
return {
...change,
Expand All @@ -377,12 +393,14 @@ export const saveChanges = async (
}),
};
});
console.log('___2', changesRelationsWithNewNodeIds);

const savedRelationsIds = await Promise.all(
changesRelationsWithNewNodeIds.map((change) =>
saveChange(changesetId, change),
),
);
console.log('___3', savedRelationsIds);

await putChangesetClose(changesetId);

Expand Down

0 comments on commit 76c2d54

Please sign in to comment.