Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JGoogleEmbedMaps::addEventHandler() to map #6472

Closed
wants to merge 3 commits into from

Conversation

itbra
Copy link
Contributor

@itbra itbra commented Mar 17, 2015

I found that when creating a map it is not considered to bind events to it. Isn't it a tyical scenario to click on a map and not only zoom in but also trigger some action?

The Google Maps API presents as an example to create the map and immediately create the desired event which expects to receive the map created as reference to bind to. I added the functions required for map event handler creation and deletion (find a PR for marker events here). Also, the function creating the script was extended to consider registered map event handlers.

I tested this functionality by taking a view template and paste the following:

// Target element
echo '<h1>JGoogleEmbedMaps Test</h1>';
echo '<div class="row">';
echo    '<div class="col col-xs-12">';
echo        '<div id="map" style="height:500px; background:gainsboro; border:gray">LOADING ...</div>';
echo    '</div>';
echo    '<div class="col col-xs-12">';
echo        '<h5>Monitor</h5>';
echo        '<p id="monitor" style="padding:1em 0.5em; border:1px solid gainsboro; border-radius:3px"></p>';
echo    '</div>';
echo '</div>';

// Config
$options = new JRegistry(array(
    'key'         => '',
    'mapid'       => 'map',
    'mapclass'    => 'mapclass'
));

// Get instance
$google = new JGoogle($options);
$map = $google->embed('Maps');

// Define load type
$map->setAutoload('jquery');

$map->setMapType('HYBRID');
$map->setCenter(array('50','10'), null);
$map->setZoom('3');

// Marker configuration
$markerOptions = array(
    'clickable' => true,
    'draggable' => false,
    'opacity'   => 0.75,
    'optimized' => true,
    'visible'   => true
);

// Add events handlers
$map->addEventHandler('bounds_changed',     'function(){ document.getElementById("monitor").innerHTML = "map bounds_changed event"; }');
$map->addEventHandler('center_changed',     'function(){ document.getElementById("monitor").innerHTML = "map center_changed event"; }');
$map->addEventHandler('click',              'function(){ alert("map click event"); }');
$map->addEventHandler('dblclick',           'function(){ alert("map dblclick event"); }');
$map->addEventHandler('drag',               'function(){ document.getElementById("monitor").innerHTML = "map drag event"; }');
$map->addEventHandler('dragend',            'function(){ document.getElementById("monitor").innerHTML = "map dragend event"; }');
$map->addEventHandler('dragstart',          'function(){ document.getElementById("monitor").innerHTML = "map dragstart event"; }');
$map->addEventHandler('heading_changed',    'function(){ document.getElementById("monitor").innerHTML = "map heading_changed event"; }');
$map->addEventHandler('idle',               'function(){ document.getElementById("monitor").innerHTML = "map idle event"; }');
$map->addEventHandler('maptypeid_changed',  'function(){ document.getElementById("monitor").innerHTML = "map maptypeid_changed event"; }');
$map->addEventHandler('mousemove',          'function(){ document.getElementById("monitor").innerHTML = "map mousemove event"; }');
$map->addEventHandler('mouseout',           'function(){ document.getElementById("monitor").innerHTML = "map mouseout event"; }');
$map->addEventHandler('mouseover',          'function(){ document.getElementById("monitor").innerHTML = "map mouseover event"; }');
$map->addEventHandler('projection_changed', 'function(){ document.getElementById("monitor").innerHTML = "map projection_changed event"; }');
$map->addEventHandler('resize',             'function(){ document.getElementById("monitor").innerHTML = "map resize event"; }');
$map->addEventHandler('rightclick',         'function(){ document.getElementById("monitor").innerHTML = "map rightclick event"; }');
$map->addEventHandler('tilesloaded',        'function(){ document.getElementById("monitor").innerHTML = "map tilesloaded event"; }');
$map->addEventHandler('tilt_changed',       'function(){ document.getElementById("monitor").innerHTML = "map tilt_changed event"; }');
$map->addEventHandler('zoom_changed',       'function(){ document.getElementById("monitor").innerHTML = "map zoom_changed event"; }');

// Prepare custom script(s)
// initialization callback
$callback =
<<<ENDSCRIPT
window.gm = map;   // Will execute after initialisation to add reference to the created map as a global.
(function($, gm, element) {
    $('#monitor').append('<em>Calling back</em>');
})(jQuery.noConflict(), window.google || {}, document.getElementById({$options->get('mapid')}));
ENDSCRIPT;

// Register custom script(s)
$map->setAdditionalJavascript($callback);

$map->echoHeader();
$map->echoBody();

What do you think about this?

If somebody experienced in writing Unit tests might help out to write 3 test for the 3 new functions i would really appreciate your support as i have no experience in that.

@@ -318,6 +318,71 @@ public function setCenter($location, $title = true, $markeroptions = array())
}

/**
* Method to add and event handler to the map.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a misspelling, an event

@Erftralle
Copy link
Contributor

Thanks for this usefull addition.

@test: Works fine for me.

@Rivaner
Copy link

Rivaner commented Oct 24, 2015

I have tested this item ✅ successfully on 72107d0

Patch works!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6472.

1 similar comment
@farrelljsec
Copy link

I have tested this item ✅ successfully on 72107d0

Patch works!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6472.

@zero-24 zero-24 added this to the Joomla! 3.5.0 milestone Oct 24, 2015
@zero-24
Copy link
Contributor

zero-24 commented Oct 24, 2015

RTC. Thanks.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6472.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Oct 24, 2015
@roland-d
Copy link
Contributor

Thanks everybody. Merged into 3.5-dev with commit fbd77ac

@roland-d roland-d closed this Oct 25, 2015
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Oct 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants