Пример #1
0
 /**
  * recursive function to find items to be used as markers on a map
  *
  * @param float $left
  * @param float $right
  * @param float $top
  * @param float $bottom
  * @param string $where
  * @param ArrayOfArray $data
  * @param int $limit
  * @param int $depth
  * @return void
  */
 public static function getMarkers($left, $right, $top, $bottom, &$where, &$data, $limit, $depth = 0)
 {
     $where_query = $where . " AND latitude IS NOT NULL AND latitude != 0" . " AND latitude >= '{$bottom}' AND latitude <= '{$top}'" . ($left > $right ? " AND (longitude >= '{$left}' OR longitude <= '{$right}')" : " AND longitude >= '{$left}' AND longitude <= '{$right}'");
     $query = "SELECT count(*) FROM kwalbum_items {$where_query}";
     $result = DB::query(Database::SELECT, $query)->execute();
     $count = (int) $result[0]['count(*)'];
     if (0 == $count) {
         return;
     }
     if (0 < $depth and $limit < $count) {
         $depth--;
         $centerLat = ($left + $right) / 2;
         $centerLon = ($top + $bottom) / 2;
         Model_Kwalbum_Item::getMarkers($left, $centerLat, $top, $centerLon, $where, $data, $limit, $depth);
         Model_Kwalbum_Item::getMarkers($centerLat, $right, $top, $centerLon, $where, $data, $limit, $depth);
         Model_Kwalbum_Item::getMarkers($left, $centerLat, $centerLon, $bottom, $where, $data, $limit, $depth);
         Model_Kwalbum_Item::getMarkers($centerLat, $right, $centerLon, $bottom, $where, $data, $limit, $depth);
     } elseif ($limit >= $count) {
         $query = 'SELECT id, latitude as lat, longitude as lon, count(*) as count, visible_dt as date, description' . ' FROM kwalbum_items' . $where_query . ' GROUP BY latitude, longitude' . ' ORDER BY latitude' . ' LIMIT ' . $limit;
         $result = DB::query(Database::SELECT, $query)->execute();
         foreach ($result as $row) {
             $row['group'] = false;
             $data[] = $row;
         }
     } else {
         $query = 'SELECT AVG(latitude) as lat, AVG(longitude) as lon' . ' FROM kwalbum_items' . $where_query . ' LIMIT 1';
         $result = DB::query(Database::SELECT, $query)->execute();
         $row = $result[0];
         $row['group'] = true;
         $row['count'] = $count;
         $data[] = $row;
     }
 }
Пример #2
0
 public function action_GetMapItems()
 {
     $zoom = (int) $_GET["z"];
     if ($zoom == 17) {
         $limit = 20;
     } else {
         $limit = 10;
     }
     $where = Model_Kwalbum_Item::get_where_query();
     if (!$where) {
         $where = ' WHERE 1=1 ';
     }
     $data = array();
     Model_Kwalbum_Item::getMarkers((double) $_GET["l"], (double) $_GET["r"], (double) $_GET["t"], (double) $_GET["b"], $where, $data, $limit, 1);
     echo "point\ttype\ttitle\tdescription";
     foreach ($data as $d) {
         echo "\n{$d['lon']},{$d['lat']}\t";
         if ($d['group']) {
             echo "g\t{$d['count']}\t{$zoom}";
         } else {
             echo "i\t{$d['id']}\t{$d['date']}";
         }
     }
 }