diff --git a/public/js/app.js b/public/js/app.js index 6ecc2d9..644ebf5 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -169,6 +169,11 @@ function getTime() { function showRandomPoint() { + if (typeof fullLoad == 'undefined') { + initPoints(); + fullLoad = true; + } + roundIndex = Math.floor(Math.random() * points.length); runner = 0; for (var key in points) @@ -199,11 +204,9 @@ function initCategories() }); } - if (isAdmin == 0) { - initPoints(true); - } + initPoints(true); - return initPoints(); + return true; } /** diff --git a/public/js/map.js b/public/js/map.js index 9d4a39c..e586c6d 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -108,6 +108,7 @@ function init(lat, lng) { { document.title = 'Лучшие выходные — это выходные в путешествии! – wikipoints.ru'; history.pushState({lat: myMap.getCenter().lat, lng: myMap.getCenter().lng, zoom: myMap.getZoom()}, document.title, "/?lat=" + myMap.getCenter().lat + "&lng=" + myMap.getCenter().lng + "&zoom=" + myMap.getZoom()); + loadPointsInBounds(); } if (status == statusMovingInHistory) @@ -206,10 +207,6 @@ function initPoints(useBounds) myMap.addLayer(markers); myMap.addLayer(markersPlus); - if (useBounds == true) { - return true; - } - if (getURLParameter('point') != 'null') { if (getURLParameter('point') == 'random') @@ -241,6 +238,35 @@ function initPoints(useBounds) return true; } +function loadPointsInBounds() +{ + bounds = myMap.getBounds(); + bounds = Array(bounds._northEast.lat,bounds._northEast.lng,bounds._southWest.lat,bounds._southWest.lng) + + $.ajax({ + url: "/json/points/", + data: { + bounds: bounds + }, + success: function (data) { + for(var i=0; i < data.length; i++) { + if (typeof points[data[i].id] == 'undefined') { + if (data[i]['categoryId'] == 24 || data[i]['categoryId'] == 25) { + markersPlus.addLayer(constructPoint(data[i])); + } else { + markers.addLayer(constructPoint(data[i])); + } + } + } + myMap.addLayer(markers); + myMap.addLayer(markersPlus); + } + }); + + return true; +} + + /** * Показывает баллун для точки. Если данных для точки нет, то подгружает их с сервера. * @param {type} id