// JavaScript Document function AbsGpsTrack(trackpoints) { this.trackpoints = new Array(); this.profile = null; this.profileArr = null; this.alpha = ""; //ff this.colors = new Array(); this.colors["0"] = "#c2c2c2"; this.colors["1"] = "#c2c2c2"; this.colors["2"] = "#646567"; this.colors["3"] = "#6a8914"; this.colors["4"] = "#9fc20a"; this.colors["5"] = "#cee12f"; this.colors["6"] = "#dfe6a0"; this.colors["7"] = "#c8e9f8"; this.colors["10"] = "#26ade3"; this.colors[null]= '#c2c2c2'; this.resetData(); this.readTrackpoints(trackpoints); } AbsGpsTrack.prototype.resetData = function() { this.minEle; this.minEle = 10000; this.maxEle; this.maxEle = -10000; this.distance; this.hm = 0; this.EAST = -180; this.WEST = 180; this.NORTH = -90; this.SOUTH = 90; }; AbsGpsTrack.prototype.getUG = function (ug) { return this.colors[ug]; }; AbsGpsTrack.prototype.getTrackpoints = function() { return this.trackpoints; }; AbsGpsTrack.prototype.addTrackpoint = function(tp) { this.trackpoints.push(tp); }; AbsGpsTrack.prototype.getTrackpointAt = function(i) { return this.trackpoints[i]; }; AbsGpsTrack.prototype.getMinEle = function(){return this.minEle;}; AbsGpsTrack.prototype.getMaxEle = function(){return this.maxEle;}; AbsGpsTrack.prototype.getEAST = function(){return this.EAST;}; AbsGpsTrack.prototype.getWEST = function(){return this.WEST;}; AbsGpsTrack.prototype.getNORTH = function(){return this.NORTH;}; AbsGpsTrack.prototype.getSOUTH = function(){return this.SOUTH;}; AbsGpsTrack.prototype.getCenter = function(){ return new AbsGpsTrackpoint( (this.NORTH+this.SOUTH)/2, (this.EAST+this.WEST)/2 ); }; AbsGpsTrack.prototype.readTrackpoints = function(trackpoints) { this.resetData(); var dis = 0; var hm = 0; var pretp = null; var head = 0; var anst = 0; var lastUg = null; var a = new Array(); for (var i = 0; i < trackpoints.length; i++) { var lat = trackpoints[i].lat; var lon = trackpoints[i].lon; var ele = trackpoints[i].ele; var ug = trackpoints[i].ug; var char = trackpoints[i].char; if (isNaN(lat)) { lat = trackpoints[i][0]; lon = trackpoints[i][1]; ele = trackpoints[i][2]; ug = trackpoints[i][3]; if (trackpoints[i][4]) { char = trackpoints[i][4]; } } lat = lat*10/10; lon = lon*10/10; ele = ele*10/10; if(ele > this.maxEle) this.maxEle = ele; if(ele < this.minEle) this.minEle = ele; if(lat > this.NORTH) this.NORTH = lat; if(lat < this.SOUTH) this.SOUTH = lat; if(lon > this.EAST) this.EAST = lon; if(lon < this.WEST) this.WEST = lon; if(i==0) dis = 0; else { dis += getDistance(pretp.lat, pretp.lon, lat, lon); if (ele > pretp.ele) { hm += (ele - pretp.ele); } } var tp = new AbsGpsTrackpoint(lat, lon, ele, ug, dis); if (i == trackpoints.length-1) { ug = lastUg; tp.ug = ug; } if (lastUg !== ug) { tp.ugChange = true; } lastUg = ug; if (char !== undefined) { $.each(char, function(ii, c) { char[ii] = parseInt(c); }) tp.char = char; } if (pretp !== null && tp.lat == pretp.lat && tp.lon == pretp.lon) { } else { a.push(tp); } pretp = tp; } for(var i=0;i 1) { firstTp = tempProfile[i-countIndexEle]; lastTp = tempProfile[i]; diffEle = (lastTp.ele - firstTp.ele) / (countIndexEle); for (var n = 1; n < countIndexEle; n++) { t = tempProfile[i - countIndexEle + n]; t.ele = firstTp.ele + diffEle *n; tempProfile[i - countIndexEle + n].ele = t.ele; } countIndexEle = 1; } if (lastDis == tp.dis) { countIndexDis++; } else if (countIndexDis > 1) { firstTp = tempProfile[i-countIndexDis]; lastTp = tempProfile[i]; diffLat = (lastTp.lat - firstTp.lat) / (countIndexDis); diffLon = (lastTp.lon - firstTp.lon) / (countIndexDis); diffDis = (lastTp.dis - firstTp.dis) / (countIndexDis); for (var n = 1; n < countIndexDis; n++) { t = tempProfile[i - countIndexDis + n]; t.lat = firstTp.lat + diffLat *n; t.lon = firstTp.lon + diffLon *n; t.dis = firstTp.dis + diffDis *n; tempProfile[i - countIndexDis + n].lat = t.lat; tempProfile[i - countIndexDis + n].lon = t.lon; tempProfile[i - countIndexDis + n].dis = t.dis; } countIndexDis = 1; } lastEle = tp.ele; lastDis = tp.dis; } // Profil glätten tempProfile = this.profilGlatten(tempProfile); tempProfile = this.profilGlatten(tempProfile); // Profil ausgeben if(!onlyView) this.profileArr = tempProfile; else return tempProfile; } return this.profileArr; }; AbsGpsTrack.prototype.updateDistance = function() { var length = 0; for(var n = 0; n=this.trackpoints.length) { n = this.trackpoints.length-1; } if(n<0) { n=0; } var wp = this.trackpoints[n]; return wp; }; AbsGpsTrack.prototype.profilGlatten = function(profile) { var g = 7; var sum; var p; var n, i; var maxEle = 0; var hm = 0; var lastOrig = null; for(var b=0;b<4;b++) for(n = 1; n<= profile.length-2; n++) { if(n<=3) g = 2*n+1; else if(n>profile.length-4) g = (profile.length-n-1)*2+1; else g=7; sum = 0; for(i = n-(g-1)/2; i<= n+(g-1)/2;i++) { sum = sum + profile[i].ele; } p = profile[n]; p.ele = sum / g; if (p.trackIndex !== undefined) { maxEle = Math.max(maxEle, p.ele); if (lastOrig !== null && p.ele > lastOrig.ele) { hm += (p.ele - lastOrig.ele); } lastOrig = this.trackpoints[p.trackIndex]; } profile[n] = p; } //this.maxEle = maxEle; //this.hm = hm; return profile; }; function AbsGpsTrackpoint(lat, lon, ele, ug, dis) { this.lat = lat; this.lon = lon; this.ele = ele; this.ug = ug; this.dis = dis; this.head; this.anst; this.ugChange = false; this.char; } AbsGpsTrackpoint.prototype.clone = function() { var newTp = new AbsGpsTrackpoint(this.lat, this.lon, this.ele, this.ug, this.dis); if (this.char !== null && this.char !== undefined) { newTp.char = this.char; } return newTp; }; function getDistance(lat1, lon1, lat2, lon2) { lat1 = parseFloat(lat1); lat2 = parseFloat(lat2); lon1 = parseFloat(lon1); lon2 = parseFloat(lon2); lat = (lat1 + lat2)/2 * 0.01745; dx = 111.3 * Math.cos(lat)*(lon2-lon1); dy = 111.3 * (lat2 - lat1); return Math.sqrt(dx*dx + dy*dy); } function getAngle(lat1, lon1, lat2, lon2) { lat = (lat1 + lat2)/2 * 0.01745; dx = 111.3 * Math.cos(lat)*(lon2-lon1); dy = 111.3 * (lat2 - lat1); angle = 180/Math.PI*Math.atan2(dx,dy); return angle; } function getAnstieg(lat1, lon1, ele1, lat2, lon2, ele2) { lat = (lat1 + lat2)/2 * 0.01745; dx = 111.3 * Math.cos(lat)*(lon2-lon1); dy = 111.3 * (lat2 - lat1); dis = Math.sqrt(dx*dx + dy*dy); eledif = ele2-ele1; angle = Math.atan(eledif/dis); return angle; }