diff --git a/board/js/UI.js b/board/js/UI.js index 6ee9af5..1a05042 100644 --- a/board/js/UI.js +++ b/board/js/UI.js @@ -41,8 +41,8 @@ var UI={ mapTypeId: google.maps.MapTypeId.ROADMAP, center:centered } - var map=new google.maps.Map(document.querySelector('#map > div'),settings); - callback.call(this,map); + this.map=new google.maps.Map(document.querySelector('#map > div'),settings); + callback.call(this); }, toggleMap : function(){ @@ -53,6 +53,16 @@ var UI={ toggleLoader : function(){ document.querySelector('.loader').classList.toggle('on'); return this; + }, + + setMarker : function(latLng){ + new google.maps.Marker({position:latLng,map:this.map}); + return this; + }, + + setCenter : function(latLng){ + this.map.panTo(latLng); + return this; } } diff --git a/board/js/cards.js b/board/js/cards.js index 7a0d632..9d8a149 100644 --- a/board/js/cards.js +++ b/board/js/cards.js @@ -1,7 +1,7 @@ "use strict"; -var card={},mapCanvas; +var card={}; var addCard=document.getElementById('addCard'); addCard.addEventListener('submit',getCard,false); @@ -46,8 +46,7 @@ function addLocation(e){ e.preventDefault(); UI.toggleLoader(); model.getUserLocation(function(userPos){ - UI.drawMap(userPos,function(map){ - mapCanvas=map; + UI.drawMap(userPos,function(){ UI.toggleMap().toggleLoader(); }); }); @@ -57,14 +56,11 @@ function geoCoder(e){ e.preventDefault(); var address=document.querySelector("input[name='address']").value; if(!address){return;} - var geocoder = new google.maps.Geocoder(); - geocoder.geocode({"address":address},function(data,status){ - if(status=='OK'){ - var latLng=data[0].geometry.location; - new google.maps.Marker({position:latLng,map:mapCanvas}); - mapCanvas.panTo(latLng); - } + model.geocode(address,function(latLng){ + UI.setMarker(latLng).setCenter(latLng); }); + + } diff --git a/board/js/model.js b/board/js/model.js index e3a3a29..4efdfd6 100644 --- a/board/js/model.js +++ b/board/js/model.js @@ -66,8 +66,15 @@ var model={ ); }, - - + geocode : function(address,callback){ + var geocoder = new google.maps.Geocoder(); + geocoder.geocode({"address":address},function(data,status){ + if(status=='OK'){ + var latLng=data[0].geometry.location; + callback.call(this,latLng); + } + }); + } }