Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 52 additions & 33 deletions projectV7.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
$(function () {
let circles = [];
let bounds;
resetMapBounds();

console.log('Get funky'); // Document Ready

const ADZUNA_BASE_URL = 'https://api.adzuna.com/v1/api/';
Expand All @@ -26,9 +28,22 @@ $(function () {
.catch(err => console.error(err));
}

function resetSearchResults(){
resetMapBounds();
removeCirclesFromMap();
// also reset form things, titles, images, data, means, etc.
}

function tryAllCities(country1, city1, country2, city2, jobCategory){

let numExpected = 2;

getLocAndJobForCity(country1, city1, jobCategory)
.then(city1results => {
if( numExpected == 2 ){
resetSearchResults();
}
numExpected--;
displayResults(city1results);
})
.catch( city1error => {
Expand All @@ -39,6 +54,10 @@ $(function () {
// --- not dependent on each other
getLocAndJobForCity(country2, city2, jobCategory)
.then(city2results => {
if( numExpected == 2 ){
resetSearchResults();
}
numExpected--;
displayResults(city2results);
})
.catch( city2error => {
Expand Down Expand Up @@ -130,52 +149,47 @@ $(function () {

}

function fixBounds(minimizedBoundsObject){
let cityBounds = {};
cityBounds.sw = minimizedBoundsObject.ga;
cityBounds.sw.lat = minimizedBoundsObject.ga.j;
cityBounds.sw.lng = minimizedBoundsObject.ga.l;
cityBounds.ne = minimizedBoundsObject.na;
cityBounds.ne.lat = minimizedBoundsObject.na.j;
cityBounds.ne.lng = minimizedBoundsObject.na.l;
delete cityBounds.ga;
delete cityBounds.na;
delete cityBounds.ne.l;
delete cityBounds.ne.j;
delete cityBounds.sw.l;
delete cityBounds.sw.j;
return new google.maps.LatLngBounds(cityBounds);
}

// GOOD ABSTRACTION, inside which has frustrating bullshit we want to ignore for now
function addCityToMapBounds(cityBounds){
return ; // not working yet
console.log('city bounds before conversion', cityBounds);

cityBounds = new google.maps.LatLngBounds([
new google.maps.LatLng(cityBounds.southwest.lat, cityBounds.southwest.lng),
new google.maps.LatLng(cityBounds.northeast.lat, cityBounds.northeast.lng)
]);

console.log('display results for city bounds:', cityBounds);
if( isNaN(bounds.north) || cityBounds.northeast.lat > bounds.north ){
// set incoming cityBounds as global bounds true north
bounds.north = cityBounds.northeast.lat;
}

if( isNaN(bounds.south) || cityBounds.southwest.lat < bounds.south ){
// set incoming cityBounds as global bounds true south
bounds.south = cityBounds.southwest.lat;
}

// add location to bounds
if( bounds ){
bounds.extend( cityBounds.southwest );
bounds.extend( cityBounds.northeast );
} else {
bounds = cityBounds;
if( isNaN(bounds.east) || cityBounds.northeast.lng > bounds.east ){
// set incoming cityBounds as global bounds true east
bounds.east = cityBounds.northeast.lng;
}

if( isNaN(bounds.west) || cityBounds.southwest.lat < bounds.west ){
// set incoming cityBounds as global bounds true west
bounds.west = cityBounds.southwest.lng;
}

}



function zoomToMapBounds(){
// center map on the global bounds
// map.fitBounds(bounds); // not working cause bounds suck
console.log("Asking google to center map on bounds: ", JSON.stringify(bounds) )
// wait until this point to make an actual google lat lng bounds object
map.fitBounds(bounds); // not working cause bounds suck
}

function resetMapBounds(){
bounds = { north: NaN, east: NaN, south: NaN, west: NaN };
}

// Displays results in HTML for ONE city
function displayResults(data) {

// put circle on map and track it
let newCircle = addCircleToMap(data);
circles.push(newCircle);
Expand Down Expand Up @@ -424,6 +438,11 @@ $(function () {
}
}

function removeCirclesFromMap(){
circles.forEach( circle => circle.setMap(null) );
circles.length = 0;
}

// Submit Button
function submitHandler() {

Expand Down Expand Up @@ -468,7 +487,7 @@ $(function () {

// Initializes Map
function initMap() {
bounds = new google.maps.LatLngBounds();
// bounds = new google.maps.LatLngBounds();
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: 37.77439, lng: -122.419416 },
zoom: 9,
Expand Down