Вывод списка треков на карте; Простые методы для показа и скрытия треков на карте; Отдельный JS файл для работы с треками;
This commit is contained in:
parent
f4b4bb2b4a
commit
08b23039ec
|
|
@ -100,6 +100,7 @@ class IndexController extends Controller
|
|||
self::addScript('/js/navigation.js?ver=' . App::getConfig('version'));
|
||||
self::addScript('/js/map.js?ver=' . App::getConfig('version'));
|
||||
self::addScript('/js/fotorama.js');
|
||||
self::addScript('/js/tracks.js?ver=' . App::getConfig('version'));
|
||||
|
||||
// self::addStyle('/css/style.css?ver=' . App::getConfig('version'));
|
||||
self::addStyle('/css/leaflet.css');
|
||||
|
|
@ -112,12 +113,12 @@ class IndexController extends Controller
|
|||
$category = Category::model()->getAll(array('order' => 'ord ASC'));
|
||||
$categoryArray = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true));
|
||||
|
||||
$routes = array();
|
||||
$favorites = array();
|
||||
$routes = $favorites = $tracks = array();
|
||||
if (App::$user && App::$user->id) {
|
||||
self::addVar('user', App::$user->id);
|
||||
$routes = Route::model()->getByAuthor(App::$user->id);
|
||||
$favorites = Favorite::model()->getAllMy();
|
||||
$tracks = Trips::model()->getAll(array('where' => '`owner` = ?'), array(App::$user->id));
|
||||
} else {
|
||||
self::addVar('user', '0');
|
||||
}
|
||||
|
|
@ -165,6 +166,7 @@ class IndexController extends Controller
|
|||
'user' => App::$user,
|
||||
'routes' => $routes,
|
||||
'favorites' => $favorites,
|
||||
'tracks' => $tracks,
|
||||
'og' => $og,
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,12 +263,13 @@ function loadPointsInBounds()
|
|||
bounds: bounds
|
||||
},
|
||||
success: function (data) {
|
||||
for(var i=0; i < data.length; i++) {
|
||||
if (typeof points[data[i].id] == 'undefined') {
|
||||
markers.addLayer(constructPoint(data[i]));
|
||||
if (typeof (data) != 'undefined' && data.length > 0) {
|
||||
for(var i=0; i < data.length; i++) {
|
||||
if (typeof points[data[i].id] == 'undefined') {
|
||||
markers.addLayer(constructPoint(data[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
myMap.addLayer(markers);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -576,30 +577,3 @@ function onLocationFound(e) {
|
|||
function onLocationError(e) {
|
||||
alert('Ошибка при определении координат: ' + e.message);
|
||||
}
|
||||
|
||||
function drawTrek(id)
|
||||
{
|
||||
colors = ['red', 'green', 'blue'];
|
||||
track = new Array();
|
||||
$.ajax({
|
||||
url: "/json/track/id/"+id,
|
||||
success: function (data) {
|
||||
if (typeof (data.tracks) != 'undefined') {
|
||||
for (var i = 0; i < data.tracks.length; i++) {
|
||||
color = colors[Math.floor(Math.random() * colors.length)]
|
||||
track[i] = L.polyline(data.tracks[i].latlngs, {color: color, width: 4, opacity: 0.8});
|
||||
track[i].addTo(myMap);
|
||||
track[i].bindPopup(data.tracks[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof (data.wayPoints) != 'undefined') {
|
||||
for (var i = 0; i < data.wayPoints.length; i++) {
|
||||
marker = L.marker([data.wayPoints[i]['lat'], data.wayPoints[i]['lng']], {icon: categories.marker, title: data.wayPoints[i]['name']})
|
||||
marker.bindPopup('<b>' + data.wayPoints[i]['name'] + '</b><br/>' +data.wayPoints[i]['description']);
|
||||
marker.addTo(myMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
var trips = new Object;
|
||||
|
||||
function showTrack(id)
|
||||
{
|
||||
if (typeof (trips[id]) == 'undefined') {
|
||||
loadTrack(id)
|
||||
} else {
|
||||
if (trips[id].status != 'show') {
|
||||
trips[id].addTo(myMap)
|
||||
trips[id].status = 'show';
|
||||
}
|
||||
|
||||
myMap.fitBounds(trips[id].getBounds());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function hideTrack(id)
|
||||
{
|
||||
if (typeof (trips[id]) == 'undefined') {
|
||||
return true;
|
||||
} else {
|
||||
if (trips[id].status == 'show') {
|
||||
myMap.removeLayer(trips[id]);
|
||||
}
|
||||
|
||||
trips[id].status = 'hide';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function loadTrack(id)
|
||||
{
|
||||
colors = ['red', 'green', 'blue', 'orange'];
|
||||
colorIndex = 0;
|
||||
tracks = new Array();
|
||||
markers = new Array();
|
||||
$.ajax({
|
||||
url: "/json/track/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)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -18,8 +18,9 @@ if (App::$user) {
|
|||
|
||||
<?php if (App::$user): ?>
|
||||
<div class="glyphicon _t" id="addPointButton" title="Добавить точку" onclick="<?= $addWithoutConfirm ? 'activateAddPoint()' : 'showPointagreement()'; ?>"><img src="/img/buttons/addPoint.png" style="margin-top: -10px; height: 30px;" /></div>
|
||||
<div class="glyphicon glyphicon-star _c boxButtonFavorites" onclick="openBox('Favorites')" title="Хочу посетить"></div>
|
||||
<div class="glyphicon _b glyphicon-cloud-download boxButtonRoutes" onclick="openBox('Routes')" title="Мои маршруты"></div>
|
||||
<div class="glyphicon _c glyphicon-star boxButtonFavorites" onclick="openBox('Favorites')" title="Хочу посетить"></div>
|
||||
<div class="glyphicon _c glyphicon-cloud-download boxButtonRoutes" onclick="openBox('Routes')" title="Мои маршруты"></div>
|
||||
<div class="glyphicon _b glyphicon-road boxButtonTracks" onclick="openBox('Tracks')" title="Мои маршруты"></div>
|
||||
<?php else: ?>
|
||||
<div class="glyphicon" id="addPointButton" onclick="$('#loginModal').modal('show');" title="Добавить точку"><img src="/img/buttons/addPoint.png" style="margin-top: -10px; height: 30px;" /></div>
|
||||
<?php endif; ?>
|
||||
|
|
@ -103,6 +104,21 @@ if (App::$user) {
|
|||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div id="boxTracks">
|
||||
<h3>Мои треки</h3>
|
||||
<span class="glyphicon glyphicon-cog" aria-hidden="true"></span>
|
||||
<a href="/tracks/">Управление</a>
|
||||
<hr/>
|
||||
<div id="tracks">
|
||||
<?php if ($tracks): ?>
|
||||
<?php foreach ($tracks as $track) : ?>
|
||||
<div class="btn-link" onclick="showTrack(<?= $track->id ?>)"><?= $track->name ?></div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
У вас пока нет сохраненных треков.
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?= App::$user ? '' : self::renderPartial('modals/login.php', null, true) ?>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
print $file->id . ' — ' . $file->name . ' ('. $file->filename.') <a href="/tracks/importgpx/id/' . $file->id . '" title="Импортировать - создать НОВЫЙ трек на карте"><span class="glyphicon glyphicon-import" aria-hidden="true"></span></a><br/>';
|
||||
print $file->id . ' — <span title="' . $file->filename . '">' . $file->name . ' [' . $file->tracksCount.' . ' . $file->tptCount.' . ' . $file->wptCount . '] <a href="/tracks/importgpx/id/' . $file->id . '" title="Импортировать - создать НОВЫЙ трек на карте"><span class="glyphicon glyphicon-import" aria-hidden="true"></span></a><br/>';
|
||||
}
|
||||
} else {
|
||||
print 'Пока ничего не загружено';
|
||||
|
|
|
|||
Loading…
Reference in New Issue