Skip to content

Commit

Permalink
procedural GMap
Browse files Browse the repository at this point in the history
Signed-off-by: fpumir <[email protected]>
  • Loading branch information
fpumir committed Oct 23, 2014
1 parent 1d521db commit 0aa10a4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
6 changes: 4 additions & 2 deletions board/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
</section>

</body>
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="js/model.js"></script>
<script type="text/javascript" src="js/UI.js"></script>
<script type="text/javascript" src="js/cards.js"></script>
</html>








5 changes: 3 additions & 2 deletions board/js/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var UI={

render:function(card,callback){
render:function(card){
var div=document.createElement('div');
div.classList.add('card');
var d=new Date(card.date);
Expand All @@ -26,7 +26,8 @@ var UI={
div.appendChild(deleteButton);
var board=document.getElementById('board');
board.appendChild(div);
callback.call(this,deleteButton);
deleteButton.addEventListener('click',deleteCard,false);
//callback.call(this,deleteButton);
},

delete:function(elmt){
Expand Down
45 changes: 42 additions & 3 deletions board/js/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
var card={};
var addCard=document.getElementById('addCard');
addCard.addEventListener('submit',getCard,false);
document.getElementById('addLocation').addEventListener('click',addLocation,false);

model.init(function(card){
UI.render(card);
});

function getCard (e) {
e.preventDefault();
Expand All @@ -15,9 +20,7 @@ function getCard (e) {
card.date=cardDate;
model.add(card,function(){
console.log('item recorded');
UI.render(card,function(deleteButton){
deleteButton.addEventListener('click',deleteCard,false);
});
UI.render(card);
});
}

Expand All @@ -33,6 +36,42 @@ function deleteCard (e) {
}


function addLocation(e){
e.preventDefault();
navigator.geolocation.getCurrentPosition(
function(pos){
var userPos={lat:pos.coords.latitude,lng:pos.coords.longitude};
drawMap(userPos);
console.log(userPos);
},
function(){
var userPos={lat:48.857713,lng:2.347271};
drawMap(userPos);
},
{enableHighAccuracy:true}
);

}
function drawMap(userPos){
var centered=new google.maps.LatLng(userPos.lat,userPos.lng);
var settings={
zoom:17,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center:centered
}
new google.maps.Map(document.querySelector('#map > div'),settings);
document.getElementById('map').classList.toggle('on');
}













Expand Down
6 changes: 6 additions & 0 deletions board/js/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

var model={

init : function(callback){
for (var i in localStorage){
callback.call(this,JSON.parse(localStorage.getItem(i)));
}
},

add : function(card,callback){
localStorage.setItem(card.date,JSON.stringify(card));
var key=localStorage.getItem(card.date);
Expand Down

0 comments on commit 0aa10a4

Please sign in to comment.