Skip to content

Commit

Permalink
next release
Browse files Browse the repository at this point in the history
  • Loading branch information
mAzurkovic committed Jan 11, 2018
1 parent a256ac0 commit 0f95139
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 211 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function getCoords(address) {
});
}

// in development, make sure the port is set to 5000
// for production, set port to 3000
app.listen(3000, function () {
console.log('Example app listening on port !');
});
Expand Down
File renamed without changes.
60 changes: 0 additions & 60 deletions public/javascripts/googleMaps.js

This file was deleted.

132 changes: 132 additions & 0 deletions public/javascripts/mainMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

function initMap() {
latLng = new google.maps.LatLng(49, 123)

map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 12,
gestureHandling: 'cooperative',
disableDefaultUI: true,
styles: [{"featureType":"water","elementType":"geometry","stylers":[{"color":"#004358"}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#1f8a70"}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#1f8a70"}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"color":"#fd7400"}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#1f8a70"},{"lightness":-20}]},{"featureType":"road.local","elementType":"geometry","stylers":[{"color":"#1f8a70"},{"lightness":-17}]},{"elementType":"labels.text.stroke","stylers":[{"color":"#ffffff"},{"visibility":"on"},{"weight":0.9}]},{"elementType":"labels.text.fill","stylers":[{"visibility":"on"},{"color":"#ffffff"}]},{"featureType":"poi","elementType":"labels","stylers":[{"visibility":"simplified"}]},{"elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"geometry","stylers":[{"color":"#1f8a70"},{"lightness":-10}]},{},{"featureType":"administrative","elementType":"geometry","stylers":[{"color":"#1f8a70"},{"weight":0.7}]}]
});
infoWindow = new google.maps.InfoWindow;

// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};

map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}

/* map.addListener('click', function(e) {
placeMarkerAndPanTo(e.latLng, map);
}); */

for (var i = 0; i < spots.length; i++) { // loop through all the locations and render a marker
var outlet = "No";
var date = (spots[i].date).toString().substring(0, 10);
if (spots[i].isOutlet) { outlet = "Yes"; }

if (spots[i].name == null) {
addMarker(spots[i].coords, spots[i].address, spots[i]._id, spots[i].points, spots[i].type, spots[i].goodFor, outlet, date);
} else {
addMarker(spots[i].coords, spots[i].name, spots[i]._id, spots[i].points, spots[i].type, spots[i].goodFor, outlet, date);

}
}

}

function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
infoWindow.open(map);
}

// adds a marker on map when user clicks on a place on the map
function placeMarkerAndPanTo(latLng, map) {
var marker = new google.maps.Marker({
position: latLng,
map: map
});
map.panTo(latLng);
}

// adds a marker as well as an info box containing the rating of the spot
function addMarker(coords, address, id, points, type, goodFor, hasOutlet, date) {
var upvote = "/upvote/" + id;
// string that is used to render the html in the info box
var contentString2 = '<div id="content" class="info"><div class="row"><div class="col s1.5"><br>' +
'<form action="/upvote/'+ id +'" method="POST">'+
'<input class="vote-button up" type="submit" name="upvote" value="↑"/></form><b style="padding-left: 10px;">'+ points +
'</b><form action="/downvote/'+ id +'" method="POST">'+
'<input class="vote-button down" type="submit" name="downvote" value="↓"/>'+
'</form></div>' + '<div class="col s10.5" id="text"><br><b>' + address + '</b><ul><li>This spot is good for <b>' + goodFor + '</b> and is a <b>' + type + '</b>.</li><li> <div>Are you able to charge packs here: <b>' + hasOutlet +
'</b></li></ul></div></div><div class="divider"></div></div></div></div>'+
'</div><br></div><div class="right-align"> Spot added on ' + date + '</div></div>' ;

var infowindow = new google.maps.InfoWindow({
content: contentString2
});

var icon = {
url: "https://i.imgur.com/2b7gHaQ.png", // url
scaledSize: new google.maps.Size(50, 50)
};

var marker = new google.maps.Marker({
position: coords,
map: map,
type: type,
goodFor: goodFor
});

allMarkers.push(marker);

marker.addListener('click', function() {
infowindow.open(map, marker);
});

}

function filterMarkersStyle(goodFor) {
console.log(goodFor);
for (i = 0; i < spots.length; i++) {
marker = allMarkers[i];
// If is same category or category not picked
if (marker.goodFor == goodFor || goodFor.length === 0) {
marker.setVisible(true);
}
// Categories don't match
else {
marker.setVisible(false);
}
}
}

function filterMarkersType(type) {
console.log(type);
for (i = 0; i < spots.length; i++) {
marker = allMarkers[i];
// If is same category or category not picked
if (marker.type == type || type.length === 0) {
marker.setVisible(true);
}
// Categories don't match
else {
marker.setVisible(false);
}
}
}
4 changes: 2 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ router.get('/', function(req, res) {
});

// add by entering an address
router.post('/add', function(req, res) {
router.post('/add-by-address', function(req, res) {
var location = req.body.address + ", " + req.body.city;
var hasOutlet = false;
console.log(location);

if (req.body.yes == "on") { hasOutlet = true; }
if (req.body.outletButton == "yes") { hasOutlet = true; }

geocoder.geocode(location, function(err, data) {

Expand Down
20 changes: 9 additions & 11 deletions views/add.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div>
<div class="col s12">
<ul class="tabs row deep-purple darken-1">
<li class="tab col s6" id="map-tab"><a class="active white-text" href="#test2">Add by clicking on map</a></li>
<li class="tab col s6" id="address-tab"><a class="white-text" href="#test3">Add by address</a></li>
</ul>
<ul class="tabs row deep-purple darken-1">
<li class="tab col s6" id="map-tab"><a class="active white-text" href="#test2">Add by clicking on map</a></li>
<li class="tab col s6" id="address-tab"><a class="white-text" href="#test3">Add by address</a></li>
</ul>
</div>
<div id="test2" class="col s12">
<div id="add-map"></div>
Expand Down Expand Up @@ -61,7 +61,7 @@

<div style="padding-left: 10px;">
<input type="radio" id="under_13" name="outletButton" value="yes" required> <label for="under_13" class="light">Yes</label><br>
<input type="radio" id="over_13" name="outletButton" value="no" required> <label for="over_13" class="light">No</label>
<input type="radio" id="over_13" name="outletButton" value="no" required> <label for="over_13" class="light">No</label>

</div>

Expand Down Expand Up @@ -96,7 +96,7 @@
<p>Make sure to know the address of your spot, and then fill out the following information.</p>
<div class="divider"></div>
<div class="row">
<form class="col s12" action="/add-by-click" method="POST" onsubmit="return checkform(this)">
<form class="col s12" action="/add-by-address" method="POST" onsubmit="return checkform(this)">
<div class="row">
<div class="input-field col s6">
<input id="address" type="text" name="address" class="validate" required>
Expand Down Expand Up @@ -134,8 +134,8 @@
<p class="col s12">Does the spot have an outlet? </p>

<div style="padding-left: 10px;">
<input type="radio" id="under_134" name="outletButton" value="yes" required> <label for="under_134" class="light">Yes</label><br>
<input type="radio" id="over_134" name="outletButton" value="no" required> <label for="over_134" class="light">No</label>
<input type="radio" id="under_134" name="outletButton" value="yes" required> <label for="under_134" class="light">Yes</label><br>
<input type="radio" id="over_134" name="outletButton" value="no" required> <label for="over_134" class="light">No</label>

</div>

Expand All @@ -160,6 +160,4 @@

</div>
</div>


<script type="text/javascript" src="/javascripts/extra.js"></script>
<script type="text/javascript" src="/javascripts/clickMap.js"></script>
Loading

0 comments on commit 0f95139

Please sign in to comment.