|
60ae102e
»
|
tuupola |
2008-10-30 |
First working marker cluste... |
1 |
<?php |
| |
2 |
|
| |
3 |
/* |
| |
4 |
* Google_Maps_Clusterer_Distance |
| |
5 |
* |
| |
6 |
* Copyright (c) 2008 Mika Tuupola |
| |
7 |
* |
| |
8 |
* Licensed under the MIT license: |
| |
9 |
* http://www.opensource.org/licenses/mit-license.php |
| |
10 |
* |
| |
11 |
* Project home: |
| |
12 |
* http://www.appelsiini.net/projects/google_maps |
| |
13 |
* |
| |
14 |
* Revision: $Id$ |
| |
15 |
* |
| |
16 |
*/ |
| |
17 |
|
| |
18 |
require_once 'Google/Maps/Overload.php'; |
| |
19 |
|
| |
20 |
class Google_Maps_Clusterer_Distance extends Google_Maps_Overload { |
| |
21 |
|
|
3e6ded20
»
|
tuupola |
2008-10-31 |
Make clusterer more configu... |
22 |
protected $distance = 20; |
| |
23 |
protected $unit = 'pixel'; |
| |
24 |
protected $color = 'blue'; |
| |
25 |
protected $marker_sizes = array('mid','mid','mid','mid','mid','','','',''); |
|
60ae102e
»
|
tuupola |
2008-10-30 |
First working marker cluste... |
26 |
|
| |
27 |
public function process(array $markers, Google_Maps_Static $map) { |
| |
28 |
$clustered = array(); |
| |
29 |
$distance = $this->getDistance(); |
| |
30 |
$unit = $this->getUnit(); |
| |
31 |
while (count($markers)) { |
| |
32 |
$marker = array_pop($markers); |
| |
33 |
$cluster = new Google_Maps_Marker_Cluster(); |
|
3e6ded20
»
|
tuupola |
2008-10-31 |
Make clusterer more configu... |
34 |
foreach ($markers as $key => $target) { |
|
60ae102e
»
|
tuupola |
2008-10-30 |
First working marker cluste... |
35 |
if (($distance > $marker->distanceTo($target, $unit, $map))) { |
|
3e6ded20
»
|
tuupola |
2008-10-31 |
Make clusterer more configu... |
36 |
unset($markers[$key]); |
|
60ae102e
»
|
tuupola |
2008-10-30 |
First working marker cluste... |
37 |
$amount = $cluster->addMarker($target); |
| |
38 |
/* Marker can display max number 9, so break out of */ |
| |
39 |
/* the loop when we reach it. One is added outside of the loop. */ |
| |
40 |
if (8 == $amount) { |
| |
41 |
break 1; |
| |
42 |
} |
| |
43 |
|
| |
44 |
} |
| |
45 |
} |
| |
46 |
|
| |
47 |
if (count($cluster->getMarkers()) > 0) { |
|
3e6ded20
»
|
tuupola |
2008-10-31 |
Make clusterer more configu... |
48 |
$sizes = $this->getMarkerSizes(); |
| |
49 |
$count = $cluster->addMarker($marker); |
| |
50 |
$cluster->setCharacter($count); |
|
60ae102e
»
|
tuupola |
2008-10-30 |
First working marker cluste... |
51 |
$cluster->setColor('blue'); |
|
3e6ded20
»
|
tuupola |
2008-10-31 |
Make clusterer more configu... |
52 |
$cluster->setSize($sizes[$count - 1]); |
|
60ae102e
»
|
tuupola |
2008-10-30 |
First working marker cluste... |
53 |
$clustered[] = $cluster; |
| |
54 |
} else { |
| |
55 |
$clustered[] = $marker; |
| |
56 |
}; |
| |
57 |
} |
| |
58 |
return $clustered; |
| |
59 |
} |
|
3e6ded20
»
|
tuupola |
2008-10-31 |
Make clusterer more configu... |
60 |
|
|
60ae102e
»
|
tuupola |
2008-10-30 |
First working marker cluste... |
61 |
} |