From ac3e9c7b544b5cedd74963f11c71b12030e7e1a7 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Tue, 13 Dec 2016 15:57:33 -0500 Subject: [PATCH] Working on making sure that all functions work for the NearMe map Fixed not pushing map postion when going to all area search Fixed when poi processing is delayed and not delayed. --- views/front/nearme/index.html | 93 +++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 31 deletions(-) diff --git a/views/front/nearme/index.html b/views/front/nearme/index.html index a296762..c66a20d 100644 --- a/views/front/nearme/index.html +++ b/views/front/nearme/index.html @@ -75,7 +75,7 @@ var highAccuracyPoisition = false; // Request high-accuracy user geolocation from user's device var postionTimeout = 15000; // Maximum amount of time we'll wait for geolocation result - 15 Sec var geolocationFailCount = 2; // Allow geolocation to fail this many times before switching to manual location settings ('set') - var trackToConsole = false; // Send debug/progress messages to developers console (Firefox) + var trackToConsole = true; // Send debug/progress messages to developers console (Firefox) // Set default - Need to make this configurable var mapLocation = new google.maps.LatLng(mapLat, mapLon); @@ -125,6 +125,7 @@ var getLocationIngoredTimer; var geolocationFailCounter = 0; var stopGeolocation = false; + var noProcessAfterZoom = false; function initMap() { @@ -245,37 +246,43 @@ // Close map bubble if used closeMapBubble(); - checkNewPOIs(); + // Check if we need to get new POIs after this zoom - Dissabled for "everywhere" search + if (!noProcessAfterZoom) { + checkNewPOIs(); + } else { + if (trackToConsole) { console.log('GLM NearMe: Not calling checkNewPOIs() for this zoom'); } + noProcessAfterZoom = false; + } + }); } - // Watch for Reference Map Position request by user + // Return to My Location $('#glmMapGoToMyLocation').on('click', function() { if (trackToConsole) { console.log('GLM NearMe: User GoToMyLocation clicked'); } - goToPosition(myMarker.getPosition()); - return false; - }); - - function goToPosition(position) { - map.setCenter(position); + noProcessAfterZoom = true; + + // Go to the user's saved postion and default zoom + map.setCenter(myMarker.getPosition()); map.setZoom(defZoom) - checkNewPOIs(); - } - + + // Clear all POIs and run check for new ones. + checkNewPOIs(boundsTimeout, true); + + }); - // Watch for request to set My Selected Location to center of map + // Set My Selected Location to center of map $('#glmMapSetMyLocation').on('click', function() { if (trackToConsole) { console.log('GLM NearMe: User SetMyLocation clicked'); } myMarker.setPosition(map.getCenter()); - return false; }); - // Watch for Previous Map Position request by user + // Previous Map Position request by user $('#glmMapBack').on('click', function() { if (trackToConsole) { console.log('GLM NearMe: User MapBack clicked'); } @@ -309,18 +316,21 @@ return false; }); - // Redo search when Search Anywhere button is clicked. + // Search Anywhere button is clicked. $('#glmNearMeSearchAnywhere').click('change', function() { + + // Using getBoundsPOIs here because it's awkward to wait when a button is clicked getBoundsPOIs(true, true); + }); - // Trigger text search for POIs when search text is changed + // Text search requested $('#glmNearMeSearchText').catchEnter().on('enterkey', function() { - getBoundsPOIs(true); + checkNewPOIs(boundsTimeout, true); }); // Schedule a check for new POIs - function checkNewPOIs(timeout = boundsTimeout) { + function checkNewPOIs(timeout = boundsTimeout, resetPOIs = false, anywhere = false) { if (trackToConsole) { console.log('GLM NearMe: checkNewPOIs()'); } @@ -328,7 +338,7 @@ window.clearTimeout(boundsDelayTimer); // Set timer to get POIs - boundsDelayTimer = window.setTimeout(getBoundsPOIs, timeout); + boundsDelayTimer = window.setTimeout(getBoundsPOIs, timeout, resetPOIs, anywhere); } @@ -354,8 +364,6 @@ setMyLocationToManual(); } - // Then turn off checked - $('#glmNearMeSearchAnywhere').attr("checked", false); } @@ -392,6 +400,8 @@ dontPushPos = false; } else { + if (trackToConsole) { console.log('GLM NearMe: Pushing location on stack'); } + // Push the previous position on the stack mapViewStack.push({ zoom: curZoom, @@ -401,8 +411,6 @@ // Show the back button $('#glmMapBack').removeClass('glm-hidden'); - // Clear the don't push on stack flag - dontPushPos = false; } // Request any POIs in new areas of the map @@ -412,7 +420,9 @@ function( newPOIs ) { if (trackToConsole) { console.log('GLM NearMe: Requesting newPOIs'); } - + + if (trackToConsole) { console.log('GLM NearMe: Number of markers = '+Object.keys(markers).length); } + // If resetPOIs is requested, clear all clusterer markers, all map markers, and our own markers array. if (resetPOIs) { @@ -423,6 +433,7 @@ markers = []; // markerClusterer.redraw(); + if (trackToConsole) { console.log('GLM NearMe: Clearing all markers.'); } // Otherwise remove only markers that are off our map } else { @@ -440,9 +451,10 @@ } - if (trackToConsole) { console.log('GLM NearMe: '+Object.keys(delQueue).length+' markers in delete queue'); } + if (trackToConsole) { console.log('GLM NearMe: Markers in delete queue = '+Object.keys(delQueue).length); } // Remove markers in the delete queue from the clusterer and markers array - can't do this in loop above + var deleted = 0; if (Object.keys(delQueue).length) { $.each( delQueue, function(key, value) { @@ -455,12 +467,19 @@ // Delete our marker delete markers[value]; + deleted++; + }); } delQueue = []; // Clear delete queue + + if (trackToConsole) { console.log('GLM NearMe: Number of markers deleted = '+deleted); } } +if (trackToConsole) { console.log('GLM NearMe: Number of markers remaining = '+Object.keys(markers).length); } + + if (trackToConsole) { console.log('GLM NearMe: Processing '+Object.keys(newPOIs.sources).length+' POI sources'); } // Add all sources (members, events, ...) to the assignedPushPins array @@ -645,6 +664,8 @@ // If there's a request to find things anywhere if (request == 'anywhere' && Object.keys(markers).length) { + noProcessAfterZoom = true; + allBounds = new google.maps.LatLngBounds(); // Find the total extent of all current markers. @@ -659,7 +680,8 @@ if (zoom > maxAnywhereZoom) { map.setZoom(maxAnywhereZoom); } - + + saveCurrentBounds(); } @@ -669,18 +691,27 @@ } ); - // Save current bounds as last bounds + saveCurrentBounds(); + + } + + // Save current bounds as last bounds + function saveCurrentBounds() { + + if (trackToConsole) { console.log('GLM NearMe: Set Last Bounds'); } + lastLatMax = latMax; lastLatMin = latMin; lastLonMax = lonMax; lastLonMin = lonMin; - // Save the current center position and zoom to push on stack before next move + // Save the current center position and save to push on stack before next move curZoom = map.getZoom(); curCenter = map.getCenter(); } - + + // Handle tracking type selection $('.glmMapMyLocationType').on('change', function() { @@ -755,7 +786,7 @@ // If current location is not on map, recenter map on location if (!map.getBounds().contains(myMarker.getPosition())) { map.setCenter(myCurrentLocation); - getBoundsPOIs(); + checkNewPOIs(); } // If we can't get the location, then switch to manual -- 2.17.1