In the action:
// parameters: zoom level, lat, lng, options
$this->gMap = new GMap(
array(
'zoom'=>4,
'center_lat'=>45,
'center_lng'=>8,
'control'=>'new google.maps.SmallMapControl()'
)
);
// some places in the world
$coordinates = array(
array(51.245475,6.821373),
array(46.262248,6.115969),
array(48.848959,2.341577),
array(48.718952,2.219180),
array(47.376420,8.547995)
);
// adds a variable "markers" defined on the global level
$this->gMap->addGlobalVariable('markers','new Array()');
// creates a custom icon for markers
$gMapIcon = new GMapIcon(
'nice_icon',
'/sfEasyGMapPlugin/images/nice_icon.png',
array(
'width'=>18,
'height'=>25,
'info_window_anchor_x'=>9,
'info_window_anchor_y'=>25
)
);
// creates two custom event listeners
$gMapEvent1 = new GMapEvent(
'mouseover',
"document.getElementById('console_div').innerHTML = 'Mouse over marker number '+this.num;"
);
$gMapEvent2 = new GMapEvent(
'mouseout',
"document.getElementById('console_div').innerHTML = '';"
);
foreach ($coordinates as $key=>$coordinate)
{
// parameters: lat, lng, marker's javascript object's name, icon object
$gMapMarker = new GMapMarker($coordinate[0],$coordinate[1],'markers['.$key.']',$gMapIcon);
$gMapMarker->addHtmlInfoWindow('<b>Coordinates:</b><br />'.implode(', ',$coordinate));
// will add a custom property to the marker's javascript object
$gMapMarker->setCustomProperty('num',$key);
// binds the event listeners to the marker
$gMapMarker->addEvent($gMapEvent1);
$gMapMarker->addEvent($gMapEvent2);
$this->gMap->addMarker($gMapMarker);
}