diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index a9cee44..bd20fdf 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -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)); diff --git a/ground/models/Point.php b/ground/models/Point.php index cf26597..3ce717d 100644 --- a/ground/models/Point.php +++ b/ground/models/Point.php @@ -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)); + } } + } diff --git a/public/js/app.js b/public/js/app.js index efff2da..b6b93a9 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -194,6 +194,8 @@ function initCategories() }); } + initPoints(true); + return initPoints(); } diff --git a/public/js/map.js b/public/js/map.js index e03ffe6..c535e0d 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -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')