Второй вариант подгрузки точек - не всех сразу

This commit is contained in:
Krivchikov Dmitry 2015-06-18 00:15:57 +03:00
parent a3fc9c73e0
commit 8b622bf2fe
4 changed files with 42 additions and 5 deletions

View File

@ -11,7 +11,16 @@ class JsonController extends Controller
if (App::$user && App::$user->isAdmin == 1) { if (App::$user && App::$user->isAdmin == 1) {
$points = Point::model()->getAll(); $points = Point::model()->getAll();
} else { } else {
$points = Point::model()->getAllPublished(); if (!isset($_GET['bounds']) || !isset($_GET['bounds'][0]) || !isset($_GET['bounds'][1]) || !isset($_GET['bounds'][2]) || !isset($_GET['bounds'][3])) {
$points = Point::model()->getAllPublished(false);
} else {
$_GET['bounds'][0] = floatval($_GET['bounds'][0]);
$_GET['bounds'][1] = floatval($_GET['bounds'][1]);
$_GET['bounds'][2] = floatval($_GET['bounds'][2]);
$_GET['bounds'][3] = floatval($_GET['bounds'][3]);
$points = Point::model()->getAllPublished($_GET['bounds']);
}
} }
$categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true)); $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true));

View File

@ -89,10 +89,20 @@ class Point extends Model
return $this->getAll(array('where' => "`name` LIKE '%$search%' OR `description` LIKE '%$search%'", 'limit' => 20)); return $this->getAll(array('where' => "`name` LIKE '%$search%' OR `description` LIKE '%$search%'", 'limit' => 20));
} }
public function getAllPublished() public function getAllPublished($bounds = false)
{ {
$userId = App::$user ? App::$user->id : 0; $userId = App::$user ? App::$user->id : 0;
return $this->getAll(array('where' => "`moderate` = 1 OR `author` = ".$userId)); if ($bounds) {
$b0 = $bounds[0]<$bounds[2]?$bounds[0]:$bounds[2];
$b2 = $bounds[0]<$bounds[2]?$bounds[2]:$bounds[0];
$b1 = $bounds[1]<$bounds[3]?$bounds[1]:$bounds[3];
$b3 = $bounds[1]<$bounds[3]?$bounds[3]:$bounds[1];
return $this->getAll(array('where' => "(`moderate` = 1 OR `author` = $userId) AND (`lat` BETWEEN '$b0' AND '$b2') AND(`lng` BETWEEN '$b1' AND '$b3')"));
} else {
return $this->getAll(array('where' => "`moderate` = 1 OR `author` = ".$userId));
}
} }
} }

View File

@ -194,6 +194,8 @@ function initCategories()
}); });
} }
initPoints(true);
return initPoints(); return initPoints();
} }

View File

@ -174,16 +174,32 @@ function constructPoint(data)
* Загружает точки с сервера. * Загружает точки с сервера.
* @returns {Boolean} * @returns {Boolean}
*/ */
function initPoints() function initPoints(useBounds)
{ {
bounds = myMap.getBounds();
if (useBounds == true) {
bounds = Array(bounds._northEast.lat,bounds._northEast.lng,bounds._southWest.lat,bounds._southWest.lng)
} else {
bounds = 0
}
$.ajax({ $.ajax({
url: "/json/points/", url: "/json/points/",
data: {
bounds: bounds
},
success: function (data) { success: function (data) {
for (var k in data) { for (var k in data) {
markers.addLayer(constructPoint(data[k])); if (typeof points[k] == 'undefined') {
markers.addLayer(constructPoint(data[k]));
}
} }
myMap.addLayer(markers); myMap.addLayer(markers);
if (useBounds == true) {
return true;
}
if (getURLParameter('point') != 'null') if (getURLParameter('point') != 'null')
{ {
if (getURLParameter('point') == 'random') if (getURLParameter('point') == 'random')