1.0.0 • Published 5 years ago
@map-colonies/node-osm-api v1.0.0
node-osm-api
Easy Node.js, TypeScript communication with OpenStreetMap api
import { Apiv6 } from '@map-colonies/node-osm-api';
const api = new Apiv6('https://www.openstreetmap.org', USER_NAME, PASSWORD);Installation
$ npm install @map-colonies/node-osm-apiUsage
- Right now we only support create/upload/close changesets
In Node.js TypeScript:
Performing Create changeset:
let changesetID: number;
async function createChangeset() {
try {
changesetID = await api.createChangeset(CREATE_CHANGESET_BODY_XML);
} catch (e) {
console.error(e);
}
}Possibble error types:
UnauthorizedErrorBadXmlError
Performing Upload changeset:
let diffRes: string;
async function uploadChangeset() {
try {
// returns osm xml diff result as string
diffRes = await api.uploadChangeset(CHANGESET_ID, OSC_XML);
} catch (e) {
console.error(e);
}
}Possibble error types:
UnauthorizedErrorBadXmlErrorChangesetOrDiffElementsNotFoundErrorChangesetAlreadyClosedErrorOwnerMismatchErrorMismatchChangesetError
Performing Close changeset:
async function closeChangeset() {
try {
await api.closeChangeset(CHANGESET_ID);
} catch (e) {
console.error(e);
}
}Possibble error types:
UnauthorizedErrorNotAllowedErrorChangesetNotFoundErrorChangesetAlreadyClosedErrorOwnerMismatchError
JavaScript
const nodeOsmApi = require('node-osm-api');
const api = new nodeOsmApi.Apiv6('https://www.openstreetmap.org', USER_NAME, PASSWORD);
async function createChangeset() {
try {
changesetID = await api.createChangeset(CREATE_CHANGESET_BODY_XML);
} catch (e) {
console.error(e);
}
}1.0.0
5 years ago