Второй вариант подгрузки точек - не всех сразу
This commit is contained in:
parent
a3fc9c73e0
commit
8b622bf2fe
|
|
@ -11,7 +11,16 @@ class JsonController extends Controller
|
|||
if (App::$user && App::$user->isAdmin == 1) {
|
||||
$points = Point::model()->getAll();
|
||||
} 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));
|
||||
|
|
|
|||
|
|
@ -89,10 +89,20 @@ class Point extends Model
|
|||
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;
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -194,6 +194,8 @@ function initCategories()
|
|||
});
|
||||
}
|
||||
|
||||
initPoints(true);
|
||||
|
||||
return initPoints();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -174,16 +174,32 @@ function constructPoint(data)
|
|||
* Загружает точки с сервера.
|
||||
* @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({
|
||||
url: "/json/points/",
|
||||
data: {
|
||||
bounds: bounds
|
||||
},
|
||||
success: function (data) {
|
||||
for (var k in data) {
|
||||
markers.addLayer(constructPoint(data[k]));
|
||||
if (typeof points[k] == 'undefined') {
|
||||
markers.addLayer(constructPoint(data[k]));
|
||||
}
|
||||
}
|
||||
myMap.addLayer(markers);
|
||||
|
||||
if (useBounds == true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (getURLParameter('point') != 'null')
|
||||
{
|
||||
if (getURLParameter('point') == 'random')
|
||||
|
|
|
|||
Loading…
Reference in New Issue