var map;
$(document).ready(function(){
/* Google Map vars and objects */
var myLatlng = new google.maps.LatLng(46.315161420540335, 11.269912719726562);
var osmMapType = new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
return "http://tile.openstreetmap.org/" +
zoom + "/" + coord.x + "/" + coord.y + ".png";
},
tileSize: new google.maps.Size(256, 256),
isPng: true,
alt: "Open Street Map",
name: "OSM",
maxZoom: 19
});
var ocmMapType = new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
return "http://thunderflames.org/tiles/cycle/" + zoom + "/" + coord.x + "/" + coord.y + ".png";
},
tileSize: new google.maps.Size(256, 256),
isPng: true,
alt: "Cycle Map",
name: "Cycle Map",
maxZoom: 13
});
var myOptions = {
zoom: 8,
center: myLatlng,
streetViewControl: true,
disableDoubleClickZoom: false,
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN},
// ROADMAP, SATELLITE, HYBRID, TERRAIN, OSM;
mapTypeId: google.maps.MapTypeId.HYBRID,
scaleControl: true,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID,google.maps.MapTypeId.TERRAIN, 'OSM','Cycle Map'],
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
overviewMapControl: true,
overviewMapControlOptions: {
opened: true
}
};
map = new google.maps.Map(
document.getElementById("map"),
myOptions);
map.mapTypes.set('OSM',osmMapType);
map.mapTypes.set('Cycle Map',ocmMapType);
//map.setMapTypeId('OSM');
// *** Overlay-Map ****
// Set map's properties now that all bindings and listeners
//window.overviewMap=new window.jeremy.jOverviewMapControl(map);
// *** BUTTONS DEFINIEREN
// Schritt zurück
var controlDiv = document.createElement('DIV');
controlDiv.style.padding = '5px';
var controlUI = document.createElement('DIV');
controlUI.style.borderStyle = 'none';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'center';
controlUI.title = 'Schritt zurück';
controlDiv.appendChild(controlUI);
var controlText = document.createElement('DIV');
controlText.style.fontFamily = 'Arial,sans-serif';
controlText.innerHTML = '';
controlUI.appendChild(controlText);
google.maps.event.addDomListener(controlUI, 'click', function() {
deletelastpoint();
});
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);
// Neue Tour
var controlDiv = document.createElement('DIV');
controlDiv.style.padding = '5px';
var controlUI = document.createElement('DIV');
controlUI.style.borderStyle = 'none';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'center';
controlUI.title = 'Neue Tour anfangen';
controlDiv.appendChild(controlUI);
var controlText = document.createElement('DIV');
controlText.style.fontFamily = 'Arial,sans-serif';
controlText.innerHTML = '';
controlUI.appendChild(controlText);
google.maps.event.addDomListener(controlUI, 'click', function() {
newtour();
});
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);
var startmarker = new google.maps.Marker({
title: 'Start',
map: null
});
var endmarker = new google.maps.Marker({
title: 'Ende',
map: null
});
startmarker.setIcon("/tourtemplates/img/flag_start.png");
endmarker.setIcon("/tourtemplates/img/flag_end.png");
hotellat = 46.537778;
hotellon = 12.135833;
if ((hotellat!=0) && (hotellon!=0)) {
var home = new google.maps.Marker({
title: 'Hotel de la Poste',
map: map
});
home.setIcon("/tourtemplates/img/hotel.png");
home.setPosition(new google.maps.LatLng(hotellat, hotellon));
}
var image = new google.maps.MarkerImage('/tourtemplates/img/cross.png',
new google.maps.Size(15, 15),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(7, 7));
var cross = new google.maps.Marker({
map: map,
icon: image
});
// cross.setIcon("/tourtemplates/img/cross.png");
map.enableKeyDragZoom({
key: "shift",
boxStyle: {
border: "2px dashed black",
backgroundColor: "red",
opacity: 0.5
},
paneStyle: {
backgroundColor: "gray",
opacity: 0.2
}
});
// Colors
var selectedColor = "#0000ff";
var deactivatedColor = "#00aa00";
var mouseoverColor = "#ff0000";
var hiddenColor = "#aaaaaa"
// Directions
var firstpoint = null;
var lastpoint = null;
var search = false;
// Höhenprofil
var seton=0;
var mappoints = [];
var height = [];
var distance = [];
$('div#hoehenprofil').mousemove(function(event) {
if(mappoints.length>0) {
xpos = event.clientX;
//line.style.left = xpos + "px";
$("div#line").css('left', xpos);
var mappoint = Math.round((xpos-10)*mappoints.length/800);
var m;
if (mappoint>0) {
m = distance[mappoint]*1000-distance[mappoint-1]*1000;
if (m==0) {m = 0.01;}
steigung = (height[mappoint]-height[mappoint-1])/(m)*100;
} else {
m = distance[mappoint+1]*1000-distance[mappoint]*1000;
if (m==0) {m = 0.01;}
steigung = (height[mappoint+1]-height[mappoint])/(m)*100;
}
if ((mappoint>=0) && (mappoint-1) {
this.setOptions({strokeColor:selectedColor});
} else {
this.setOptions({strokeColor: deactivatedColor});
}
});
google.maps.event.addListener(p[poly], 'click', function() {
$('div#wait').fadeIn(10);
if(dirlastpoint==null) {
this.setOptions({strokeColor:selectedColor});
var tracksid = $.inArray(this, p);
tour[tourorder] = this;
tourorder++;
FullTour.push(this);
FullTourId.push(tracksid);
setTrackData(tracksid);
setButtons();
$('div#wait').fadeOut(10);
}
});
// END OF ADDING TRACK
}
// CHECKING BUTTONS
function setButtons(){
if (FullTour.length>0) {
//$('a#newtour').show();
$('a#deletelast').show();
$('li#save').show();
$('li#gps').show();
$('a#roadbook').show();
} else {
//$('a#newtour').hide();
$('a#deletelast').hide();
$('li#save').hide();
$('li#gps').hide();
$('a#roadbook').hide();
}
}
// INFO - Data
function setInfo(){
//hm = Math.max(TourMaxAltitude, DirectionMaxAltitude) - Math.min(TourMinAltitude, DirectionMinAltitude);
hm = TourHpPlus + DirectionHpPlus;
km = TourDistance + DirectionDistance;
if(km>0) {
if(hm/km*0.8 >=44) {
difficulty = 'schwer';
} else if(hm/km*0.8 >=33) {
difficulty = 'mittel';
} else {
difficulty = 'leicht';
}
} else {
difficulty = '---';
}
if(difficulty!='---') {
$('span#difficulty').html('');
}
$('span#distance').html(km.toFixed(0) + " km");
$('span#altitude').html(hm.toFixed(0) + " hm");
$.post('/tourtemplates/php/ajax.hoehenprofil.php?width=800&height=110', {tracks: FullTourId.join(","), direction: $.toJSON(Direction), elevation: $.toJSON(DirectionElevation)},
function(data){
$('div#hoehenprofil').html('');
});
if(FullTour.length>0) {
$.post('/tourtemplates/php/hoehenprofil_data.php', {tracks: FullTourId.join(","), direction: $.toJSON(Direction), elevation: $.toJSON(DirectionElevation)},
function(data){
jdata = $.evalJSON(data);
//alert(data);
mappoints = jdata.mappoints;
height = jdata.height;
distance = jdata.distance;
TourHpPlus = jdata.hpplus;
});
}
}
// ADDING TRACK
function setTrackData(tracksid){
// Alle tracks deaktivieren
for(poly in p) {
p[poly].setOptions({clickable: false, strokeColor: hiddenColor});
//p[poly].setMap(null);
}
$.post('/tourtemplates/php/ajax.hoteltours.php', {action: "nexttracks", tracksid: tracksid, alltracks: FullTourId.join(",")},
function(data) {
jdata = $.evalJSON(data);
tracks = jdata.nexttours;
firstpoint = jdata.firstpoint;
lastpoint = jdata.lastpoint;
TourMinAltitude = jdata.minheight;
TourMaxAltitude = jdata.maxheight;
TourHpPlus = jdata.hpplus;
TourDistance = jdata.distance;
AllowedTours = tracks.split(',');
// Start- und Endposition anzeigen
startmarker.setPosition(new google.maps.LatLng(firstpoint.lat, firstpoint.lon));
startmarker.setMap(map);
if(dirlastpoint==null){
endmarker.setPosition(new google.maps.LatLng(lastpoint.lat, lastpoint.lon));
endmarker.setMap(map);
}
// Benachtbarte Tracks aktivieren
if (dirlastpoint==null) {
for(tour in AllowedTours) {
if (p[AllowedTours[tour]]!== undefined) {
p[AllowedTours[tour]].setMap(map);
p[AllowedTours[tour]].setOptions({clickable: true});
p[AllowedTours[tour]].setOptions({strokeColor: deactivatedColor});
}
}
// Vorhergehenden Track deaktivieren
if(tourorder>1) {
FullTour[tourorder-2].setOptions({clickable: false});
}
}
// Alle Tracks der Tour aktivieren
for(tour in FullTour) {
FullTour[tour].setMap(map);
FullTour[tour].setOptions({strokeColor:selectedColor});
}
if (FullTour.length>0) $('div.routeplanner').hide();
setInfo();
}
);
}
map.setCenter(bounds.getCenter()) ;
map.fitBounds(bounds);
$('a#maptype-roadmap').click(function(){map.setMapTypeId(google.maps.MapTypeId.ROADMAP);});
$('a#maptype-satellite').click(function(){map.setMapTypeId(google.maps.MapTypeId.SATELLITE);});
$('a#maptype-hybrid').click(function(){map.setMapTypeId(google.maps.MapTypeId.HYBRID);});
$('a#maptype-terrain').click(function(){map.setMapTypeId(google.maps.MapTypeId.TERRAIN);});
$('a#maptype-osm').click(function(){map.setMapTypeId('OSM');});
function newtour() {
if (confirm('Soll die aktuelle Bearbeitung abgebrochen werden und eine neue Planung begonnen werden?')){
$('div.routeplanner').show();
AllowedTours = []; // Contains the id's
FullTour = []; // Contains the polyline
FullTourId = []; // Contains the id's
search = false;
tourorder = 0;
dirlastpoint = null;
dd.setMap(null);
directionsDisplay.setMap(null);
directionsDisplay.setPanel(null);
TourDistance = 0;
TourHpPlus = 0;
DirectionDistance = 0;
DirectionHpPlus = 0;
DirectionMinAltitude = 9000;
DirectionMaxAltitude = 0;
mappoints = [];
WayPoints = [];
height = [];
distance = [];
Direction = [];
DirectionElevation = [];
startmarker.setMap(null);
endmarker.setMap(null);
$('div#hoehenprofil').html("");
for(poly in p) {
p[poly].setOptions({clickable: true, strokeColor: deactivatedColor});
p[poly].setMap(map);
}
setInfo();
setButtons();
}
}
$('a#newtour').click(function(){
newtour();
});
function deletelastpoint(){
if (dirlastpoint == null) { // Letzte Punkt ist vordefiniert
if (FullTour.length>0) {
FullTour.pop();
FullTourId.pop();
tourorder--;
}
if (FullTour.length>0) {
trackid = FullTourId[FullTourId.length-1];
setTrackData(trackid);
} else {
AllowedTours = []; // Contains the id's
FullTour = []; // Contains the polyline
FullTourId = []; // Contains the id's
tourorder = 0;
mappoints = [];
for(poly in p) {
p[poly].setOptions({clickable: true, strokeColor: deactivatedColor});
p[poly].setMap(map);
}
startmarker.setMap(null);
endmarker.setMap(null);
$('div#hoehenprofil').html("");
mappoints = [];
}
} else { // Letzte Punkt ist Direction-Path
WayPoints.pop();
if (WayPoints.length==0) {
dirlastpoint = null;
directionsDisplay.setMap(null);
directionsDisplay.setPanel(null);
DirectionDistance = 0;
DirectionMinAltitude = 9000;
DirectionMaxAltitude = 0;
trackid = FullTourId[FullTourId.length-1];
setTrackData(trackid);
Direction = [];
DirectionElevation =[];
//setInfo();
} else {
setDirectionPoint(WayPoints[WayPoints.length-1].location);
setTrackData(-1);
}
//setInfo();
}
setButtons();
}
$('a#deletelast').click(function() {
deletelastpoint();
});
function saveas(filetype){
$.post('/tourtemplates/php/gpsfile.php?filetype='+filetype, {tracks: FullTourId.join(","), direction: $.toJSON(Direction), elevation: $.toJSON(DirectionElevation)},
function(data){
window.location.href = '/tourtemplates/php/filedata.php?filename='+data+"&filetype="+filetype;
});
}
$('a#saveasgpx').click(function(){
saveas('gpx');
_gaq.push(['_trackEvent', 'Hotel de la Poste', 'Dateien', 'gpx - Eigene Tour']);
});
$('a#saveaskml').click(function(){
saveas('kml');
_gaq.push(['_trackEvent', 'Hotel de la Poste', 'Dateien', 'kml - Eigene Tour']);
});
$('a#saveaskmz').click(function(){
saveas('kmz');
_gaq.push(['_trackEvent', 'Hotel de la Poste','Dateien', 'kmz - Eigene Tour']);
});
$('a#saveastk').click(function(){
saveas('tk');
_gaq.push(['_trackEvent','Hotel de la Poste', 'Dateien', 'tk - Eigene Tour']);
});
$('a#saveastrk').click(function(){
saveas('trk');
_gaq.push(['_trackEvent', 'Hotel de la Poste', 'Dateien', 'trk - Eigene Tour']);
//window.open("/tourtemplates/php/gpsfile.php?filetype=trk&tracks="+FullTourId.join(","));
});
$('a#garmin').click(function(){
//width: 340,
//height: 170
_gaq.push(['_trackEvent', 'Hotel de la Poste', 'Export Garmin', 'Eigene Tour']);
$.post('/tourtemplates/php/gpsfile.php?filetype=gpx&tourname='+$("input#tourname").val(), {tracks: FullTourId.join(","), direction: $.toJSON(Direction), elevation: $.toJSON(DirectionElevation)},
function(data){
$.fancybox({
href: '/tourtemplates/php/garmin.php?file='+data+"&tourname="+$("input#tourname").val(),
type: 'iframe',
width: 340,
height: 170
});
});
});
setButtons();
// DIRECTIONS
function setDirectionPoint(point) {
if (lastpoint) {
dirlastpoint = point;
//if (WayPoints.length>0){
var request = {
origin: new google.maps.LatLng(lastpoint.lat, lastpoint.lon),
waypoints: WayPoints,
destination: point,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.METRIC
}
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(response);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("directionspanel"));
DirectionHtml = [];
// Html
for(var j = 0; j < response.routes.length; j++){
for (var k = 0; k< response.routes[j].legs.length; k++) {
for (var l= 0; l< response.routes[j].legs[k].steps.length; l++) {
if (response.routes[j].legs[k].steps[l].instructions != '') {
DirectionHtml.push(response.routes[j].legs[k].steps[l].instructions);
}
}
}
}
} else {
alert('Keine individuellen Wegpunkte gefunden.');
}
});
// }
}
}
google.maps.event.addListener(map, 'click', function(event) {
setDirectionPoint(event.latLng);
});
var elevator = new google.maps.ElevationService();
google.maps.event.addListener(directionsDisplay, 'directions_changed', function(){
DirectionDistance = 0;
DirectionMinAltitude = 9000;
DirectionMaxAltitude = 0;
var myroute = directionsDisplay.directions.routes[0];
for(i = 0; i0) {
if (results[i-1].elevation km
setInfo();
})
$('a#roadbook').click(function(){
$.post('/tourtemplates/php/ajax.hoehenprofil.php?width=640&height=110', {tracks: FullTourId.join(","), direction: $.toJSON(Direction), elevation: $.toJSON(DirectionElevation)},
function(data){
var params = [];
var polyLatLngs = [];
var dx = 1;
/*/if (mappoints) {
//var polyParams = "color:00FF80,weight:5|";
if (mappoints.length>150) {
dx = mappoints.length / 150;
}
for (var j = 0; j < mappoints.length; j=Math.round(j+dx)) {
ps = mappoints[j].split(',');
cpos = new google.maps.LatLng(ps[0],ps[1]);
polyLatLngs.push(cpos);
}
//params.push("path=" + polyParams + polyLatLngs.join("|"));
}
if(Direction.length>0) {
dx = 1;
if(Direction.length>150) {
dx=Direction.length/150;
}
for(var j = 0; j < Direction.length;j=Math.round(j+dx)) {
polyLatLngs.push(Direction[j]);
}
}
*/
/*baseUrl = "/roadbook-h27.hpdf?"+params.join("&");
var extraParams = [];
extraParams.push("center=" + map.getCenter().lat().toFixed(6) + "," + map.getCenter().lng().toFixed(6));
extraParams.push("zoom=" + map.getZoom());
extraParams.push("hp="+ data);
extraParams.push("title="+ $('input#tourname').val());
window.open(baseUrl + '&' + extraParams.join("&"), "",'');*/
//polylineEncoder = new PolylineEncoder();
//polyline = polylineEncoder.dpEncodeToJSON(polyLatLngs);
$.post('/tourtemplates/php/gpsfile.php?filetype=kmz', {tracks: FullTourId.join(","), direction: $.toJSON(Direction), elevation: $.toJSON(DirectionElevation)},
function(data2){
baseUrl = "/roadbook-h27.hpdf";
var extraParams = [];
extraParams.push("center=" + map.getCenter().lat().toFixed(6) + "," + map.getCenter().lng().toFixed(6));
extraParams.push("zoom=" + map.getZoom());
extraParams.push("hp="+ data);
extraParams.push("title="+ $('input#tourname').val());
extraParams.push("kmzfile="+data2);
extraParams.push("maptype=" + map.getMapTypeId());
window.open(baseUrl + '?' + extraParams.join("&"), "",'');
});
});
});
var dir = new google.maps.DirectionsService;
var dd = new google.maps.DirectionsRenderer({draggable: false, preserveViewport: false, markerOptions: {visible: false},
PolylineOptions: {strokeColor:"#cccccc"}});
function setDirections(fromAddress, toAddress, locale) {
if ((fromAddress) && (toAddress)) {
var request = {
origin: fromAddress,//new google.maps.LatLng(lastpoint.lat, lastpoint.lon),
destination: new google.maps.LatLng(46.537778,12.135833),
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.METRIC
}
lastpoint = new google.maps.LatLng(46.537778,12.135833);
//setDirectionPoint(fromAddress);
dir.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK){
dd.setDirections(response);
dd.setMap(map);
dd.setPanel(document.getElementById("directionspanel"));
search = true;
map.enabled = false;
}
});
}
}
$('div.routeplanner form').submit(function() {
setDirections(this.saddr.value, this.daddr.value, 'de');
return false;
});
});