diff --git a/public/js/map.js b/public/js/map.js index 6d13d6d..5ae3738 100644 --- a/public/js/map.js +++ b/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) { rightCoords = [e.latlng.lat, e.latlng.lng]; @@ -153,13 +153,18 @@ function constructPoint(data) icon = categories[data['categoryId']]; if (data['moderate'] != 'show') { icon = categories.lock; - data['name'] = 'На модерации: '+data['name']; + data['name'] = 'На модерации: ' + data['name']; } points[id] = L.marker( [data['lat'], data['lng']], {icon: icon, title: data['name'], id: id, categoryId: data['categoryId']} ).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]; @@ -210,79 +215,83 @@ function initPoints() */ 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("

"+marker.options['title']+"

Загрузка...").openPopup(); + marker.bindPopup("

" + marker.options['title'] + "

Загрузка...").openPopup(); $.ajax({ url: "/json/point/id/" + id, success: function (data) { pointsSources[id] = data; - if (typeof (data.images) == 'object') - { - photos = '
'; - - if (data.images.length > 1) - photos += '
+' + (data.photosCount - 1) + '
'; - - photos += ''; - photos += '
'; - } - else - { - photos = ''; - } - - onModerate = ''; - if (data.moderate != 'show') { - onModerate = 'На модерации: '; - } - - description = '
' + '

' + onModerate + data.name + '

' + photos; - description += data.descriptionHtml; - description += '
'; - description += '
'; - description += ' Подробнее'; - description += ''; - description += ''; - description += ''; - - if (isAdmin == '1') - { - description += ''; - if (getURLParameter('edit') == 'true') - { - editPoint(id); - } - } - description += '
'; - - 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; - }); + drawInfoPopup(id) } }); } else { + drawInfoPopup(id); + } +} + +function drawInfoPopup(id) { + data = pointsSources[id]; + if (typeof (data.images) == 'object') + { + photos = '
'; + + if (data.images.length > 1) + photos += '
+' + (data.photosCount - 1) + '
'; + + photos += ''; + photos += '
'; + } + else + { + photos = ''; + } + + onModerate = ''; + if (data.moderate != 'show') { + onModerate = 'На модерации: '; + } + + description = '
' + '

' + onModerate + data.name + '

' + photos; + description += data.descriptionHtml; + description += '
'; + description += '
'; + description += ' Подробнее'; + description += ''; + description += ''; + description += ''; + + if (isAdmin == '1') + { + description += ''; + if (getURLParameter('edit') == 'true') + { + editPoint(id); + } + } + description += '
'; + + 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(); diff = (bounds._northEast.lat - bounds._southWest.lat) / 4; myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom()); + marker.openPopup(); 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)