Skip to content

Commit

Permalink
JGoogleEmbedMaps::addEventHandler() to map Fixes #6472
Browse files Browse the repository at this point in the history
  • Loading branch information
itbra authored and roland-d committed Oct 25, 2015
1 parent 269b781 commit fbd77ac
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions libraries/joomla/google/embed/maps.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,71 @@ public function setCenter($location, $title = true, $markeroptions = array(), $m
return $this;
}

/**
* Method to add an event handler to the map.
* Event handlers must be passed in either as callback name or fully qualified function declaration
*
* @param string $type The event name
* @param string $function The event handling function body
*
* @example to add an event call:
* $map->addEventHandler('click', 'function(){ alert("map click event"); }');
*
* @return JGoogleEmbedMaps The object for method chaining
*
* @since 12.3
*/
public function addEventHandler($type, $function)
{
$events = $this->listEventHandlers();

$events[$type] = $function;

$this->setOption('events', $events);

return $this;
}

/**
* Method to remove an event handler from the map
*
* @param string $type The event name
*
* @example to delete an event call:
* $map->deleteEventHandler('click');
*
* @return string The event handler content
*
* @since 12.3
*/
public function deleteEventHandler($type = null)
{
$events = $this->listEventHandlers();

if ($type === null || !isset($events[$type]))
{
return;
}

$event = $events[$type];
unset($events[$type]);
$this->setOption('events', $events);

return $event;
}

/**
* List the events added to the map
*
* @return array A list of events
*
* @since 12.3
*/
public function listEventHandlers()
{
return $this->getOption('events') ? $this->getOption('events') : array();
}

/**
* Add a marker to the map
*
Expand Down Expand Up @@ -587,6 +652,16 @@ public function getHeader()
$setup .= '};';
$setup .= "var map = new google.maps.Map(document.getElementById('{$id}'), mapOptions);";

$events = $this->listEventHandlers();

if (isset($events) && count($events))
{
foreach ($events as $type => $handler)
{
$setup .= "google.maps.event.addListener(map, '{$type}', {$handler});";
}
}

$markers = $this->listMarkers();

if (isset($markers) && count($markers))
Expand Down

0 comments on commit fbd77ac

Please sign in to comment.