Skip to content

Commit

Permalink
Updated launchmap function
Browse files Browse the repository at this point in the history
  • Loading branch information
brendannee committed Feb 26, 2011
1 parent 25ec573 commit 16fc187
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 73 deletions.
41 changes: 11 additions & 30 deletions js/main-mobile.js
Expand Up @@ -2,10 +2,11 @@
var routeserver = "ec2-184-73-96-123.compute-1.amazonaws.com";

//Hard code map bounds
var l_lat = 37.306399999999996;
var h_lat = 38.316994299999998;
var l_lng = -123.02877599999999;
var h_lng = -121.637;
var bounds = new Object();
bounds.l_lat = 37.306399999999996;
bounds.h_lat = 38.316994299999998;
bounds.l_lng = -123.02877599999999;
bounds.h_lng = -121.637;

var map;

Expand All @@ -21,23 +22,6 @@ var profile = new Array();

var errorAlert=0;

function launchMap(){
map = new google.maps.Map(document.getElementById("map_canvas"), {
zoom: 10,
center: new google.maps.LatLng(37.880002, -122.189941),
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var bikeLayer = new google.maps.BicyclingLayer();
bikeLayer.setMap(map);

$("#map_canvas").parent().bind('pageshow',function(){
//Resize map to fit screen
$("#map_canvas").css('height',$(window).height()-parseInt($('#profile').css('height'))-2-parseInt($('#map .ui-header').css('height')));
google.maps.event.trigger(map,'resize'); //tell google maps to resize itself
});
}

function processpath(data, redraw, routeno){
switch(routeno){
case 0:
Expand All @@ -56,12 +40,6 @@ function processpath(data, redraw, routeno){

var decodedPoints = google.maps.geometry.encoding.decodePath(data[1][0]);

if(typeof(routelines[routeno])=="undefined"){
routelines[routeno] = new google.maps.Polyline();
// Add listener to route lines
new google.maps.event.addListener(routelines[routeno], "mouseover", function() { showRoute(routeno); });
}

routelines[routeno].setOptions({
strokeColor: coloroff,
strokeOpacity: 0.4,
Expand Down Expand Up @@ -94,9 +72,6 @@ function processpath(data, redraw, routeno){
$("#permalink").html("<a href='" + window.location.href + linkURL + "' title='Direct Link to this route' rel='external'><img src='images/link.png'> Permalink to Route</a>");
$("#twitter").html("<a href='http://www.addtoany.com/add_to/twitter?linkurl=" + encodeURIComponent("http://bikesy.com"+linkURL) + "&linkname=" + encodeURIComponent("Bike Route from " + startName.replace(/\+/g, "").replace(/&/g, "and") + " to " + finishName.replace(/\+/g, "").replace(/&/g, "and"))+"'><img src='images/twitter.png'> Tweet This</a>");

var distance = new Array();
var elevation = new Array();
var tripstats = new Array();
distance[routeno] = Math.round(routelines[routeno].inMiles()*10)/10;
elevation[routeno] = Math.round(getElevGain(data[2]));

Expand Down Expand Up @@ -413,6 +388,12 @@ google.setOnLoadCallback(function(){

launchMap();

$("#map_canvas").parent().bind('pageshow',function(){
//Resize map to fit screen
$("#map_canvas").css('height',$(window).height()-parseInt($('#profile').css('height'))-2-parseInt($('#map .ui-header').css('height')));
google.maps.event.trigger(map,'resize'); //tell google maps to resize itself
});

//Detect saved route from URL
if($.getUrlVar('start')!=undefined && $.getUrlVar('end')!=undefined){
$('#startbox').val($.getUrlVar('start').replace(/\+/g,' '));
Expand Down
67 changes: 28 additions & 39 deletions js/main.js
Expand Up @@ -10,10 +10,11 @@ var routeserver = "ec2-184-73-96-123.compute-1.amazonaws.com";
h_lng = data[2];
});*/
//Hard code map bounds
var l_lat = 37.306399999999996;
var h_lat = 38.316994299999998;
var l_lng = -123.02877599999999;
var h_lng = -121.637;
var bounds = new Object();
bounds.l_lat = 37.306399999999996;
bounds.h_lat = 38.316994299999998;
bounds.l_lng = -123.02877599999999;
bounds.h_lng = -121.637;

var map;

Expand Down Expand Up @@ -179,9 +180,6 @@ function processpath(data, redraw, routeno){
$("#permalink").html("<a href='" + window.location.href + linkURL + "' title='Direct Link to this route'><img src='images/link.png'> Permalink to Route</a>");
$("#twitter").html("<a href='http://www.addtoany.com/add_to/twitter?linkurl=" + encodeURIComponent("http://bikesy.com"+linkURL) + "&linkname=" + encodeURIComponent("Bike Route from " + startName.replace(/\+/g, "").replace(/&/g, "and") + " to " + finishName.replace(/\+/g, "").replace(/&/g, "and"))+"'><img src='images/twitter.png'> Tweet This</a>");

var distance = new Array();
var elevation = new Array();
var tripstats = new Array();
distance[routeno] = Math.round(routelines[routeno].inMiles()*10)/10;

elevation[routeno] = Math.round(getElevGain(data[2]));
Expand Down Expand Up @@ -304,35 +302,6 @@ function processpath(data, redraw, routeno){
showRoute(1);
}

function launchMap(){
map = new google.maps.Map(document.getElementById("map_canvas"), {
zoom: 10,
center: new google.maps.LatLng(37.880002, -122.189941),
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var bikeLayer = new google.maps.BicyclingLayer();
bikeLayer.setMap(map);

//Add welcome screen
$('#welcome_screen').fadeIn();

// Allow for clicking on the map to assign initial start points
google.maps.event.addListener(map, 'click', function(event) {
if (typeof(start_marker) == "undefined"){
addMarker(event.latLng, "start");
startpoint = event.latLng;
$("#inputs #startbox").tooltip().hide();
$("#endpointtext").fadeIn(); //Show Endpoint Tooltip
} else if (typeof(start_marker) != "undefined" && typeof(end_marker) == "undefined"){
if(startpoint.toString()!=event.latLng.toString()){
addMarker(event.latLng, "end");
recalc('both');
}
}
});
}

function drawpath(request, redraw, port){
$('#welcome_screen').fadeOut(); // hide welcome screen if its still up
$('#loading_image').show(); // show loading image, as request is about to start
Expand Down Expand Up @@ -410,9 +379,11 @@ google.setOnLoadCallback(function(){

$(document).ready(function(){
//Chrome Frame check
CFInstall.check({
mode:'overlay'
});
if(typeof CFInstall != 'undefined'){
CFInstall.check({
mode:'overlay'
});
}

resizeWindow();
//If the User resizes the window, adjust the #container height
Expand Down Expand Up @@ -473,6 +444,24 @@ google.setOnLoadCallback(function(){
});

launchMap();

//Add welcome screen
$('#welcome_screen').fadeIn();

// Allow for clicking on the map to assign initial start points
google.maps.event.addListener(map, 'click', function(event) {
if (typeof(start_marker) == "undefined"){
addMarker(event.latLng, "start");
startpoint = event.latLng;
$("#inputs #startbox").tooltip().hide();
$("#endpointtext").fadeIn(); //Show Endpoint Tooltip
} else if (typeof(start_marker) != "undefined" && typeof(end_marker) == "undefined"){
if(startpoint.toString()!=event.latLng.toString()){
addMarker(event.latLng, "end");
recalc('both');
}
}
});

//Detect saved route from URL
if($.getUrlVar('start')!=undefined && $.getUrlVar('end')!=undefined){
Expand Down
26 changes: 22 additions & 4 deletions js/util.js
Expand Up @@ -87,8 +87,8 @@ function proper(str){
return str.replace(/\w\S*/, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}

function bounds(lat1, lng1, lat2, lng2){
if(lat1>h_lat || lat2>h_lat || lat1<l_lat || lat2<l_lat || lng1>h_lng || lng2>h_lng || lng1<l_lng || lng2<l_lng){
function checkBounds(lat1, lng1, lat2, lng2){
if(lat1>bounds.h_lat || lat2>bounds.h_lat || lat1<bounds.l_lat || lat2<bounds.l_lat || lng1>bounds.h_lng || lng2>bounds.h_lng || lng1<bounds.l_lng || lng2<bounds.l_lng){
return false;
} else {
return true;
Expand All @@ -114,6 +114,24 @@ function translatePorts(hills){
alert(i+8080);
}

function launchMap(){
map = new google.maps.Map(document.getElementById("map_canvas"), {
zoom: 10,
center: new google.maps.LatLng(37.880002, -122.189941),
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var bikeLayer = new google.maps.BicyclingLayer();
bikeLayer.setMap(map);

//Setup route lines
for(i=0;i<3;i++){
routelines[i] = new google.maps.Polyline();
// Add listener to route lines
new google.maps.event.addListener(routelines[i], "mouseover", function() { showRoute(i); });
}
}

function submitForm() {
// Redraws map based on info in the form
start = $('#startbox').val();
Expand Down Expand Up @@ -154,7 +172,7 @@ function submitForm() {
elat = results[0].geometry.location.lat();
elng = results[0].geometry.location.lng();
//Now move along
if(bounds(slat,slng,elat,elng)){
if(checkBounds(slat,slng,elat,elng)){
drawpath("lat1="+slat+"&lng1="+slng+"&lat2="+elat+"&lng2="+elng, true, port);
map.panTo(new google.maps.LatLng((slat+elat)/2,(slng+elng)/2));
} else {
Expand Down Expand Up @@ -236,7 +254,7 @@ function recalc(marker_name) {
var hills = $('#hills').val();
var port = translatePorts(hills);

if(bounds(slat,slng,elat,elng)){
if(checkBounds(slat,slng,elat,elng)){

sCoords = new google.maps.LatLng(slat,slng);
eCoords = new google.maps.LatLng(elat,elng);
Expand Down

0 comments on commit 16fc187

Please sign in to comment.