Skip to content

Commit

Permalink
Merge pull request #4 from xjedam/master
Browse files Browse the repository at this point in the history
Done
  • Loading branch information
pokonski committed Nov 29, 2011
2 parents f50c6d8 + a678573 commit 6098f9e
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 68 deletions.
53 changes: 49 additions & 4 deletions app/assets/javascripts/application.js.erb
Expand Up @@ -47,7 +47,7 @@ function constructBounds(markers){
return new google.maps.LatLngBounds(new google.maps.LatLng(min_lat,min_lng), new google.maps.LatLng(max_lat,max_lng) );
}

function addMarker(map,markers,pos,skip_middle,url){
function addMarker(map,markers,pos,skip_middle,url, index){
var marker = new google.maps.Marker({
position: pos,
draggable: EDITABLE,
Expand All @@ -68,14 +68,17 @@ function constructBounds(markers){
});
google.maps.event.addListener(marker, 'drag', function(e) {
drawPath(markers);
getElevation(markers);
});
google.maps.event.addListener(marker, 'dragend', function(e) {
setIcons(markers);
drawPath(markers);
getElevation(markers);
saveRoute(UPDATE_PATH,markers);

});
markers.push(marker);
if(index)
markers.splice(index, 0, marker);
else
markers.push(marker);
setIcons(markers,skip_middle);
drawPath(markers);
return marker;
Expand Down Expand Up @@ -116,6 +119,48 @@ function constructBounds(markers){
strokeOpacity: 0.8,
strokeWeight: 2.5
});

google.maps.event.addListener(path, 'rightclick', function(e) {
var insert_after, best_approx;
var pos1;
$.each(markers, function(index, marker){
var pos2 = marker.position;
if(pos1) {
var cur_approx = Math.abs((pos1.lat() - pos2.lat()) * (pos1.lng() - e.latLng.lng()) - (pos1.lat() - e.latLng.lat()) * (pos1.lng() - pos2.lng()));
if(!best_approx || cur_approx < best_approx) {
best_approx = cur_approx;
insert_after = index;
}
}
pos1 = pos2;

});
addMarker(map, markers, e.latLng, null, null, insert_after);
getElevation(markers);
saveRoute(UPDATE_PATH,markers);
});

google.maps.event.addListener(path, 'mouseover', function(e) {
if (pointer == null) {
pointer = new google.maps.Marker({
position: e.latLng,
map: map,
visible: true,
clickable: false,
icon: "/assets/pointer.png"
});
} else {
pointer.setVisible(true);
pointer.setPosition(e.latLng);
}
});

google.maps.event.addListener(path, 'mouseout', function(e) {
if (pointer) {
clearPointer(pointer,markers)
}
});

path.setMap(map);

$('#distance').text((path.Distance()/1000).toFixed(2)+" km");
Expand Down
1 change: 1 addition & 0 deletions app/views/routes/show.html.haml
Expand Up @@ -81,6 +81,7 @@
if (!EDITABLE)
return false;
addMarker(map,markers,e.latLng);
getElevation(markers);
saveRoute(UPDATE_PATH,markers);
$('#elevation-item').show();
});
Expand Down
10 changes: 0 additions & 10 deletions public/assets/application-e112d5c513d88b6fef37aea538695fe5.css

This file was deleted.

Binary file not shown.
19 changes: 0 additions & 19 deletions public/assets/application-fb8e1c0a9ee79b70e1d8a52d82f0ca10.js

This file was deleted.

Binary file not shown.
10 changes: 0 additions & 10 deletions public/assets/application.css

This file was deleted.

Binary file removed public/assets/application.css.gz
Binary file not shown.
19 changes: 0 additions & 19 deletions public/assets/application.js

This file was deleted.

Binary file removed public/assets/application.js.gz
Binary file not shown.
Binary file not shown.
Binary file removed public/assets/finish.png
Binary file not shown.
Binary file not shown.
Binary file removed public/assets/hiking.png
Binary file not shown.
6 changes: 0 additions & 6 deletions public/assets/manifest.yml

This file was deleted.

Binary file not shown.
Binary file removed public/assets/start.png
Binary file not shown.

0 comments on commit 6098f9e

Please sign in to comment.