Changeset 1236

Show
Ignore:
Timestamp:
10/09/10 19:41:52 (3 years ago)
Author:
d0nut
Message:

may finish gmap 2.0.0 RC 3

Location:
g-map
Files:
1 removed
6 modified

Legend:

Unmodified
Added
Removed
  • g-map/files/js/gmap/AjaxMap.class.js

    r1235 r1236  
    88var AjaxMap = function(url, divID, switchable) { 
    99        this.url = url; 
     10        this.requestCounter = 0; 
     11        this.events = []; 
     12        this.boundsUsed; 
     13        this.zoomUsed; 
     14 
    1015        this.constructor(divID, switchable); 
    11         this.events = []; 
    12          
     16 
    1317        this.registerEvent = function(callback) { 
    1418                this.events.push(callback); 
    1519        }; 
    16          
     20 
    1721        /** 
    1822         *  
    1923         */ 
    2024        this.fireClickEvent = function(marker) { 
    21                 marker.openInfoWindowHtml(marker.getLatLng() + "\nzoom: " + this.gmap.getZoom()); 
    22                 // start ajax request for ClusterMarker here 
     25                var id = ++this.requestCounter; 
     26                marker.openInfoWindowHtml('<div id="info-'+id+'">...</div>'); 
     27                 
     28                var url = this.url; 
     29                url += '&zoom='+this.zoomUsed; 
     30                url += '&bounds='+this.boundsUsed; 
     31                url += '&action=pick'; 
     32                url += '&lon='+marker.getLatLng().x; 
     33                url += '&lat='+marker.getLatLng().y; 
     34                 
     35                var ajaxRequest = new AjaxRequest(); 
     36                ajaxRequest.openGet(url + SID_ARG_2ND, function(map, id) { 
     37                        return function() { 
     38                                if(ajaxRequest.xmlHttpRequest.readyState == 4 && ajaxRequest.xmlHttpRequest.status == 200) { 
     39                                        var dom = document.getElementById('info-'+id); 
     40                                        if(!dom) { 
     41                                                return; 
     42                                        } 
     43                                        var data = eval('(' + ajaxRequest.xmlHttpRequest.responseText + ')'); 
     44                                        var html = []; 
     45                                        for(var i=0; i<data.length; i++) { 
     46                                                html.push('<a href="index.php?page=User&amp;userID=' + data[i][0] + SID_ARG_2ND + '">' +  
     47                                                        data[i][1] + 
     48                                                        '</a>'); 
     49                                        } 
     50                                        dom.innerHTML = html.join(', '); 
     51                                }; 
     52                        }; 
     53                }(this, id)); 
     54        }; 
     55         
     56        /** 
     57         * get current bounds with additional to need refresh data with every move 
     58         */ 
     59        this.getBounds = function() { 
     60                var bounds = this.gmap.getBounds(); 
     61                var a = bounds.getSouthWest(); 
     62                var b = bounds.getNorthEast(); 
     63 
     64                // add additional 30 percent 
     65                a.y -= Math.abs(a.y - b.y) * 0.3; 
     66                b.y += Math.abs(a.y - b.y) * 0.3; 
     67                a.x -= Math.abs(a.x - b.x) * 0.2; 
     68                b.x += Math.abs(a.x - b.x) * 0.2; 
     69                 
     70                bounds.extend(new GLatLng(a.y, a.x)); 
     71                bounds.extend(new GLatLng(b.y, b.x)); 
     72                 
     73                return bounds; 
     74        }; 
     75         
     76        /** 
     77         * 
     78         */ 
     79        this.needsUpdate = function() { 
     80                if(!this.mapInitialized) { 
     81                        return true; 
     82                } 
     83                 
     84                if(this.gmap.getZoom() != this.zoomUsed) { 
     85                        return true; 
     86                } 
     87                 
     88                return !this.boundsUsed.containsBounds(this.gmap.getBounds()); 
    2389        }; 
    2490 
     91        /** 
     92         * 
     93         */ 
    2594        this.update = function() { 
    26                 // TODO: only run ajax update when leaving bounding box (extra 30%) 
    27                 url = this.url; 
    28                  
     95                if(!this.needsUpdate()) { 
     96                        return; 
     97                } 
     98                         
     99                var bounds, zoom, url = this.url; 
     100 
    29101                if(this.mapInitialized) { 
    30                         url += '&zoom='+this.gmap.getZoom(); 
    31                         url += '&bounds='+this.gmap.getBounds(); 
    32                         url += '&initialized=1'; 
     102                        bounds = this.getBounds(); 
     103                        zoom = this.gmap.getZoom(); 
     104 
     105                        url += '&zoom='+zoom; 
     106                        url += '&bounds='+bounds; 
     107                        url += '&action=update'; 
     108                } else { 
     109                        url += '&action=initialize'; 
    33110                } 
    34111 
    35112                var ajaxRequest = new AjaxRequest(); 
    36                 ajaxRequest.openGet(url + SID_ARG_2ND, function(map) { 
     113                ajaxRequest.openGet(url + SID_ARG_2ND, function(map, bounds, zoom) { 
    37114                        return function() { 
    38115                                if(ajaxRequest.xmlHttpRequest.readyState == 4 && ajaxRequest.xmlHttpRequest.status == 200) { 
     116                                        // remember the used bounds 
     117                                        map.boundsUsed = bounds; 
     118                                        map.zoomUsed = zoom; 
     119 
    39120                                        var data = eval('(' + ajaxRequest.xmlHttpRequest.responseText + ')'); 
    40121                                        var coordinates, overlay; 
     
    42123                                        if(map.mapInitialized) { 
    43124                                                map.gmap.clearOverlays(); 
    44                                                 for(var i in data) { 
     125                                                for(var i=0; i<data.length; i++) { 
    45126                                                        coordinates = new GLatLng(data[i].lat, data[i].lon); 
    46127 
     
    66147                                                map.setCoordinates(coordinates); 
    67148                                                map.gmap.clearOverlays(); 
    68                                                  
     149                 
    69150                                                map.update(); 
    70151                                                map.runEvents(); 
     
    72153                                } 
    73154                        }; 
    74                 }(this)); 
     155                }(this, bounds, zoom)); 
    75156        }; 
    76          
     157 
    77158        this.runEvents = function() { 
    78159                GEvent.addListener(this.gmap, "moveend", function(map) { 
  • g-map/files/js/gmap/ClusterMarker.class.js

    r1234 r1236  
    5151         
    5252        this.openInfoWindowHtml = function(html) { 
    53                 var window = this.map_.getInfoWindow(); 
    54                 window.reset(this.getLatLng(), [new GInfoWindowTab("", html)]); 
    55                 window.show(); 
     53                this.map_.openInfoWindowHtml(this.getLatLng(), html); 
    5654        }; 
    5755} 
  • g-map/files/lib/data/gmap/GmapCluster.class.php

    r1226 r1236  
    4848         * @return   object Google_Maps_Coordinate 
    4949         */ 
    50         protected function getCluster(array $markers) { 
     50        protected function getCluster(array $markers, $return_ids = false) { 
    5151                $count = count($markers); 
     52                $ids = array(); 
    5253 
    5354                /* Calculate average lat and lon of markers. */ 
     
    5657                   $lat_sum += $marker['lat']; 
    5758                   $lon_sum += $marker['lon']; 
     59                   if($return_ids) { 
     60                        $ids[] = $marker['id']; 
     61                   } 
    5862                } 
    5963                $lat_avg = $lat_sum / $count; 
    6064                $lon_avg = $lon_sum / $count; 
    6165                 
    62                 return array( 
     66                $data = array( 
    6367                        'count' => $count, 
    6468                        'lat' => $lat_avg, 
    6569                        'lon' => $lon_avg 
    6670                ); 
     71                if(count($ids)) { 
     72                        $data['ids'] = $ids; 
     73                } 
     74                 
     75                return $data; 
    6776        } 
    6877 
     
    7180         * @param       $markers        Array of lat and lon locations. 
    7281         */ 
    73         public function getMarkers(array $markers) { 
     82        public function getMarkers(array $markers, $pick = array()) { 
    7483                $clustered = array(); 
    7584 
     
    102111                return $clustered; 
    103112        } 
     113 
     114        /** 
     115         * 
     116         * @param       $markers        Array of lat and lon locations. 
     117         */ 
     118        public function getIDs(array $markers, $lat, $lon) { 
     119 
     120                /* Loop until all markers have been compared. */ 
     121                while (count($markers)) { 
     122                        $marker  = array_pop($markers); 
     123                        $cluster = array(); 
     124 
     125                        /* Compare against all markers which are left. */ 
     126                        foreach ($markers as $key => $target) { 
     127                                $pixels = $this->pixelDistance($marker['lat'], $marker['lon'], $target['lat'], $target['lon'], $this->zoom); 
     128 
     129                                /* If two markers are closer than given distance remove */ 
     130                                /* target marker from array and add it to cluster.        */ 
     131                                if ($this->distance > $pixels) { 
     132                                        unset($markers[$key]); 
     133                                        $cluster[] = $target; 
     134                                } 
     135                        } 
     136 
     137                        /* If a marker has been added to cluster, add also the one  */ 
     138                        /* we were comparing to and remove the original from array. */ 
     139                        if (count($cluster) > 0) { 
     140                                $cluster[] = $marker; 
     141                                $cluster = $this->getCluster($cluster, true); 
     142                                if(abs($cluster['lat'] - $lat) < 0.000000001 && abs($cluster['lon'] - $lon) < 0.000000001) { 
     143                                        return $cluster['ids']; 
     144                                } 
     145                        } else { 
     146                                if(abs($marker['lat'] - $lat) < 0.000000001 && abs($marker['lon'] - $lon) < 0.000000001) { 
     147                                        return array($marker['id']); 
     148                                } 
     149                        } 
     150                } 
     151                return null; 
     152        } 
    104153} 
  • g-map/files/lib/page/MapAjaxPage.class.php

    r1235 r1236  
    1414 */ 
    1515class MapAjaxPage extends AbstractPage { 
     16        public $action = ''; 
    1617        protected $zoom = 0; 
    1718        protected $distance = 35; 
    1819        protected $bounds= array(); 
    19         protected $initialized = false; 
    2020         
    21         protected $markers = array(); 
     21        protected $datapoints = array(); 
    2222         
    2323        /** 
     
    4242                                        ), 
    4343                                ); 
    44  
    45                                 // extra 30% 
    46                                 // TODO: let javascript control the bounding box 
    47                                 $this->bounds[0]['lat'] -= abs($this->bounds[0]['lat'] - $this->bounds[1]['lat']) * 0.3; 
    48                                 $this->bounds[1]['lat'] += abs($this->bounds[0]['lat'] - $this->bounds[1]['lat']) * 0.3; 
    49                                 $this->bounds[0]['lon'] -= abs($this->bounds[0]['lon'] - $this->bounds[1]['lon']) * 0.3; 
    50                                 $this->bounds[1]['lon'] += abs($this->bounds[0]['lon'] - $this->bounds[1]['lon']) * 0.3; 
    5144                        } 
    5245                } 
    5346                 
    5447                // just get bounds 
    55                 $this->initialized = isset($_GET['initialized']) && $_GET['initialized']; 
     48                $this->action = $_GET['action']; 
    5649                 
    5750                // load content 
    5851                $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; 
    5956        } 
    6057         
     
    6764                $markers = array(); 
    6865 
    69                 $sql = 'SELECT          X(pt) AS lon, 
     66                $sql = 'SELECT          '.($this->action == 'pick' ? 'userID AS id,' : '').' 
     67                                        X(pt) AS lon, 
    7068                                        Y(pt) AS lat 
    7169                        FROM            wcf'.WCF_N.'_gmap_user 
     
    7775                } 
    7876                         
    79                 if(!$this->initialized) { 
     77                if(!$this->action == 'initialize') { 
    8078                        $sql = 'SELECT  AVG(lon) AS lon, 
    8179                                        AVG(lat) AS lat 
     
    9189                 
    9290                $cluster = new GmapCluster($this->distance, $this->zoom); 
    93                 $this->markers = $cluster->getMarkers($markers); 
     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                } 
    94102        } 
    95103 
     
    100108                parent::show(); 
    101109 
    102                 echo json_encode($this->markers); 
     110                echo json_encode($this->datapoints); 
    103111        } 
    104112} 
  • g-map/optionals/de.gmap.wbb/package.xml

    r1232 r1236  
    1010                <packagedescription language="it"><![CDATA[Questo pacchetto aggiunge alcune ottimizzazioni WBB al G-Map per WCF.]]></packagedescription> 
    1111                <isunique>0</isunique> 
    12                 <version>2.0.0 RC 1</version> 
     12                <version>2.0.0 RC 3</version> 
    1313                <date>DATE</date> 
    1414                <plugin>com.woltlab.wbb</plugin> 
     
    3333        </instructions> 
    3434 
    35         <instructions type="update" fromversion="2.0.0 RC 1"> 
     35        <instructions type="update" fromversion="2.0.0 RC 2"> 
    3636                <files>files.tar</files> 
     37                <languages languagecode="it">it.xml</languages> 
    3738        </instructions> 
    3839</package> 
  • g-map/package.xml

    r1232 r1236  
    1010                <packagedescription language="it"><![CDATA[Questo pacchetto aggiunge una mappa di Google sul tuo forum.]]></packagedescription> 
    1111                <isunique>1</isunique> 
    12                 <version>2.0.0 RC 2</version> 
     12                <version>2.0.0 RC 1</version> 
    1313                <date>DATE</date> 
    1414                <plugin>com.woltlab.wcf</plugin> 
     
    4444        </instructions> 
    4545         
    46         <instructions type="update" fromversion="2.0.0 RC 1"> 
     46        <instructions type="update" fromversion="2.0.0 RC 2"> 
    4747                <files>files.tar</files> 
    48                 <templates>templates.tar</templates> 
    49                 <languages languagecode="de">de.xml</languages> 
    50                 <languages languagecode="en">en.xml</languages> 
     48                <languages languagecode="it">it.xml</languages> 
    5149        </instructions> 
    5250</package>