From 1035d4b8fdda427e12d7959bdabd9ed8866e3ab2 Mon Sep 17 00:00:00 2001 From: Mark Carter Date: Sat, 10 Oct 2015 20:32:01 -0400 Subject: [PATCH 1/6] added locate() and onUserLocated() --- js/busfinder.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/js/busfinder.js b/js/busfinder.js index d0eab07..ea35e56 100644 --- a/js/busfinder.js +++ b/js/busfinder.js @@ -608,9 +608,19 @@ $(function(){ this.$('.mapcanvas').show(); App.MapView.resize(); + //this.locate(); + return this; }, + locate: function() { + LocateUser($.proxy(this.onUserLocated, this)); + }, + + onUserLocated: function(location) { + App.MapView.createUserMarker(location, true); + }, + resize: function() { App.MapView.$el.height(window.innerHeight - $('.navbar').outerHeight(true) - this.$('select').outerHeight(true) - 10); App.MapView.resize(); @@ -619,7 +629,7 @@ $(function(){ addBuses: function() { App.MapView.clear(); - App.MapView.createUserMarker(DowntownNorfolk); + //App.MapView.createUserMarker(DowntownNorfolk); this.collection.each(function(bus){ App.MapView.createBusMarker(bus); }); @@ -628,6 +638,7 @@ $(function(){ App.MapView.setBounds(); this.firstUpdate = false; } + this.locate(); }, updateBuses: function() { From c578ab65f3b66f7fa78347cee6907128ee1d728c Mon Sep 17 00:00:00 2001 From: Mark Carter Date: Mon, 12 Oct 2015 06:27:09 -0400 Subject: [PATCH 2/6] test commit --- js/busfinder.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/js/busfinder.js b/js/busfinder.js index ea35e56..cbbeb86 100644 --- a/js/busfinder.js +++ b/js/busfinder.js @@ -245,6 +245,7 @@ $(function(){ map: this.map }); this.markers.push(userMarker); + console.log(this.markers); }, createStopMarker: function(stop, animate, onClick) { @@ -510,6 +511,8 @@ $(function(){ var onFail = function() { onLocated(DowntownNorfolk); + console.log("OrigFail!"); + console.log(new Date()); $('#geolocation-failed').prependTo('#stops').fadeIn(); }; @@ -517,13 +520,41 @@ $(function(){ var onSuccess = function(position) { clearTimeout(timeout); + console.log("origSuccess"); onLocated(new google.maps.LatLng(position.coords.latitude, position.coords.longitude)); }; + console.log("starting orig locate"); navigator.geolocation ? navigator.geolocation.getCurrentPosition(onSuccess, onFail) : onFail(); }; + var LocateRouteUser = function(onLocated) { + + var onFail = function() { + onLocated(DowntownNorfolk); + console.log("FAIL"); + console.log(new Date()); + }; + + var failTwo = function() { + onLocated(DowntownNorfolk); + console.log("TimeFail"); + } + + var timeout = setTimeout(failTwo, 5000); + + var onSuccess = function(position) { + console.log("new Success"); + clearTimeout(timeout); + onLocated(new google.maps.LatLng(position.coords.latitude, position.coords.longitude)); + }; + + navigator.geolocation ? + navigator.geolocation.getCurrentPosition(onSuccess, onFail) : onFail(); + + }; + var SnowRoute = Backbone.View.extend({ template: _.template($('#snow-route-template').html()), @@ -614,11 +645,13 @@ $(function(){ }, locate: function() { - LocateUser($.proxy(this.onUserLocated, this)); + LocateRouteUser($.proxy(this.onUserLocated, this)); }, onUserLocated: function(location) { App.MapView.createUserMarker(location, true); + console.log(location); + console.log(new Date()); }, resize: function() { From 8d3bc20e28ce7f51b8ca9f7e91745e4d80a34454 Mon Sep 17 00:00:00 2001 From: Mark Carter Date: Mon, 12 Oct 2015 11:09:21 -0400 Subject: [PATCH 3/6] added routerUser functions and array --- js/busfinder.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/js/busfinder.js b/js/busfinder.js index cbbeb86..9185bfe 100644 --- a/js/busfinder.js +++ b/js/busfinder.js @@ -204,6 +204,7 @@ $(function(){ this.markers = []; this.busMarkers = {}; this.oldBusMarkers = {}; + this.routeUserMarkers = []; google.maps.event.addListener(this.map, 'dragstart', $.proxy(this.cancelCenterChanged, this)); google.maps.event.addListener(this.map, 'dragend', $.proxy(this.readyCenterChanged, this)); @@ -230,6 +231,9 @@ $(function(){ while(this.markers.length) { this.markers.pop().setMap(null); + } + while(this.routeUserMarkers.length) { + this.routeUserMarkers.pop().setMap(null); } this.oldBusMarkers = this.busMarkers; this.busMarkers = {}; @@ -245,7 +249,18 @@ $(function(){ map: this.map }); this.markers.push(userMarker); - console.log(this.markers); + }, + + createRouteUserMarker: function(location, animate) { + var userMarker = new google.maps.Marker({ + position: location, + animation: animate && google.maps.Animation.DROP, + map: this.map + }); + while(this.routeUserMarkers.length) { + this.routeUserMarkers.pop().setMap(null); + }; + this.routeUserMarkers.push(userMarker); }, createStopMarker: function(stop, animate, onClick) { @@ -511,8 +526,6 @@ $(function(){ var onFail = function() { onLocated(DowntownNorfolk); - console.log("OrigFail!"); - console.log(new Date()); $('#geolocation-failed').prependTo('#stops').fadeIn(); }; @@ -520,11 +533,9 @@ $(function(){ var onSuccess = function(position) { clearTimeout(timeout); - console.log("origSuccess"); onLocated(new google.maps.LatLng(position.coords.latitude, position.coords.longitude)); }; - console.log("starting orig locate"); navigator.geolocation ? navigator.geolocation.getCurrentPosition(onSuccess, onFail) : onFail(); }; @@ -533,19 +544,15 @@ $(function(){ var onFail = function() { onLocated(DowntownNorfolk); - console.log("FAIL"); - console.log(new Date()); }; var failTwo = function() { onLocated(DowntownNorfolk); - console.log("TimeFail"); } var timeout = setTimeout(failTwo, 5000); var onSuccess = function(position) { - console.log("new Success"); clearTimeout(timeout); onLocated(new google.maps.LatLng(position.coords.latitude, position.coords.longitude)); }; @@ -639,8 +646,6 @@ $(function(){ this.$('.mapcanvas').show(); App.MapView.resize(); - //this.locate(); - return this; }, @@ -649,9 +654,7 @@ $(function(){ }, onUserLocated: function(location) { - App.MapView.createUserMarker(location, true); - console.log(location); - console.log(new Date()); + App.MapView.createRouteUserMarker(location, true); }, resize: function() { From 7e0695b881bbd4202ae8b313955b2a4aaddb4741 Mon Sep 17 00:00:00 2001 From: Mark Carter Date: Mon, 12 Oct 2015 11:13:25 -0400 Subject: [PATCH 4/6] failTwo not needed --- js/busfinder.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/js/busfinder.js b/js/busfinder.js index 9185bfe..489cc3b 100644 --- a/js/busfinder.js +++ b/js/busfinder.js @@ -546,11 +546,7 @@ $(function(){ onLocated(DowntownNorfolk); }; - var failTwo = function() { - onLocated(DowntownNorfolk); - } - - var timeout = setTimeout(failTwo, 5000); + var timeout = setTimeout(onFail, 5000); var onSuccess = function(position) { clearTimeout(timeout); From 7d67a4f8f674808bc87016a8ef134ba768d4d54b Mon Sep 17 00:00:00 2001 From: Mark Carter Date: Mon, 12 Oct 2015 12:11:52 -0400 Subject: [PATCH 5/6] added zoom to routeView --- js/busfinder.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/busfinder.js b/js/busfinder.js index 489cc3b..7b07782 100644 --- a/js/busfinder.js +++ b/js/busfinder.js @@ -401,6 +401,12 @@ $(function(){ draggable: flag, scrollwheel: flag, disableDoubleClickZoom: !flag}); + }, + + setZoomOption: function(flag) { + this.map.setOptions({ + zoomControl: flag + }); } }); @@ -838,6 +844,7 @@ $(function(){ this.clearIntervals(); App.ContentView.setSubView(new RouteView({routeIds: routeIds})); App.MapView.setDraggable(true); + App.MapView.setZoomOption(true); $('#loading').remove(); }, From 2019414dba1207c86a82c1b4c697fc1891d25479 Mon Sep 17 00:00:00 2001 From: Mark Carter Date: Mon, 12 Oct 2015 13:32:33 -0400 Subject: [PATCH 6/6] unset zoom when moving into the other views --- js/busfinder.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js/busfinder.js b/js/busfinder.js index 7b07782..032d145 100644 --- a/js/busfinder.js +++ b/js/busfinder.js @@ -832,12 +832,14 @@ $(function(){ this.clearIntervals(); App.ContentView.setSubView(new HomeView); App.MapView.setDraggable(false); + App.MapView.setZoomOption(false); }, stopView: function(stopIds) { this.clearIntervals(); App.ContentView.setSubView(new StopsByIdView({stopIds: stopIds})); App.MapView.setDraggable(false); + App.MapView.setZoomOption(false); }, routeView: function(routeIds) { @@ -853,6 +855,7 @@ $(function(){ var location = lat && lng && new google.maps.LatLng(lat, lng); App.ContentView.setSubView(new FindStopsView({location: location})); App.MapView.setDraggable(true); + App.MapView.setZoomOption(false); $('#loading').remove(); },