FIX - непоказывание попапа при перемещении по истории, при клике в маршруте и так далее
This commit is contained in:
parent
5a6408c059
commit
ab7c821713
133
public/js/map.js
133
public/js/map.js
|
|
@ -126,7 +126,7 @@ function init(lat, lng) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Добавление произвольной точки в маршрут по правому клику
|
// Добавление произвольной точки в маршрут по правому клику
|
||||||
myMap.on('contextmenu',function(e){
|
myMap.on('contextmenu', function (e) {
|
||||||
if (status == statusReady)
|
if (status == statusReady)
|
||||||
{
|
{
|
||||||
rightCoords = [e.latlng.lat, e.latlng.lng];
|
rightCoords = [e.latlng.lat, e.latlng.lng];
|
||||||
|
|
@ -153,13 +153,18 @@ function constructPoint(data)
|
||||||
icon = categories[data['categoryId']];
|
icon = categories[data['categoryId']];
|
||||||
if (data['moderate'] != 'show') {
|
if (data['moderate'] != 'show') {
|
||||||
icon = categories.lock;
|
icon = categories.lock;
|
||||||
data['name'] = 'На модерации: '+data['name'];
|
data['name'] = 'На модерации: ' + data['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
points[id] = L.marker(
|
points[id] = L.marker(
|
||||||
[data['lat'], data['lng']], {icon: icon, title: data['name'], id: id, categoryId: data['categoryId']}
|
[data['lat'], data['lng']], {icon: icon, title: data['name'], id: id, categoryId: data['categoryId']}
|
||||||
).on('click', function (e) {
|
).on('click', function (e) {
|
||||||
showInfo(e.target.options.id);
|
if (!(id in pointsSources)) {
|
||||||
|
showInfo(e.target.options.id);
|
||||||
|
} else {
|
||||||
|
history.pushState({pointId: id}, document.title, "/?point=" + e.target.options.id);
|
||||||
|
document.title = e.target.options.title;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return points[id];
|
return points[id];
|
||||||
|
|
@ -210,79 +215,83 @@ function initPoints()
|
||||||
*/
|
*/
|
||||||
function showInfo(id)
|
function showInfo(id)
|
||||||
{
|
{
|
||||||
marker = points[id];
|
if (!(id in points)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(id in points) || marker.options.description == undefined)
|
marker = points[id];
|
||||||
|
if (!(id in pointsSources))
|
||||||
{
|
{
|
||||||
marker.bindPopup("<h3>"+marker.options['title']+"</h3><img src='/img/loading.gif' style='height: 16px;' /> Загрузка...").openPopup();
|
marker.bindPopup("<h3>" + marker.options['title'] + "</h3><img src='/img/loading.gif' style='height: 16px;' /> Загрузка...").openPopup();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/json/point/id/" + id,
|
url: "/json/point/id/" + id,
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
pointsSources[id] = data;
|
pointsSources[id] = data;
|
||||||
if (typeof (data.images) == 'object')
|
drawInfoPopup(id)
|
||||||
{
|
|
||||||
photos = '<div style="position: relative;">';
|
|
||||||
|
|
||||||
if (data.images.length > 1)
|
|
||||||
photos += '<div class="photosCount"><span class="glyphicon glyphicon-camera"></span> <b>+' + (data.photosCount - 1) + '</b></div>';
|
|
||||||
|
|
||||||
photos += '<img src="/photos/small/' + data.img + '" onclick="showImage(\'' + id + '\')" />';
|
|
||||||
photos += '</div>';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
photos = '<img src="' + data.img + '" onclick="showImage(\'' + id + '\')" />';
|
|
||||||
}
|
|
||||||
|
|
||||||
onModerate = '';
|
|
||||||
if (data.moderate != 'show') {
|
|
||||||
onModerate = 'На модерации: ';
|
|
||||||
}
|
|
||||||
|
|
||||||
description = '<div class="infoCard">' + '<h3>' + onModerate + data.name + '</h3>' + photos;
|
|
||||||
description += data.descriptionHtml;
|
|
||||||
description += '</div><div class="clear"></div>';
|
|
||||||
description += '<div class="btn-group control">';
|
|
||||||
description += '<a type="button" class="btn btn-default" href="/page/point/id/' + id + '"><span class="glyphicon glyphicon-eye-open"></span> <span class="label">Подробнее</span></a>';
|
|
||||||
description += '<button type="button" class="btn btn-default" onclick="addToRoute(' + id + ')"><span class="glyphicon glyphicon-map-marker"></span> <span class="label">В маршрут</span></button>';
|
|
||||||
description += '<button type="button" class="btn btn-default" onclick="addRemoveLike(' + id + ')"><span id="myLikesButton" class="glyphicon glyphicon-' + (data.iLike ? 'ok' : 'thumbs-up') + '"></span> <span class="label">Нравится</span></button>';
|
|
||||||
description += '<button type="button" class="btn btn-default" onclick="addRemoveFavorite(' + id + ')"><span id="myFavoritesButton" class="glyphicon glyphicon-star' + (data.inFavorites ? '' : '-empty') + ' "></span> <span class="label">Хочу посетить</span></button>';
|
|
||||||
|
|
||||||
if (isAdmin == '1')
|
|
||||||
{
|
|
||||||
description += '<button type="button" class="btn btn-default" onclick="editPoint(' + id + ')"><span class="glyphicon glyphicon-pencil"></span> <span class="label">Редактировать</span></button>';
|
|
||||||
if (getURLParameter('edit') == 'true')
|
|
||||||
{
|
|
||||||
editPoint(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
description += '</div>';
|
|
||||||
|
|
||||||
maxWidth = $(window).width() < 500 ? $(window).width() : 500;
|
|
||||||
maxHeight = $(window).height() < 300 ? $(window).height() : 300;
|
|
||||||
marker.options.description = description;
|
|
||||||
marker.bindPopup(marker.options.description, {maxWidth: maxWidth, minWidth: 400,maxHeight: maxHeight});
|
|
||||||
|
|
||||||
markers.zoomToShowLayer(marker, function () {
|
|
||||||
marker.openPopup();
|
|
||||||
|
|
||||||
bounds = myMap.getBounds();
|
|
||||||
diff = (bounds._northEast.lat - bounds._southWest.lat) / 4;
|
|
||||||
myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom());
|
|
||||||
|
|
||||||
history.pushState({pointId: id}, document.title, "/?point=" + id);
|
|
||||||
document.title = data.name;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
drawInfoPopup(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawInfoPopup(id) {
|
||||||
|
data = pointsSources[id];
|
||||||
|
if (typeof (data.images) == 'object')
|
||||||
|
{
|
||||||
|
photos = '<div style="position: relative;">';
|
||||||
|
|
||||||
|
if (data.images.length > 1)
|
||||||
|
photos += '<div class="photosCount"><span class="glyphicon glyphicon-camera"></span> <b>+' + (data.photosCount - 1) + '</b></div>';
|
||||||
|
|
||||||
|
photos += '<img src="/photos/small/' + data.img + '" onclick="showImage(\'' + id + '\')" />';
|
||||||
|
photos += '</div>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
photos = '<img src="' + data.img + '" onclick="showImage(\'' + id + '\')" />';
|
||||||
|
}
|
||||||
|
|
||||||
|
onModerate = '';
|
||||||
|
if (data.moderate != 'show') {
|
||||||
|
onModerate = 'На модерации: ';
|
||||||
|
}
|
||||||
|
|
||||||
|
description = '<div class="infoCard">' + '<h3>' + onModerate + data.name + '</h3>' + photos;
|
||||||
|
description += data.descriptionHtml;
|
||||||
|
description += '</div><div class="clear"></div>';
|
||||||
|
description += '<div class="btn-group control">';
|
||||||
|
description += '<a type="button" class="btn btn-default" href="/page/point/id/' + id + '"><span class="glyphicon glyphicon-eye-open"></span> <span class="label">Подробнее</span></a>';
|
||||||
|
description += '<button type="button" class="btn btn-default" onclick="addToRoute(' + id + ')"><span class="glyphicon glyphicon-map-marker"></span> <span class="label">В маршрут</span></button>';
|
||||||
|
description += '<button type="button" class="btn btn-default" onclick="addRemoveLike(' + id + ')"><span id="myLikesButton" class="glyphicon glyphicon-' + (data.iLike ? 'ok' : 'thumbs-up') + '"></span> <span class="label">Нравится</span></button>';
|
||||||
|
description += '<button type="button" class="btn btn-default" onclick="addRemoveFavorite(' + id + ')"><span id="myFavoritesButton" class="glyphicon glyphicon-star' + (data.inFavorites ? '' : '-empty') + ' "></span> <span class="label">Хочу посетить</span></button>';
|
||||||
|
|
||||||
|
if (isAdmin == '1')
|
||||||
|
{
|
||||||
|
description += '<button type="button" class="btn btn-default" onclick="editPoint(' + id + ')"><span class="glyphicon glyphicon-pencil"></span> <span class="label">Редактировать</span></button>';
|
||||||
|
if (getURLParameter('edit') == 'true')
|
||||||
|
{
|
||||||
|
editPoint(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
description += '</div>';
|
||||||
|
|
||||||
|
maxWidth = $(window).width() < 500 ? $(window).width() : 500;
|
||||||
|
maxHeight = $(window).height() < 300 ? $(window).height() : 300;
|
||||||
|
marker.options.description = description;
|
||||||
|
marker.bindPopup(marker.options.description, {maxWidth: maxWidth, minWidth: 400, maxHeight: maxHeight});
|
||||||
|
|
||||||
|
markers.zoomToShowLayer(marker, function () {
|
||||||
bounds = myMap.getBounds();
|
bounds = myMap.getBounds();
|
||||||
diff = (bounds._northEast.lat - bounds._southWest.lat) / 4;
|
diff = (bounds._northEast.lat - bounds._southWest.lat) / 4;
|
||||||
myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom());
|
myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom());
|
||||||
|
marker.openPopup();
|
||||||
|
|
||||||
history.pushState({pointId: id}, document.title, "/?point=" + id);
|
history.pushState({pointId: id}, document.title, "/?point=" + id);
|
||||||
document.title = points[id].options.title;
|
document.title = marker.options.title;
|
||||||
}
|
});
|
||||||
|
window.event.stopPropagation();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLayer(name)
|
function setLayer(name)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue