Replace Leaftlet Elevation with HeightGraph
This commit is contained in:
@@ -23,6 +23,7 @@ class Converter extends PhpObject {
|
||||
|
||||
$oGeoJson->buildTracks($oGpx->getTracks());
|
||||
if($oGeoJson->isSimplicationRequired()) $oGeoJson->buildTracks($oGpx->getTracks(), true);
|
||||
$oGeoJson->sortOffTracks();
|
||||
$oGeoJson->saveFile();
|
||||
|
||||
return $oGpx->getLog().'<br />'.$oGeoJson->getLog();
|
||||
@@ -205,6 +206,58 @@ class GeoJson extends Geo {
|
||||
if($bSimplify) $this->addNotice('Total: '.$iGlobalInvalidPointCount.'/'.$iGlobalPointCount.' points removed ('.round($iGlobalInvalidPointCount / $iGlobalPointCount * 100, 1).'%)');
|
||||
}
|
||||
|
||||
|
||||
public function sortOffTracks() {
|
||||
$this->addNotice('Sorting off-tracks');
|
||||
|
||||
//Find first & last track points
|
||||
$asTracksEnds = array();
|
||||
$asTracks = array();
|
||||
foreach($this->asTracks as $iTrackId=>$asTrack) {
|
||||
$sTrackId = 't'.$iTrackId;
|
||||
$asTracksEnds[$sTrackId] = array('first'=>reset($asTrack['geometry']['coordinates']), 'last'=>end($asTrack['geometry']['coordinates']));
|
||||
$asTracks[$sTrackId] = $asTrack;
|
||||
}
|
||||
|
||||
//Find variants close-by tracks
|
||||
$asClonedTracks = $asTracks;
|
||||
foreach($asClonedTracks as $sTrackId=>$asTrack) {
|
||||
if($asTrack['properties']['type'] != 'off-track') continue;
|
||||
|
||||
$iMinDistance = INF;
|
||||
$sConnectedTrackId = 0;
|
||||
$iPosition = 0;
|
||||
|
||||
//Test all track ending points to find the closest
|
||||
foreach($asTracksEnds as $sTrackEndId=>$asTrackEnds) {
|
||||
if($sTrackEndId != $sTrackId) {
|
||||
//Calculate distance between the last point of the track and every starting point of other tracks
|
||||
$iDistance = self::getDistance($asTracksEnds[$sTrackId]['last'], $asTrackEnds['first']);
|
||||
if($iDistance < $iMinDistance) {
|
||||
$sConnectedTrackId = $sTrackEndId;
|
||||
$iPosition = 0; //Track before the Connected Track
|
||||
$iMinDistance = $iDistance;
|
||||
}
|
||||
|
||||
//Calculate distance between the first point of the track and every ending point of other tracks
|
||||
$iDistance = self::getDistance($asTracksEnds[$sTrackId]['first'], $asTrackEnds['last']);
|
||||
if($iDistance < $iMinDistance) {
|
||||
$sConnectedTrackId = $sTrackEndId;
|
||||
$iPosition = +1; //Track after the Connected Track
|
||||
$iMinDistance = $iDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Move track
|
||||
unset($asTracks[$sTrackId]);
|
||||
$iOffset = array_search($sConnectedTrackId, array_keys($asTracks)) + $iPosition;
|
||||
$asTracks = array_slice($asTracks, 0, $iOffset) + array($sTrackId => $asTrack) + array_slice($asTracks, $iOffset);
|
||||
}
|
||||
|
||||
$this->asTracks = array_values($asTracks);
|
||||
}
|
||||
|
||||
private function parseOptions($sComment){
|
||||
$asOptions = array(self::OPT_SIMPLE=>'');
|
||||
foreach(explode("\n", $sComment) as $sLine) {
|
||||
@@ -243,6 +296,21 @@ class GeoJson extends Geo {
|
||||
}
|
||||
|
||||
private function buildGeoJson() {
|
||||
return json_encode(array('features'=>$this->asTracks));
|
||||
return json_encode(array('type'=>'FeatureCollection', 'features'=>$this->asTracks));
|
||||
}
|
||||
|
||||
private static function getDistance($asPointA, $asPointB) {
|
||||
$fLatFrom = $asPointA[1];
|
||||
$fLonFrom = $asPointA[0];
|
||||
$fLatTo = $asPointB[1];
|
||||
$fLonTo = $asPointB[0];
|
||||
|
||||
$fRad = M_PI / 180;
|
||||
|
||||
//Calculate distance from latitude and longitude
|
||||
$fTheta = $fLonFrom - $fLonTo;
|
||||
$fDistance = sin($fLatFrom * $fRad) * sin($fLatTo * $fRad) + cos($fLatFrom * $fRad) * cos($fLatTo * $fRad) * cos($fTheta * $fRad);
|
||||
|
||||
return acos($fDistance) / $fRad * 60 * 1.853;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user