FIX - непоказывание попапа при перемещении по истории, при клике в маршруте и так далее
This commit is contained in:
parent
5a6408c059
commit
ab7c821713
|
|
@ -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) {
|
||||||
|
if (!(id in pointsSources)) {
|
||||||
showInfo(e.target.options.id);
|
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,15 +215,28 @@ 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;
|
||||||
|
drawInfoPopup(id)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
drawInfoPopup(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawInfoPopup(id) {
|
||||||
|
data = pointsSources[id];
|
||||||
if (typeof (data.images) == 'object')
|
if (typeof (data.images) == 'object')
|
||||||
{
|
{
|
||||||
photos = '<div style="position: relative;">';
|
photos = '<div style="position: relative;">';
|
||||||
|
|
@ -261,28 +279,19 @@ function showInfo(id)
|
||||||
maxWidth = $(window).width() < 500 ? $(window).width() : 500;
|
maxWidth = $(window).width() < 500 ? $(window).width() : 500;
|
||||||
maxHeight = $(window).height() < 300 ? $(window).height() : 300;
|
maxHeight = $(window).height() < 300 ? $(window).height() : 300;
|
||||||
marker.options.description = description;
|
marker.options.description = description;
|
||||||
marker.bindPopup(marker.options.description, {maxWidth: maxWidth, minWidth: 400,maxHeight: maxHeight});
|
marker.bindPopup(marker.options.description, {maxWidth: maxWidth, minWidth: 400, maxHeight: maxHeight});
|
||||||
|
|
||||||
markers.zoomToShowLayer(marker, function () {
|
markers.zoomToShowLayer(marker, function () {
|
||||||
|
bounds = myMap.getBounds();
|
||||||
|
diff = (bounds._northEast.lat - bounds._southWest.lat) / 4;
|
||||||
|
myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom());
|
||||||
marker.openPopup();
|
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);
|
history.pushState({pointId: id}, document.title, "/?point=" + id);
|
||||||
document.title = data.name;
|
document.title = marker.options.title;
|
||||||
});
|
});
|
||||||
}
|
window.event.stopPropagation();
|
||||||
});
|
return true;
|
||||||
} else {
|
|
||||||
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 = points[id].options.title;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLayer(name)
|
function setLayer(name)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue