diff --git a/app/controllers/location.js b/app/controllers/location.js index afbf43f..214fcbf 100644 --- a/app/controllers/location.js +++ b/app/controllers/location.js @@ -4,9 +4,37 @@ const getLocation = async (req, res) => { const title = "Odaberite lokaciju"; const nextStep = req.query.nextStep || "/"; + //Check if location data already exists (active request) + //If it does then get location is called through edit field query + //and map should show already selected location not initial map + let selectedLatLngBounds = {}; + let boundsSelected = false; + + const searchRequest = await currentSearchRequest(req); + + if (!searchRequest || !searchRequest.dataValues) { + res.render("notFound", { title: " " }); + return; + } + const selectedArea = searchRequest.areaToSearch; + const sw = selectedArea.coordinates[0][3]; + const ne = selectedArea.coordinates[0][1]; + + if (sw[0] && ne[0]) { + selectedLatLngBounds = { + swLat: sw[1], + swLng: sw[0], + neLat: ne[1], + neLng: ne[0] + }; + boundsSelected = true; + } + res.render("location", { nextStep, - title + title, + boundsSelected, + selectedLatLngBounds }); }; diff --git a/app/views/location.ejs b/app/views/location.ejs index 01a25ef..8e30feb 100644 --- a/app/views/location.ejs +++ b/app/views/location.ejs @@ -1,13 +1,17 @@