root/g-map/files/lib/page/MapAjaxPage.class.php @ 1236

Revision 1236, 2.9 kB (checked in by d0nut, 3 years ago)

may finish gmap 2.0.0 RC 3

Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/page/AbstractPage.class.php');
4
5// map imports
6require_once(WCF_DIR.'lib/data/gmap/GmapCluster.class.php');
7
8/**
9 * Returns the AJAX Content for the Gooogle Map
10 *
11 * @package     de.gmap.wcf.data.page
12 * @author      Torben Brodt
13 * @license     GNU General Public License <http://opensource.org/licenses/gpl-3.0.html>
14 */
15class MapAjaxPage extends AbstractPage {
16        public $action = '';
17        protected $zoom = 0;
18        protected $distance = 35;
19        protected $bounds= array();
20       
21        protected $datapoints = array();
22       
23        /**
24         * @see Page::readData()
25         */
26        public function readParameters() {
27                parent::readParameters();
28               
29                $this->zoom = max(min(21, isset($_GET['zoom']) ? $_GET['zoom'] : 0), 0);
30               
31                // ((50.08930948264218, 10.298652648925781), (50.14434619645057, 10.506362915039062))
32                if(isset($_GET['bounds'])) {
33                        if(preg_match('/^\(\((-?\d+\.?\d*), (-?\d+\.?\d*)\), \((-?\d+\.?\d*), (-?\d+\.?\d*)\)\)$/', $_GET['bounds'], $match)) {
34                                $this->bounds = array(
35                                        array(
36                                                'lat' => $match[1],
37                                                'lon' => $match[2]
38                                        ),
39                                        array(
40                                                'lat' => $match[3],
41                                                'lon' => $match[4]
42                                        ),
43                                );
44                        }
45                }
46               
47                // just get bounds
48                $this->action = $_GET['action'];
49               
50                // load content
51                $this->content = isset($_GET['content']) && $_GET['content'];
52               
53                // coordinates
54                $this->lat = isset($_GET['lat']) ? floatval($_GET['lat']) : 0;
55                $this->lon = isset($_GET['lon']) ? floatval($_GET['lon']) : 0;
56        }
57       
58        /**
59         * @see Page::readData()
60         */
61        public function readData() {
62                parent::readData();
63               
64                $markers = array();
65
66                $sql = 'SELECT          '.($this->action == 'pick' ? 'userID AS id,' : '').'
67                                        X(pt) AS lon,
68                                        Y(pt) AS lat
69                        FROM            wcf'.WCF_N.'_gmap_user
70                        WHERE           1';
71                       
72                if($this->bounds) {
73                        $sql .= ' AND X(pt) BETWEEN '.floatval($this->bounds[0]['lon']).' AND '.floatval($this->bounds[1]['lon']).' ';
74                        $sql .= ' AND Y(pt) BETWEEN '.floatval($this->bounds[0]['lat']).' AND '.floatval($this->bounds[1]['lat']).' ';
75                }
76                       
77                if(!$this->action == 'initialize') {
78                        $sql = 'SELECT  AVG(lon) AS lon,
79                                        AVG(lat) AS lat
80                                FROM (
81                                        '.$sql.'
82                                ) x';
83                }
84
85                $result = WCF::getDB()->sendQuery($sql);
86                while ($row = WCF::getDB()->fetchArray($result)) {
87                        $markers[] = $row;
88                }
89               
90                $cluster = new GmapCluster($this->distance, $this->zoom);
91                if($this->action == 'pick') {
92                        require_once(WCF_DIR.'lib/data/user/User.class.php');
93                        $ids = $cluster->getIDs($markers, $this->lat, $this->lon);
94                        $this->datapoints = User::getUsers(implode(",", $ids));
95                        $this->datapoints = array_map(create_function('$a', 'return array(
96                                intval($a->userID),
97                                $a->username
98                        );'), $this->datapoints);
99                } else {
100                        $this->datapoints = $cluster->getMarkers($markers);
101                }
102        }
103
104        /**
105         * @see Page::show()
106         */
107        public function show() {
108                parent::show();
109
110                echo json_encode($this->datapoints);
111        }
112}
113?>
Note: See TracBrowser for help on using the browser.