Implement lint
This commit is contained in:
+24
-24
@@ -3,11 +3,11 @@
|
||||
namespace Franzz\Livetrail;
|
||||
|
||||
class GeoJson extends Geo {
|
||||
protected const EXT = '.geojson';
|
||||
|
||||
const EXT = '.geojson';
|
||||
const MAX_FILESIZE = 2; //MB
|
||||
const MAX_DEVIATION_FLAT = 0.1; //10%
|
||||
const MAX_DEVIATION_ELEV = 0.1; //10%
|
||||
private const MAX_FILESIZE = 2; //MB
|
||||
private const MAX_DEVIATION_FLAT = 0.1; //10%
|
||||
private const MAX_DEVIATION_ELEV = 0.1; //10%
|
||||
|
||||
public function __construct($sCodeName) {
|
||||
parent::__construct($sCodeName);
|
||||
@@ -38,7 +38,7 @@ class GeoJson extends Geo {
|
||||
$iGlobalInvalidPointCount = 0;
|
||||
$iGlobalPointCount = 0;
|
||||
|
||||
$this->asTracks = array();
|
||||
$this->asTracks = [];
|
||||
foreach($asTracks as $asTrackProps) {
|
||||
$asOptions = $this->parseOptions($asTrackProps['cmt']);
|
||||
|
||||
@@ -64,18 +64,18 @@ class GeoJson extends Geo {
|
||||
continue 2; //discard tracks
|
||||
}
|
||||
|
||||
$asTrack = array(
|
||||
$asTrack = [
|
||||
'type' => 'Feature',
|
||||
'properties' => array(
|
||||
'properties' => [
|
||||
'name' => $asTrackProps['name'],
|
||||
'type' => $sType,
|
||||
'description' => $asTrackProps['desc']
|
||||
),
|
||||
'geometry' => array(
|
||||
],
|
||||
'geometry' => [
|
||||
'type' => 'LineString',
|
||||
'coordinates' => array()
|
||||
)
|
||||
);
|
||||
'coordinates' => []
|
||||
]
|
||||
];
|
||||
|
||||
if($sType != 'hitchhiking' && str_contains($asTrackProps['desc'], ' ➜ ')) {
|
||||
list($sFrom, $sTo) = explode(' ➜ ', $asTrackProps['desc']);
|
||||
@@ -86,9 +86,9 @@ class GeoJson extends Geo {
|
||||
$asTrackPoints = $asTrackProps['points'];
|
||||
$iPointCount = count($asTrackPoints);
|
||||
$iInvalidPointCount = 0;
|
||||
$asPrevPoint = array();
|
||||
$asPrevPoint = [];
|
||||
foreach($asTrackPoints as $iIndex=>$asPoint) {
|
||||
$asNextPoint = ($iIndex < ($iPointCount - 1))?$asTrackPoints[$iIndex + 1]:array();
|
||||
$asNextPoint = ($iIndex < ($iPointCount - 1))?$asTrackPoints[$iIndex + 1]:[];
|
||||
if($bSimplify && !empty($asPrevPoint) && !empty($asNextPoint)) {
|
||||
if(!$this->isPointValid($asPrevPoint, $asPoint, $asNextPoint)) {
|
||||
$iInvalidPointCount++;
|
||||
@@ -112,11 +112,11 @@ class GeoJson extends Geo {
|
||||
$this->addNotice('Sorting off-tracks');
|
||||
|
||||
//Find first & last track points
|
||||
$asTracksEnds = array();
|
||||
$asTracks = array();
|
||||
$asTracksEnds = [];
|
||||
$asTracks = [];
|
||||
foreach($this->asTracks as $iTrackId=>$asTrack) {
|
||||
$sTrackId = 't'.$iTrackId;
|
||||
$asTracksEnds[$sTrackId] = array('first'=>reset($asTrack['geometry']['coordinates']), 'last'=>end($asTrack['geometry']['coordinates']));
|
||||
$asTracksEnds[$sTrackId] = ['first'=>reset($asTrack['geometry']['coordinates']), 'last'=>end($asTrack['geometry']['coordinates'])];
|
||||
$asTracks[$sTrackId] = $asTrack;
|
||||
}
|
||||
|
||||
@@ -153,14 +153,14 @@ class GeoJson extends Geo {
|
||||
//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);
|
||||
$asTracks = array_slice($asTracks, 0, $iOffset) + [$sTrackId => $asTrack] + array_slice($asTracks, $iOffset);
|
||||
}
|
||||
|
||||
$this->asTracks = array_values($asTracks);
|
||||
}
|
||||
|
||||
public function getCenter() {
|
||||
$asCoords = array();
|
||||
$asCoords = [];
|
||||
$asMainTracks = array_filter($this->asTracks, function ($astrack) {return $astrack['properties']['type'] == 'main';});
|
||||
foreach($asMainTracks as $asMainTrack) {
|
||||
foreach($asMainTrack['geometry']['coordinates'] as $aiCoords) {
|
||||
@@ -173,7 +173,7 @@ class GeoJson extends Geo {
|
||||
|
||||
private function parseOptions($sComment) {
|
||||
$sComment = strip_tags(html_entity_decode($sComment));
|
||||
$asOptions = array(self::OPT_SIMPLE=>'');
|
||||
$asOptions = [self::OPT_SIMPLE=>''];
|
||||
foreach(explode("\n", $sComment) as $sLine) {
|
||||
$asOptions[mb_strtolower(trim(mb_strstr($sLine, ':', true)))] = mb_strtolower(trim(mb_substr(mb_strstr($sLine, ':'), 1)));
|
||||
}
|
||||
@@ -189,8 +189,8 @@ class GeoJson extends Geo {
|
||||
|
||||
//Path Turn Check -> -> -> ->
|
||||
//Law of Cosines (vector): angle = arccos(OA.OB / ||OA||.||OB||)
|
||||
$fVectorOA = array('lon'=>($asPointA['lon'] - $asPointO['lon']), 'lat'=> ($asPointA['lat'] - $asPointO['lat']));
|
||||
$fVectorOB = array('lon'=>($asPointB['lon'] - $asPointO['lon']), 'lat'=> ($asPointB['lat'] - $asPointO['lat']));
|
||||
$fVectorOA = ['lon'=>($asPointA['lon'] - $asPointO['lon']), 'lat'=> ($asPointA['lat'] - $asPointO['lat'])];
|
||||
$fVectorOB = ['lon'=>($asPointB['lon'] - $asPointO['lon']), 'lat'=> ($asPointB['lat'] - $asPointO['lat'])];
|
||||
|
||||
$fLengthOA = sqrt(pow($asPointA['lon'] - $asPointO['lon'], 2) + pow($asPointA['lat'] - $asPointO['lat'], 2));
|
||||
$fLengthOB = sqrt(pow($asPointO['lon'] - $asPointB['lon'], 2) + pow($asPointO['lat'] - $asPointB['lat'], 2));
|
||||
@@ -210,10 +210,10 @@ class GeoJson extends Geo {
|
||||
}
|
||||
|
||||
private function buildGeoJson() {
|
||||
return json_encode(array('type'=>'FeatureCollection', 'features'=>$this->asTracks));
|
||||
return json_encode(['type'=>'FeatureCollection', 'features'=>$this->asTracks]);
|
||||
}
|
||||
|
||||
private static function getDistance($asPointA, $asPointB) {
|
||||
private static function getDistance($asPointA, $asPointB) {
|
||||
$fLatFrom = $asPointA[1];
|
||||
$fLonFrom = $asPointA[0];
|
||||
$fLatTo = $asPointB[1];
|
||||
|
||||
Reference in New Issue
Block a user