From 55319a54e9e1e94dc06f3f96bc3e37726f43586f Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Thu, 19 Dec 2019 02:12:23 +0100 Subject: [PATCH] WIP Idea to implement bound map to be equal to selected --- app/controllers/location.js | 21 ++++++++++++++++++++- app/views/location.ejs | 33 ++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/app/controllers/location.js b/app/controllers/location.js index afbf43f..77ad699 100644 --- a/app/controllers/location.js +++ b/app/controllers/location.js @@ -4,9 +4,28 @@ const getLocation = async (req, res) => { const title = "Odaberite lokaciju"; const nextStep = req.query.nextStep || "/"; + //Check if location data already exists + //If it does then get location is called through edit field query + //and map should show already selected location not initial map + let selectedLatLngBounds = 0; + + 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 = [sw, ne]; + } + res.render("location", { nextStep, - title + title, + selectedLatLngBounds }); }; diff --git a/app/views/location.ejs b/app/views/location.ejs index 01a25ef..dc587cb 100644 --- a/app/views/location.ejs +++ b/app/views/location.ejs @@ -1,13 +1,17 @@

- Područje na mapi će biti uključeno u pretragu. Namjestite mapu na ulice - koje želite da budu vidljive. + Područje na mapi će biti uključeno u pretragu. Namjestite mapu na ulice koje + želite da budu vidljive.

- +
@@ -17,12 +21,17 @@ -
+
- Dalje + Dalje
@@ -87,6 +96,13 @@ }; map = new google.maps.Map(mapElement, initialMapParams); + //After map initialization we check if area is already selected + //If yes we bound map to show selected area + console.log(<%= selectedLatLngBounds[0] %>); + if (<%= selectedLatLngBounds %>) { + map.fitBounds(<%= selectedLatLngBounds %>); + } + const inputElement = document.getElementById('autocompleteInput'); const restrictAutocompleteResultsToBosniaOnly = {'country': 'ba'}; const initialAutocompleteParams = { @@ -177,5 +193,8 @@ }); }); - +