Changeset 1236
- Timestamp:
- 10/09/10 19:41:52 (3 years ago)
- Location:
- g-map
- Files:
-
- 1 removed
- 6 modified
-
files/js/gmap/AjaxMap.class.js (modified) (4 diffs)
-
files/js/gmap/ClusterMarker.class.js (modified) (1 diff)
-
files/lib/data/gmap/GmapBounds.class.php (deleted)
-
files/lib/data/gmap/GmapCluster.class.php (modified) (4 diffs)
-
files/lib/page/MapAjaxPage.class.php (modified) (6 diffs)
-
optionals/de.gmap.wbb/package.xml (modified) (2 diffs)
-
package.xml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
g-map/files/js/gmap/AjaxMap.class.js
r1235 r1236 8 8 var AjaxMap = function(url, divID, switchable) { 9 9 this.url = url; 10 this.requestCounter = 0; 11 this.events = []; 12 this.boundsUsed; 13 this.zoomUsed; 14 10 15 this.constructor(divID, switchable); 11 this.events = []; 12 16 13 17 this.registerEvent = function(callback) { 14 18 this.events.push(callback); 15 19 }; 16 20 17 21 /** 18 22 * 19 23 */ 20 24 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&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()); 23 89 }; 24 90 91 /** 92 * 93 */ 25 94 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 29 101 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'; 33 110 } 34 111 35 112 var ajaxRequest = new AjaxRequest(); 36 ajaxRequest.openGet(url + SID_ARG_2ND, function(map ) {113 ajaxRequest.openGet(url + SID_ARG_2ND, function(map, bounds, zoom) { 37 114 return function() { 38 115 if(ajaxRequest.xmlHttpRequest.readyState == 4 && ajaxRequest.xmlHttpRequest.status == 200) { 116 // remember the used bounds 117 map.boundsUsed = bounds; 118 map.zoomUsed = zoom; 119 39 120 var data = eval('(' + ajaxRequest.xmlHttpRequest.responseText + ')'); 40 121 var coordinates, overlay; … … 42 123 if(map.mapInitialized) { 43 124 map.gmap.clearOverlays(); 44 for(var i in data) {125 for(var i=0; i<data.length; i++) { 45 126 coordinates = new GLatLng(data[i].lat, data[i].lon); 46 127 … … 66 147 map.setCoordinates(coordinates); 67 148 map.gmap.clearOverlays(); 68 149 69 150 map.update(); 70 151 map.runEvents(); … … 72 153 } 73 154 }; 74 }(this ));155 }(this, bounds, zoom)); 75 156 }; 76 157 77 158 this.runEvents = function() { 78 159 GEvent.addListener(this.gmap, "moveend", function(map) { -
g-map/files/js/gmap/ClusterMarker.class.js
r1234 r1236 51 51 52 52 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); 56 54 }; 57 55 } -
g-map/files/lib/data/gmap/GmapCluster.class.php
r1226 r1236 48 48 * @return object Google_Maps_Coordinate 49 49 */ 50 protected function getCluster(array $markers ) {50 protected function getCluster(array $markers, $return_ids = false) { 51 51 $count = count($markers); 52 $ids = array(); 52 53 53 54 /* Calculate average lat and lon of markers. */ … … 56 57 $lat_sum += $marker['lat']; 57 58 $lon_sum += $marker['lon']; 59 if($return_ids) { 60 $ids[] = $marker['id']; 61 } 58 62 } 59 63 $lat_avg = $lat_sum / $count; 60 64 $lon_avg = $lon_sum / $count; 61 65 62 returnarray(66 $data = array( 63 67 'count' => $count, 64 68 'lat' => $lat_avg, 65 69 'lon' => $lon_avg 66 70 ); 71 if(count($ids)) { 72 $data['ids'] = $ids; 73 } 74 75 return $data; 67 76 } 68 77 … … 71 80 * @param $markers Array of lat and lon locations. 72 81 */ 73 public function getMarkers(array $markers ) {82 public function getMarkers(array $markers, $pick = array()) { 74 83 $clustered = array(); 75 84 … … 102 111 return $clustered; 103 112 } 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 } 104 153 } -
g-map/files/lib/page/MapAjaxPage.class.php
r1235 r1236 14 14 */ 15 15 class MapAjaxPage extends AbstractPage { 16 public $action = ''; 16 17 protected $zoom = 0; 17 18 protected $distance = 35; 18 19 protected $bounds= array(); 19 protected $initialized = false;20 20 21 protected $ markers = array();21 protected $datapoints = array(); 22 22 23 23 /** … … 42 42 ), 43 43 ); 44 45 // extra 30%46 // TODO: let javascript control the bounding box47 $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;51 44 } 52 45 } 53 46 54 47 // just get bounds 55 $this-> initialized = isset($_GET['initialized']) && $_GET['initialized'];48 $this->action = $_GET['action']; 56 49 57 50 // load content 58 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; 59 56 } 60 57 … … 67 64 $markers = array(); 68 65 69 $sql = 'SELECT X(pt) AS lon, 66 $sql = 'SELECT '.($this->action == 'pick' ? 'userID AS id,' : '').' 67 X(pt) AS lon, 70 68 Y(pt) AS lat 71 69 FROM wcf'.WCF_N.'_gmap_user … … 77 75 } 78 76 79 if(!$this-> initialized) {77 if(!$this->action == 'initialize') { 80 78 $sql = 'SELECT AVG(lon) AS lon, 81 79 AVG(lat) AS lat … … 91 89 92 90 $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 } 94 102 } 95 103 … … 100 108 parent::show(); 101 109 102 echo json_encode($this-> markers);110 echo json_encode($this->datapoints); 103 111 } 104 112 } -
g-map/optionals/de.gmap.wbb/package.xml
r1232 r1236 10 10 <packagedescription language="it"><![CDATA[Questo pacchetto aggiunge alcune ottimizzazioni WBB al G-Map per WCF.]]></packagedescription> 11 11 <isunique>0</isunique> 12 <version>2.0.0 RC 1</version>12 <version>2.0.0 RC 3</version> 13 13 <date>DATE</date> 14 14 <plugin>com.woltlab.wbb</plugin> … … 33 33 </instructions> 34 34 35 <instructions type="update" fromversion="2.0.0 RC 1">35 <instructions type="update" fromversion="2.0.0 RC 2"> 36 36 <files>files.tar</files> 37 <languages languagecode="it">it.xml</languages> 37 38 </instructions> 38 39 </package> -
g-map/package.xml
r1232 r1236 10 10 <packagedescription language="it"><![CDATA[Questo pacchetto aggiunge una mappa di Google sul tuo forum.]]></packagedescription> 11 11 <isunique>1</isunique> 12 <version>2.0.0 RC 2</version>12 <version>2.0.0 RC 1</version> 13 13 <date>DATE</date> 14 14 <plugin>com.woltlab.wcf</plugin> … … 44 44 </instructions> 45 45 46 <instructions type="update" fromversion="2.0.0 RC 1">46 <instructions type="update" fromversion="2.0.0 RC 2"> 47 47 <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> 51 49 </instructions> 52 50 </package>
