diff --git a/pdt-marinehelper-client/src/app/components/Map.js b/pdt-marinehelper-client/src/app/components/Map.js index b6122a53..6075623c 100644 --- a/pdt-marinehelper-client/src/app/components/Map.js +++ b/pdt-marinehelper-client/src/app/components/Map.js @@ -51,7 +51,8 @@ const geojson = { export const Map = createReactClass({ propTypes: { - geoJson: PropTypes.object + geoJson: PropTypes.object, + onClick: PropTypes.func }, render() { @@ -68,9 +69,10 @@ export const Map = createReactClass({ }} onClick={(map, evt) => { console.log(evt); + this.props.onClick(evt); }} onMouseMove={(map, evt) => { - console.log(evt); + //console.log(evt); }} > diff --git a/pdt-marinehelper-client/src/app/components/Scenario.js b/pdt-marinehelper-client/src/app/components/Scenario.js index 92933871..8cfe983c 100644 --- a/pdt-marinehelper-client/src/app/components/Scenario.js +++ b/pdt-marinehelper-client/src/app/components/Scenario.js @@ -5,16 +5,26 @@ import axios from "axios"; import "./Scenario.css"; import { Map } from "./Map"; -import { Grid, Col, Row} from "react-bootstrap"; +import { Grid, Col, Row } from "react-bootstrap"; import { PageHeader, Checkbox } from "react-bootstrap"; -import { Form, FormGroup, ControlLabel, FormControl, Button, InputGroup } from "react-bootstrap"; +import { + Form, + FormGroup, + ControlLabel, + FormControl, + Button, + InputGroup +} from "react-bootstrap"; export const Scenario = createReactClass({ getInitialState() { let scenario = this._getScenario(); return { scenario, - open: false + open: false, + activated: null, + startPosition: {}, + endPosition: {} }; }, @@ -46,7 +56,25 @@ export const Scenario = createReactClass({ return parsedUrl.searchParams.get("scenario"); }, + _handleMapClick(evt) { + if (this.state.activated !== null) { + if (this.state.activated === 1) { + this.setState({ + startPosition: evt.lngLat, + activated: null + }); + } + if (this.state.activated === 2) { + this.setState({ + endPosition: evt.lngLat, + activated: null + }); + } + } + }, + render() { + console.log(this.state.startPosition, this.state.endPosition); let controls = null; const scenario = this.state.scenario; switch (scenario) { @@ -59,109 +87,83 @@ export const Scenario = createReactClass({ {"Harbours"} - - {"Toilets"} - - - {"Showers"} - - - {"Electricity"} - - - {"Fuel station"} - - - {"Chandler"} - - - {"Laundrette"} - - - {"Boatyard"} - - - {"Slipway"} - - - {"Boat hoist"} - - - {"Visitor berth"} - + {"Toilets"} + {"Showers"} + {"Electricity"} + {"Fuel station"} + {"Chandler"} + {"Laundrette"} + {"Boatyard"} + {"Slipway"} + {"Boat hoist"} + {"Visitor berth"} ); break; - case "dangers": + case "dangers": controls = (
- - - - {"Dangers"} - - -

{"Select line of your cruise"}

-
- - 1 - - - - - - - - - 2 - - - - - - - -
-
- -

{"Choose dangers to show"}

- - {"Isolated dangers"} - - - {"Beacons"} - - - {"Rocks"} - - - {"Buoys"} - - - {"Wrecks"} - - - {"Cardinal signs"} - - - {"Special purpose signs"} - - - {"Lights"} - - - {"Coast lines"} - -
- -
-
+ + + + {"Dangers"} + + +

{"Select line of your cruise"}

+
+ + 1 + + + + + + + + + 2 + + + + + + + +
+
+ +

{"Choose dangers to show"}

+ {"Isolated dangers"} + {"Beacons"} + {"Rocks"} + {"Buoys"} + {"Wrecks"} + {"Cardinal signs"} + {"Special purpose signs"} + {"Lights"} + {"Coast lines"} +
+ +
+ ); break; - case "coves": + case "coves": controls = (
@@ -170,18 +172,10 @@ export const Scenario = createReactClass({ {"Coves"} - - {"Anchorages"} - - - {"Moorings"} - - - {"Show underwater cables/pipes"} - - - {"Show restricted areas"} - + {"Anchorages"} + {"Moorings"} + {"Show underwater cables/pipes"} + {"Show restricted areas"} @@ -195,7 +189,7 @@ export const Scenario = createReactClass({
{controls} - +
); } diff --git a/pdt-marinehelper-server/api/controllers/covesController.js b/pdt-marinehelper-server/api/controllers/covesController.js new file mode 100644 index 00000000..13814401 --- /dev/null +++ b/pdt-marinehelper-server/api/controllers/covesController.js @@ -0,0 +1,94 @@ +const db = require("../../db"); + +exports.getAllAnchorages = (req, res, next) => { + const SELECT_ANCHORAGES_QUERY = + 'SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", ST_AsGeoJSON(ST_Transform(way, 4326)) AS geojson ' + + "FROM planet_osm_point " + + "WHERE \"seamark:type\" = 'anchorage'"; + + db.query(SELECT_ANCHORAGES_QUERY, [], (err, res1) => { + if (err) { + return next(err); + } + + const result = res1.rows.map(row => { + const geojson = JSON.parse(row.geojson); + return { ...row, geojson }; + }); + + res.status(200).json({ + message: "anchorages fetched", + result: result, + error: err + }); + }); +}; + +exports.getAllMoorings = (req, res, next) => { + const SELECT_MOORINGS_QUERY = + 'SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as geojson ' + + "FROM planet_osm_point " + + "WHERE \"seamark:type\" = 'mooring'"; + + db.query(SELECT_MOORINGS_QUERY, [], (err, res1) => { + if (err) { + return next(err); + } + + const result = res1.rows.map(row => { + const geojson = JSON.parse(row.geojson); + return { ...row, geojson }; + }); + + res.status(200).json({ + message: "moorings fetched", + result: result, + error: err + }); + }); +}; + +exports.getAllRestrictedAreas = (req, res, next) => { + const SELECT_RESTRICTED_AREAS_QUERY = ""; + + db.query(SELECT_RESTRICTED_AREAS_QUERY, [], (err, res1) => { + if (err) { + return next(err); + } + + const result = res1.rows.map(row => { + const geojson = JSON.parse(row.geojson); + return { ...row, geojson }; + }); + + res.status(200).json({ + message: "restricted areas fetched", + result: result, + error: err + }); + }); +}; + +exports.getAllUnderwaterCablesAndPipes = (req, res, next) => { + const SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY = + 'SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as geojson ' + + "FROM planet_osm_line " + + "WHERE \"seamark:type\" = 'pipeline_submarine' OR \"seamark:type\" = 'cable_submarine'"; + + db.query(SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY, [], (err, res1) => { + if (err) { + return next(err); + } + + const result = res1.rows.map(row => { + const geojson = JSON.parse(row.geojson); + return { ...row, geojson }; + }); + + res.status(200).json({ + message: "underwater cables and pipes fetched", + result: result, + error: err + }); + }); +}; diff --git a/pdt-marinehelper-server/api/controllers/dangersController.js b/pdt-marinehelper-server/api/controllers/dangersController.js new file mode 100644 index 00000000..4e79af5a --- /dev/null +++ b/pdt-marinehelper-server/api/controllers/dangersController.js @@ -0,0 +1,34 @@ +const db = require("../../db"); + +exports.getDangers = (req, res, next) => { + const queryParams = { + lineString: req.body.lineString, + isolatedDangers: req.body.isolatedDangers, + beacons: req.body.beacons, + rocks: req.body.rocks, + buoys: req.body.buoys, + wrecks: req.body.wrecks, + cardinalSigns: req.body.cardinalSigns, + specialPurposeSigns: req.body.specialPurposeSigns, + lights: req.body.lights, + coastLines: req.body.coastLines + }; + let SELECT_DANGERS_QUERY = ""; + + db.query(SELECT_DANGERS_QUERY, [], (err, res1) => { + if (err) { + return next(err); + } + + const result = res1.rows.map(row => { + const geojson = JSON.parse(row.geojson); + return { ...row, geojson }; + }); + + res.status(200).json({ + message: "dangers fetched", + result: result, + error: err + }); + }); +}; diff --git a/pdt-marinehelper-server/api/controllers/harboursController.js b/pdt-marinehelper-server/api/controllers/harboursController.js index 85530b56..e4e4dea9 100644 --- a/pdt-marinehelper-server/api/controllers/harboursController.js +++ b/pdt-marinehelper-server/api/controllers/harboursController.js @@ -2,53 +2,56 @@ const db = require("../../db"); exports.getOne = (req, res, next) => { const { id } = req.query; - const SELECT_HARBOUR_QUERY = 'select "seamark:type", "seamark:harbour:category", ST_AsGeoJSON(ST_Transform(way, 4326)) as way ' + - "from planet_osm_polygon " + - "where \"seamark:type\" = 'harbour' and osm_id = $1"; - - db.query( - SELECT_HARBOUR_QUERY, - [id], - (err, res1) => { - if (err) { - return next(err); - } - - const result = res1.rows.map(row => { - const way = JSON.parse(row.way); - return { ...row, way }; - }); - - res.status(200).json({ - message: "harbour fetched", - result: result, - error: err - }); + const SELECT_HARBOUR_QUERY = + 'select "seamark:type", "seamark:harbour:category", ST_AsGeoJSON(ST_Transform(way, 4326)) as geojson ' + + "from planet_osm_polygon " + + "where \"seamark:type\" = 'harbour' and osm_id = $1"; + + db.query(SELECT_HARBOUR_QUERY, [id], (err, res1) => { + if (err) { + return next(err); } - ); + + const result = res1.rows.map(row => { + const geojson = JSON.parse(row.geojson); + return { ...row, geojson }; + }); + + res.status(200).json({ + message: "harbour fetched", + result: result, + error: err + }); + }); }; exports.getAll = (req, res, next) => { - db.query( - 'select "seamark:type", "seamark:harbour:category", ST_AsGeoJSON(ST_Transform(way, 4326)) as way ' + - "from planet_osm_polygon " + - "where \"seamark:type\" = 'harbour'", - [], - (err, res1) => { - if (err) { - return next(err); - } - - const result = res1.rows.map(row => { - const way = JSON.parse(row.way); - return { ...row, way }; - }); - - res.status(200).json({ - message: "harbours fetched", - result: result, - error: err - }); + const SELECT_HARBOURS_QUERY = + "WITH harbours AS (" + + 'SELECT "osm_id", "seamark:type", "seamark:name", "seamark:harbour:category", "name", ST_AsGeoJSON(ST_Centroid(ST_Transform(way, 4326))) as geojson ' + + "FROM planet_osm_polygon " + + "WHERE \"seamark:type\" = 'harbour' " + + "UNION " + + 'SELECT "osm_id", "seamark:type", "seamark:name", "seamark:harbour:category", "name", ST_AsGeoJSON(ST_Transform(way, 4326)) as geojson ' + + "FROM planet_osm_point " + + "WHERE \"seamark:type\" = 'harbour' " + + ") " + + "SELECT * FROM harbours"; + + db.query(SELECT_HARBOURS_QUERY, [], (err, res1) => { + if (err) { + return next(err); } - ); + + const result = res1.rows.map(row => { + const geojson = JSON.parse(row.geojson); + return { ...row, geojson }; + }); + + res.status(200).json({ + message: "harbours fetched", + result: result, + error: err + }); + }); }; diff --git a/pdt-marinehelper-server/api/controllers/productsController.js b/pdt-marinehelper-server/api/controllers/productsController.js deleted file mode 100644 index 9ee4fb47..00000000 --- a/pdt-marinehelper-server/api/controllers/productsController.js +++ /dev/null @@ -1,47 +0,0 @@ -exports.getAll = (req, res, next) => { - res.status(200).json({ - message: "handling get requess to products" - }); -}; - -exports.insertOne = (req, res, next) => { - const product = { - name: req.body.name, - price: req.body.price - }; - res.status(201).json({ - message: "handling post requess to products", - createdProduct: product - }); -}; - -exports.getOne = (req, res, next) => { - const id = req.params.productId; - if (id === "special") { - res.status(200).json({ - message: "special id", - id: id - }); - } else { - res.status(200).json({ - message: "id", - id: id - }); - } -}; - -exports.updateOne = (req, res, next) => { - const id = req.params.productId; - res.status(200).json({ - message: "update product id", - id: id - }); -}; - -exports.deleteOne = (req, res, next) => { - const id = req.params.productId; - res.status(200).json({ - message: "delete product id", - id: id - }); -}; diff --git a/pdt-marinehelper-server/api/routes/coves.js b/pdt-marinehelper-server/api/routes/coves.js new file mode 100644 index 00000000..5c161da5 --- /dev/null +++ b/pdt-marinehelper-server/api/routes/coves.js @@ -0,0 +1,13 @@ +const express = require("express"); +const router = express.Router(); +const covesController = require("../controllers/covesController"); + +router.route("/getAllAnchorages").get(covesController.getAllAnchorages); + +router.route("/getAllMoorings").get(covesController.getAllMoorings); + +router.route("/getAllRestrictedAreas").get(covesController.getAllRestrictedAreas); + +router.route("/getAllUnderwaterCablesAndPipes").get(covesController.getAllUnderwaterCablesAndPipes); + +module.exports = router; diff --git a/pdt-marinehelper-server/api/routes/dangers.js b/pdt-marinehelper-server/api/routes/dangers.js new file mode 100644 index 00000000..ef38d1f7 --- /dev/null +++ b/pdt-marinehelper-server/api/routes/dangers.js @@ -0,0 +1,7 @@ +const express = require("express"); +const router = express.Router(); +const dangersController = require("../controllers/dangersController"); + +router.route("/getDangers").post(dangersController.getDangers); + +module.exports = router; diff --git a/pdt-marinehelper-server/api/routes/products.js b/pdt-marinehelper-server/api/routes/products.js deleted file mode 100644 index 7c610265..00000000 --- a/pdt-marinehelper-server/api/routes/products.js +++ /dev/null @@ -1,15 +0,0 @@ -const express = require("express"); -const router = express.Router(); -const productsController = require("../controllers/productsController"); - -router.route("/").get(productsController.getAll); - -router.route("/").post(productsController.insertOne); - -router.route("/:productId").get(productsController.getOne); - -router.route("/:productId").patch(productsController.updateOne); - -router.route("/:productId").delete(productsController.deleteOne); - -module.exports = router; diff --git a/pdt-marinehelper-server/app.js b/pdt-marinehelper-server/app.js index 1cf013c0..16894a01 100644 --- a/pdt-marinehelper-server/app.js +++ b/pdt-marinehelper-server/app.js @@ -3,9 +3,9 @@ const app = express(); const morgan = require("morgan"); const bodyParser = require("body-parser"); -const productRoutes = require("./api/routes/products"); -const orderRoutes = require("./api/routes/orders"); const harbourRoutes = require("./api/routes/harbours"); +const coveRoutes = require("./api/routes/coves"); +const dangerRoutes = require("./api/routes/dangers"); app.use(morgan("dev")); app.use(bodyParser.urlencoded({ extended: false })); @@ -24,9 +24,9 @@ app.use((req, res, next) => { next(); }); -app.use("/products", productRoutes); -app.use("/orders", orderRoutes); app.use("/harbours", harbourRoutes); +app.use("/coves", coveRoutes); +app.use("/dangers", dangerRoutes); app.use((req, res, next) => { const error = new Error("not found");