var tourtype = new Array(); tourtype[0] = {id:0, name:'Horská turistika, VHT, ferrata', path:'horo'}; tourtype[1] = {id:1, name:'Auto, moto výlety', path:'auto'}; tourtype[2] = {id:2, name:'Běh, orientační běh', path:'beh'}; tourtype[3] = {id:3, name:'Cyklistika', path:'cyklo'}; tourtype[4] = {id:4, name:'Inline', path:'inline'}; tourtype[5] = {id:5, name:'Běh na lyžích', path:'lyzovani'}; tourtype[6] = {id:6, name:'Nordic walking', path:'nordic'}; tourtype[7] = {id:7, name:'Skialpinismus', path:'skialp'}; tourtype[8] = {id:8, name:'Turistika na sněžnicích', path:'sneznice'}; tourtype[9] = {id:9, name:'Pěší turistika, trekking', path:'trekking'}; tourtype[10] = {id:10, name:'Vodáci, raft, jachting', path:'voda'}; var difftype = new Array(); difftype[0] = {id:0, name:'Lehká', path:'blue'}; difftype[1] = {id:1, name:'Střední', path:'red'}; difftype[2] = {id:2, name:'Těžká', path:'black'}; for (var ti = 0; ti < tourtype.length; ti++) { tourtype[ti].icos = new Array(); tourtype[ti].icossel = new Array(); for (var ti2 = 0; ti2 < difftype.length; ti2++) { tourtype[ti].icos[ti2] = createIcoStart(tourtype[ti].path, difftype[ti2].path); tourtype[ti].icossel[ti2] = createIcoStartSel(tourtype[ti].path, difftype[ti2].path); } } for (var ti2 = 0; ti2 < difftype.length; ti2++) { difftype[ti2].ico = createIcoEnd(difftype[ti2].path); } function Tour(map, mapi) { this.map = map; this.mapi = mapi; this.trackid = -1; // default = track is not loaded this.authorid = -1; // default = track is not saved => has no author this.authorname = ''; // default = track is not saved => has no author this.tracklength = 0; // starting length this.trackelev = 0; this.trackelevrev = 0; this.trackelevprofile = ''; this.trackwidth = 5; this.tracktrans = 0.65; this.trackcolor = '#000000'; this.trackvisible = true; this.tourtype = 0; // default tour type this.difficulty = 1; // default = normal (1) this.name = ''; this.desc = ''; this.startname = ''; this.transitnames = ''; this.endname = ''; this.daypassed = ''; this.timepassed = ''; this.rating = 0; this.pois = new Array(); this.points = new Array(); this.polyline = null; this.timerelev = null; this.clearTour = clearTour; function clearTour() { this.clearTrack(); this.clearPois(); } this.addPoi = addPoi; function addPoi(latlng, tool) { var item = new PoiItem(tool, 'Název ' + (this.pois.length + 1) + '. zájmového bodu', 'Popis zájmového bodu'); item.pos = latlng; this.mapi.markers.CreatePoiMarker(tool, item); this.pois.push(item); } this.addPoint = addPoint; function addPoint(latlng, tool) { var item = new PointItem(tool, ''); item.pos = latlng; if (this.points.length > 0) { this.mapi.markers.CreatePointMarker(tool, item, false); } else { this.mapi.markers.CreatePointMarkerStart(tool, item, tourtype[this.tourtype].icos[this.difficulty], tourtype[this.tourtype].icossel[this.difficulty]); } this.points.push(item); } this.addPointBefore = addPointBefore; function addPointBefore(latlng, tool, id) { var item = new PointItem(tool, ''); item.pos = latlng; this.mapi.markers.CreatePointMarker(tool, item, false); this.points.splice(id, 0, item); } this.removePoint = removePoint; function removePoint(point, updatearray) { this.mapi.markers.removeMarker(point.idmarker); if (updatearray) { found = -1; if (this.points.length > 0) for (var ti = 0; ti < this.points.length; ti++) { if (this.points[ti].idmarker == point.idmarker) found = ti; } if (found > -1) this.points.splice(found, 1); if ((found == 0) && (this.points.length > 0)) { var oldmarker = this.points[0].idmarker; this.mapi.markers.CreatePointMarkerStart(this.points[0].tool, this.points[0], tourtype[this.tourtype].icos[this.difficulty], tourtype[this.tourtype].icossel[this.difficulty]); this.mapi.markers.removeMarker(oldmarker); } } } this.clearTrack = clearTrack; function clearTrack() { this.mapi.ctrlPanelToolTrack.selectedPoints = new Array(); while (this.points.length > 0) { point = this.points.pop(); this.removePoint(point, false); } } this.removePoi = removePoi; function removePoi(poi, updatearray) { this.mapi.markers.removeMarker(poi.idmarker); if (updatearray) { found = -1; if (this.pois.length) for (var ti = 0; ti < this.pois.length; ti++) { if (this.pois[ti].idmarker == poi.idmarker) found = ti; } if (found > -1) this.pois.splice(found, 1); } } this.clearPois = clearPois; function clearPois() { this.mapi.ctrlPanelToolPois.selectedPois = new Array(); while (this.pois.length > 0) { poi = this.pois.pop(); this.removePoi(poi, false); } } this.refreshPoly = refreshPoly; function refreshPoly() { this.recreatePoly(); } this.recreatePoly = recreatePoly; function recreatePoly() { if (this.timerelev) clearTimeout(this.timerelev); addCallback(callbacktype.elevtimeout, this, this.updateElevation); this.timerelev = setTimeout(function() { runCallback(callbacktype.elevtimeout, ''); }, 1750); this.tracklength = 0; if (this.polyline != null) this.polyline.setMap(null); var pts = Array(); if (this.points.length > 0) for (var ti = 0; ti < this.points.length; ti++) { if (ti > 0) { try { this.tracklength+= google.maps.geometry.spherical.computeDistanceBetween(this.points[ti-1].pos, this.points[ti].pos); } catch(e) { //PJ odchyceni vyjimky pri vypoctu, neni treba reagovat } } pts.push(this.points[ti].pos); } var polyOptions = { path: pts, //geodesic: true, strokeColor: this.trackcolor, strokeOpacity: this.tracktrans, strokeWeight: this.trackwidth }; this.polyline = new google.maps.Polyline(polyOptions); //this.polyline = new google.maps.Polyline(pts, this.trackcolor, this.trackwidth, this.tracktrans); if (!this.trackvisible) { this.polyline.setVisible(false); //this.polyline.hide(); } //this.map.addOverlay(this.polyline); this.polyline.setMap(this.map); } this.hidePoly = hidePoly; function hidePoly() { if (this.polyline != null) this.polyline.setVisible(false); this.trackvisible = false; } this.showPoly = showPoly ; function showPoly () { if (this.polyline != null) this.polyline.setVisible(true); this.trackvisible = true; } this.updateElevation = updateElevation; function updateElevation() { if (this.points.length > 1) { var coords = 'c='; for (var x = 0; x < this.points.length; x++) { if (x > 0) coords+= '|'; coords+= this.points[x].pos.lng().toFixed(5); coords+= ':'; coords+= this.points[x].pos.lat().toFixed(5); } addCallback(callbacktype.elevcalcsuccess, this, this.foundElevCalc); addCallback(callbacktype.elevcalccomplete, this, this.completeElevCalc); addCallback(callbacktype.elevcalcerror, this, this.errorElevCalc); url = 'elevationcalc.php'; jQuery.ajax({cache:false, data:coords, error:function() { runCallback(callbacktype.elevcalcerror, ''); }, success:function(data) { runCallback(callbacktype.elevcalcsuccess, data); }, complete:function() { runCallback(callbacktype.elevcalccomplete, ''); }, url:url, type:'POST'}); } else { this.setElevation(0); } } this.foundElevCalc = foundElevCalc; function foundElevCalc(data) { var parts = data.split(":"); if (parts.length != 2) { this.setElevation(0); this.setElevationRev(0); } else { var parts2 = parts[1].split("|"); this.setElevation(parts2[0]); this.setElevationRev(parts2[1]); } } this.errorElevCalc = errorElevCalc; function errorElevCalc() { this.setElevation(0); this.setElevationRev(0); } this.completeElevCalc = completeElevCalc; function completeElevCalc() { } this.setElevation = setElevation; function setElevation(elev) { this.trackelev = elev; } this.setElevationRev = setElevationRev; function setElevationRev(elev) { this.trackelevrev = elev; } this.setType = setType; function setType(id) { if (this.maptype != id) { try { this.tourtype = tourtype[id].id; var item = this.points[0]; var idmarker = item.idmarker; this.mapi.markers.CreatePointMarkerStart(this.mapi.ctrlPanelToolTrack, item, tourtype[this.tourtype].icos[this.difficulty], tourtype[this.tourtype].icossel[this.difficulty]); this.mapi.markers.removeMarker(idmarker); return true; } catch(e) { return false; } } else { return true; } } this.setDifficulty = setDifficulty; function setDifficulty(id) { if (this.difficulty != id) { try { this.difficulty = difftype[id].id; var item = this.points[0]; var idmarker = item.idmarker; this.mapi.markers.CreatePointMarkerStart(this.mapi.ctrlPanelToolTrack, item, tourtype[this.tourtype].icos[this.difficulty], tourtype[this.tourtype].icossel[this.difficulty]); this.mapi.markers.removeMarker(idmarker); if (this.points.length > 1) { var item = this.points[this.points.length - 1]; var idmarker = item.idmarker; this.mapi.markers.CreatePointMarkerEnd(this.mapi.ctrlPanelToolTrack, item, difftype[this.difficulty].ico); this.mapi.markers.removeMarker(idmarker); } return true; } catch(e) { return false; } } else { return true; } } this.loadTrack = loadTrack; function loadTrack(idtrack, hkey) { addCallback(callbacktype.loadtracksuccess, this, this.foundLoadTrack); addCallback(callbacktype.loadtrackcomplete, this, this.completeLoadTrack); addCallback(callbacktype.loadtrackerror, this, this.errorLoadTrack); url = 'loadtrack.php'; params = { idtrack:idtrack, hkey:hkey }; jQuery.ajax({cache:false, data:params, dataType:'json', error:function() { runCallback(callbacktype.loadtrackerror, ''); }, success:function(data) { runCallback(callbacktype.loadtracksuccess, data); }, complete:function() { runCallback(callbacktype.loadtrackcomplete, ''); }, url:url, type:'POST'}); } this.foundLoadTrack = foundLoadTrack; function foundLoadTrack(data) { if (data.error != 0) { alert('Trasa nemohla být načtena - ' + data.errordesc); } else { this.mapi.tour.clearTour(); this.trackid = data.idtrack; this.authorid = data.iduser; this.authorname = data.username; this.trackelev = data.elevation; this.trackelevrev = 0; this.trackelevprofile = data.profilefile; this.trackwidth = data.trackwidth; this.tracktrans = data.tracktrans; this.trackcolor = '#' + data.trackcolor; this.tourtype = data.tracktype; this.difficulty = data.trackdiff; this.name = data.name; this.desc = data.description; this.startname = data.startname; this.transitnames = data.transitname; this.endname = data.finishname; this.daypassed = data.rundate; this.timepassed = data.runlength; this.rating = data.rating; var bnds = new google.maps.LatLngBounds(); if (data.points.length > 0) for (var ti = 0; ti < data.points.length; ti++) { var p = new google.maps.LatLng(data.points[ti][0], data.points[ti][1]); bnds.extend(p); this.mapi.tour.addPoint(p, this.mapi.ctrlPanelToolTrack); if (data.points[ti][2].length > 0) { this.mapi.tour.points[ti].name = data.points[ti][2]; if (ti != 0) { var id = this.mapi.tour.points[ti].idmarker; this.mapi.markers.CreatePointMarker(this.mapi.ctrlPanelToolTrack, this.mapi.tour.points[ti], true); this.mapi.markers.removeMarker(id); } } if (ti == (data.points.length - 1)) { var id = this.mapi.tour.points[ti].idmarker; this.mapi.markers.CreatePointMarkerEnd(this.mapi.ctrlPanelToolTrack, this.mapi.tour.points[ti], difftype[this.difficulty].ico); this.mapi.markers.removeMarker(id); } } this.mapi.tour.refreshPoly(); this.mapi.ctrlPanelToolTrack.refreshList(); if (data.pois.length > 0) for (var ti = 0; ti < data.pois.length; ti++) { var p = new google.maps.LatLng(data.pois[ti][0], data.pois[ti][1]); bnds.extend(p); this.mapi.tour.addPoi(p, this.mapi.ctrlPanelToolPois); if (data.pois[ti][2].length > 0) this.mapi.tour.pois[ti].name = data.pois[ti][2]; if (data.pois[ti][3].length > 0) this.mapi.tour.pois[ti].desc = data.pois[ti][3]; } this.mapi.ctrlPanelToolPois.refreshList(); if ((data.points.length > 0) || (data.pois.length > 0)) { //var zlevel = this.mapi.gmap.getBoundsZoomLevel(bnds); //var cent = bnds.getCenter(); //this.mapi.gmap.setCenter(cent, zlevel); this.mapi.gmap.fitBounds(bnds); } this.mapi.ctrlPanel.activateTool(this.mapi.ctrlPanelToolDetails); } } this.errorLoadTrack = errorLoadTrack; function errorLoadTrack() { alert('Trasu nebylo možné načíst.'); } this.completeLoadTrack = completeLoadTrack; function completeLoadTrack() { } } // poi item function PoiItem(tool, name, desc) { this.tool = tool; this.name = name; this.desc = desc; } // point item function PointItem(tool, name) { this.tool = tool; this.name = name; }