atriusmaps-node-sdk
Version:
This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information
47 lines (43 loc) • 1.56 kB
JavaScript
;
var geom = require('./geom.js');
async function locationToEndpoint(app, location) {
if (location.poiId) {
return app.bus.get("wayfinder/getNavigationEndpoint", {
ep: location.poiId
});
}
const { lat, lng, ord, title = "" } = location;
let { ordinal, floorId, structureId } = location;
if (lat == null || lng == null) {
throw Error("To obtain a location, you must provide a lat,lng or a poiId");
}
if (ordinal === void 0 && ord !== void 0) {
ordinal = ord;
}
const structures = await getStructures(app);
if (ordinal == null) {
if (floorId == null) {
throw Error("Call to locationToEndpoint with no ordinal and no floorId");
} else {
const floor = geom.getFloor(structures, floorId);
if (!floor) {
throw Error(`floor with id ${floorId} not found.`);
}
ordinal = floor.ordinal;
}
} else {
if (floorId == null) {
const mapviewBBox = await app.bus.get("map/getViewBBox");
const { structure, floor } = geom.getStructureAndFloorAtPoint(structures, lat, lng, ordinal, mapviewBBox, true);
floorId = floor?.id;
structureId = structure?.id;
}
}
if (floorId != null && structureId == null) {
structureId = geom.getStructureForFloorId(structures, floorId)?.id;
}
return { lat, lng, floorId, ordinal, title, structureId };
}
const getStructures = async (app) => app.bus.get("venueData/getVenueData").then((vd) => vd.structures);
exports.getStructures = getStructures;
exports.locationToEndpoint = locationToEndpoint;