первый непонятный алгоритм упрощения трека
This commit is contained in:
parent
03941c8118
commit
cd963f2be2
|
|
@ -658,4 +658,119 @@ class JsonController extends Controller
|
|||
die;
|
||||
}
|
||||
|
||||
|
||||
static function actionSimpletrack()
|
||||
{
|
||||
$id = intval(App::getParam('id'));
|
||||
|
||||
if (!$id) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$trip = Trips::model()->getByPK($id);
|
||||
|
||||
if ($trip->isEmpty() || ($trip->status != Trips::STATUS_PUBLIC && $trip->owner != App::$user->id)) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$res = array(
|
||||
'name' => $trip->name,
|
||||
'time' => $trip->createdAt,
|
||||
);
|
||||
|
||||
$resWayPoints = array();
|
||||
$resTracks = array();
|
||||
$resLatlngs = array();
|
||||
$totCnt = 0;
|
||||
|
||||
|
||||
$wayPoints = WayPoints::model()->getAll(array('where' => '`tripId` = ?'), array($trip->id));
|
||||
if ($wayPoints) {
|
||||
foreach ($wayPoints as $block) {
|
||||
$resWayPoints[] = array(
|
||||
'lat' => floatval($block->lat),
|
||||
'lng' => floatval($block->lng),
|
||||
'time' => strtotime($block->createdAt),
|
||||
'name' => (string) $block->name,
|
||||
'description' => nl2br($block->description),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$tracks = Tracks::model()->getAll(array('where' => '`tripId` = ?'), array($trip->id));
|
||||
if ($tracks) {
|
||||
foreach ($tracks as $track) {
|
||||
$resLatlngs = array();
|
||||
$trackPoints = TrackPoints::model()->getAll(array('where' => '`trackId` = ?', 'noKeys' => TRUE), array($track->id));
|
||||
if ($trackPoints) {
|
||||
for ($index = 0; $index < count($trackPoints); $index++) {
|
||||
|
||||
$trackPoint = $trackPoints[$index];
|
||||
|
||||
if ($index > 2 && $index < count($trackPoints)-2) {
|
||||
|
||||
$nextPoint = $trackPoints[$index+1];
|
||||
$nextPoint = array(
|
||||
'lat' => $nextPoint->lat,
|
||||
'lng' => $nextPoint->lng,
|
||||
);
|
||||
|
||||
$distance1 = Geo::distance($prevPoint, array('lat' => $trackPoint->lat, 'lng' => $trackPoint->lng));
|
||||
|
||||
if ($distance1 < 100) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$distance2 = Geo::distance($nextPoint, array('lat' => $trackPoint->lat, 'lng' => $trackPoint->lng));
|
||||
$distance3 = Geo::distance($prevPoint, $nextPoint);
|
||||
|
||||
|
||||
if (($distance3 / ($distance1+$distance2)) > 0.982) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$prevPoint = $trackPoints[$index];
|
||||
$prevPoint = array(
|
||||
'lat' => $prevPoint->lat,
|
||||
'lng' => $prevPoint->lng,
|
||||
);
|
||||
|
||||
|
||||
$resLatlngs[] = array(
|
||||
'lat' => $trackPoint->lat,
|
||||
'lng' => $trackPoint->lng,
|
||||
);
|
||||
}
|
||||
// die;
|
||||
}
|
||||
|
||||
$totCnt += count($resLatlngs);
|
||||
$resTracks[] = array(
|
||||
'name' => (string) $track->name,
|
||||
'length' => 0,
|
||||
'latlngs' => $resLatlngs,
|
||||
'points' => count($resLatlngs),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$res['wayPoints'] = $resWayPoints;
|
||||
$res['tracks'] = $resTracks;
|
||||
$res['totCnt'] = $totCnt;
|
||||
|
||||
|
||||
$json = self::renderPartial('json.php', $res, TRUE);
|
||||
|
||||
$trip->json = $json;
|
||||
$trip->save();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
print $json;
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ function hideTrack(id)
|
|||
function loadTrack(id)
|
||||
{
|
||||
colors = ['red', 'green', 'blue', 'orange'];
|
||||
colors = ['green'];
|
||||
colorIndex = 0;
|
||||
tracks = new Array();
|
||||
markers = new Array();
|
||||
|
|
@ -76,4 +77,43 @@ function loadTrack(id)
|
|||
});
|
||||
}
|
||||
|
||||
function loadSimpleTrack(id)
|
||||
{
|
||||
colors = ['red', 'green', 'blue', 'orange'];
|
||||
colors = ['red'];
|
||||
colorIndex = 0;
|
||||
tracks = new Array();
|
||||
markers = new Array();
|
||||
$.ajax({
|
||||
url: "/json/simpletrack/id/" + id,
|
||||
success: function (data) {
|
||||
trips[id] = L.featureGroup();
|
||||
|
||||
if (typeof (data.tracks) != 'undefined') {
|
||||
for (var i = 0; i < data.tracks.length; i++) {
|
||||
color = colors[colorIndex];
|
||||
colorIndex = (colorIndex == colors.length-1) ? 0 : colorIndex+1;
|
||||
|
||||
tracks[i] = L.polyline(data.tracks[i].latlngs, {color: color, width: 4, opacity: 0.8});
|
||||
tracks[i].bindPopup(data.tracks[i].name);
|
||||
trips[id].addLayer(tracks[i])
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof (data.wayPoints) != 'undefined') {
|
||||
for (var i = 0; i < data.wayPoints.length; i++) {
|
||||
markers[i] = L.marker([data.wayPoints[i]['lat'], data.wayPoints[i]['lng']], {icon: categories.marker, title: data.wayPoints[i]['name']})
|
||||
markers[i].bindPopup('<b>' + data.wayPoints[i]['name'] + '</b><br/>' + data.wayPoints[i]['description']);
|
||||
trips[id].addLayer(markers[i])
|
||||
}
|
||||
}
|
||||
|
||||
showTrack(id)
|
||||
},
|
||||
error: function (data) {
|
||||
alert('Не удалось загрузить трек. Возможно это приватный трек и вы не его владелец.')
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue