-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmarkers_alternate_click.php
95 lines (81 loc) · 2.29 KB
/
markers_alternate_click.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
// This is for my examples
require( '_system/config.php' );
$relevant_code = array(
'\PHPGoogleMaps\Overlay\Marker',
'\PHPGoogleMaps\Overlay\MarkerDecorator'
);
// Autoload stuff
require( '_system/autoload.php' );
$map = new \PHPGoogleMaps\Map;
$locations = array(
'New York, NY',
'San Diego, CA',
'Dallas, TX',
'Seattle, WA',
'Miami, FL',
'Atlanta, GA',
'Boise, ID',
'Green Bay, WI',
'Detroit, MI',
'Denver, CO',
'Phoenix, AZ',
'Portland, OR',
'Chicago, IL',
'New Orleans, LA',
'San Francisco, CA',
'Las Vegas, NV'
);
foreach( $locations as $i => $location ) {
$marker = \PHPGoogleMaps\Overlay\Marker::createFromLocation( $location,
array(
'title' => $location,
'content' => "$location marker"
)
);
$marker_decorator = $map->addObject( $marker );
// You have to add the event handler after the marker has been added to a map
$click_handler = new \PHPGoogleMaps\Event\EventListener( $marker_decorator, 'click', 'function(){alert("You clicked " + '. $marker_decorator .'.content);}' );
$map->addObject( $click_handler );
}
// Diable infowindows so that only the alternate click handler gets triggered
$map->disableInfoWindows();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Alternate Click Handlers - <?php echo PAGE_TITLE ?></title>
<link rel="stylesheet" type="text/css" href="_css/style.css">
<?php $map->printHeaderJS() ?>
<?php $map->printMapJS() ?>
</head>
<body>
<h1>Alternate Click Handlers</h1>
<?php require( '_system/nav.php' ) ?>
<p>Steps for creating alternate click handlers</p>
<ol>
<li>Create a marker and add it to the map
<pre>
$marker = \PHPGoogleMaps\Overlay\Marker::createFromLocation( $location,
array(
'title' => 'title',
'content' => 'content'
)
);
$map->addObject( &$marker );
</pre>
</li>
<li>Create an event listener with the alternate click handler for the marker and and add that to the map
<pre>
$click_handler = new \PHPGoogleMaps\Event\EventListener( $marker, 'click', 'function(){alert("You clicked " + '. $marker .'.content);}' );
$map->addObject( $click_handler );
</pre>
</li>
<li>Optionally disable infowindows
<pre>$map->disableInfoWindows();</pre>
</li>
</ol>
<?php $map->printMap() ?>
</body>
</html>