Commit be207d7d authored by athanasios's avatar athanasios
Browse files

boundingbox now optional

parent 972dcd68
const config = {
port: 9000
port: 9000,
boundingBoxBufferPercent: 15
}
module.exports = config;
\ No newline at end of file
const express = require("express");
const { check, validationResult, oneOf } = require("express-validator")
const { check, validationResult } = require("express-validator")
const { toLower } = require("../src/customSanitizers");
const { errorHandler } = require("../src/errorHandler");
const checkFactory = require("../src/validationCheckFactory");
const { getSceneHandler } = require("../src/getSceneHandler");
const { getCapabilitiesHandler } = require("../src/getCapabilitiesHandler");
const assets = require("../src/assets");
const bb = require("../src/boundingbox");
const redirectTo = require("../src/redirectTo");
......@@ -56,8 +57,11 @@ const sceneChecks = [
.exists().withMessage("MissingParameterValue")
.customSanitizer(toLower)
.equals("getscene").withMessage("InvalidParameterValue"),
check("boundingbox")
check("layers")
.exists().withMessage("MissingParameterValue")
.custom(value => assets.allLayersExist(value)).withMessage("UnknownLayer"),
check("boundingbox")
.optional()
.matches(/^((\-?\d+(\.\d+)?),){3}(\-?\d+(\.\d+)?)$/).withMessage("InvalidParameterValue")
.custom(value => bb.isValid(value)).withMessage("InvalidParameterValue"),
check("cullingvolume")
......@@ -74,11 +78,7 @@ const sceneChecks = [
.matches(/^((\-?\d+(\.\d+)?),){1}(\-?\d+(\.\d+)?)$/).withMessage("InvalidParameterValue"),
check("time")
.exists().withMessage("MissingParameterValue")
.matches(/\d+/).withMessage("InvalidParameterValue"),
check("intersect")
.exists().withMessage("MissingParameterValue")
.customSanitizer(toLower)
.isIn(["true", "false"]).withMessage("InvalidParameterValue")
.matches(/\d+/).withMessage("InvalidParameterValue")
];
router.route("/scene").get(sceneChecks, (req, res) => {
......
......@@ -2,6 +2,22 @@ const fs = require("fs");
const boxIntersect = require("box-intersect");
const path = require('path');
const getLayers = (layers) => {
return new Promise((resolve, reject) => {
fs.readFile("./assets/assets.json", (err, data) => {
if (err) {
reject();
}
let assets = JSON.parse(data);
let requestedLayers = layers.split(",");
assets = assets.filter(asset => requestedLayers.includes(asset.id));
assets = assets.filter(asset => asset.scope == "public");
resolve(assets);
});
});
}
const getIntersectingLayers = (bb, layers) => {
return new Promise((resolve, reject) => {
......@@ -124,4 +140,4 @@ const isPublic = (url) => {
}
module.exports = { getIntersectingLayers, getIntersecting, allLayersExist, getPublicLayers, isPublic };
\ No newline at end of file
module.exports = { getIntersectingLayers, getIntersecting, allLayersExist, getPublicLayers, isPublic, getLayers };
\ No newline at end of file
......@@ -12,8 +12,7 @@ const fromRequest = (req) => {
camera: camera.fromString(req.query.camera),
offCenterFrustum: offCenterFrustum.fromString(req.query.frustum),
drawingBuffer: drawingBuffer.fromString(req.query.drawingbuffer),
requestTime: req.query.time,
intersect: JSON.parse(req.query.intersect.toLowerCase())
requestTime: req.query.time
};
}
......
......@@ -61,6 +61,7 @@ class GeographicBoundingBox {
}
const fromString = (str) => {
if(!str) return null;
let tokens = str.split(",");
return new GeographicBoundingBox(...tokens.map(token => parseFloat(token)));
}
......
......@@ -3,7 +3,7 @@ const Traverse = require("./traverse");
const getSceneHandler = (req, res) => {
assets.getIntersecting(req.query.boundingbox).then(layers => {
assets.getLayers(req.query.layers).then(layers => {
let traverse = new Traverse();
traverse.begin(req, layers[0].url)
......
const config = require("../config");
class Nodes {
constructor() {
......@@ -21,9 +23,9 @@ class Nodes {
time: context.requestTime
};
if (context.intersect) {
if (context.bb != null) {
let requestedBB = context.bb.clone();
requestedBB.extend(25);
requestedBB.extend(config.boundingBoxBufferPercent);
if (requestedBB.intersectWithGeographic(boundingSphere.geographicCenter)) {
this.nodes.push(entry);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment