Только частичная подгрузка точек на карте. Для случайной точки подгружаем всё и работаем по-старому

This commit is contained in:
Krivchikov Dmitry 2016-03-07 23:41:36 +03:00
parent 0942e34e25
commit 0724236e2e
2 changed files with 37 additions and 8 deletions

View File

@ -169,6 +169,11 @@ function getTime() {
function showRandomPoint() function showRandomPoint()
{ {
if (typeof fullLoad == 'undefined') {
initPoints();
fullLoad = true;
}
roundIndex = Math.floor(Math.random() * points.length); roundIndex = Math.floor(Math.random() * points.length);
runner = 0; runner = 0;
for (var key in points) for (var key in points)
@ -199,11 +204,9 @@ function initCategories()
}); });
} }
if (isAdmin == 0) { initPoints(true);
initPoints(true);
}
return initPoints(); return true;
} }
/** /**

View File

@ -108,6 +108,7 @@ function init(lat, lng) {
{ {
document.title = 'Лучшие выходные — это выходные в путешествии! wikipoints.ru'; 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()); 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) if (status == statusMovingInHistory)
@ -206,10 +207,6 @@ function initPoints(useBounds)
myMap.addLayer(markers); myMap.addLayer(markers);
myMap.addLayer(markersPlus); myMap.addLayer(markersPlus);
if (useBounds == true) {
return true;
}
if (getURLParameter('point') != 'null') if (getURLParameter('point') != 'null')
{ {
if (getURLParameter('point') == 'random') if (getURLParameter('point') == 'random')
@ -241,6 +238,35 @@ function initPoints(useBounds)
return true; 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 * @param {type} id