? ? Success

User tests: Successful: Unsuccessful:

avatar itbra
itbra
10 Mar 2015

I found that when adding a marker to the map it is not considered to bind events to it. Isn't it a tyical scenario to click on a marker to show a balloon with short info or a link to more details?

The Google Maps API presents as an example to create the marker and immediately create the desired event which expects to receive the marker created as reference to bind to. I extended those functions responsible for marker creation by adding them another argument for the events (find a PR for map events here). Also, the function creating the script was extended to evaluate the currently set markers not only for their options but also for events to bind.

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->setZoom('3');

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

$map->setCenter(array('51.165691','10.451526'), 'Germany', $markerOptions,
array(
    'click' => 'function(e) {
        console.log("event: ", e);
        map.setCenter(this.getPosition());
        document.getElementById("monitor").innerHTML = "Clicked:&nbsp;" + this.title;
    }'
));

// Add markers
$map->addMarker(array('46.227638','2.213749'),  'France');  
$map->addMarker(array('60.472023','8.468946'),  'Norway', $markerOptions);
$map->addMarker(array('51.919437','19.145136'), 'Poland', $markerOptions, array());
$map->addMarker(array('41.871941','12.567380'), 'Italy',  $markerOptions, array(
    'click' => 'function(e) {
        console.log("event: ", e);
        map.setCenter(this.getPosition());
        document.getElementById("monitor").innerHTML = "Clicked:&nbsp;" + this.title;
    }'
));

// Prepare 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>Callback executed</em>')
})(jQuery.noConflict(), window.google || {}, document.getElementById({$options->get('mapid')}));
ENDSCRIPT;

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

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

So far this works. I wonder why this hasn't been considered yet. What do you think about this?

avatar itbra itbra - open - 10 Mar 2015
avatar joomla-cms-bot joomla-cms-bot - change - 10 Mar 2015
Labels Added: ?
avatar itbra itbra - change - 11 Mar 2015
The description was changed
avatar itbra
itbra - comment - 11 Mar 2015

The tests appear to fail although the code works properly. Can somebody please tell me what causes the test to fail? Is there probably a change required in the test class? Mabe current tests don't consider the new arguments and therefore cause the test to fail?
I have no idea, but this message from travis Failed asserting that two arrays are equal. makes me to assume that.

avatar Hackwar
Hackwar - comment - 11 Mar 2015

The tests fail because you have a PHP syntax error in your changed test file on line 360. You are doing a "somethin" => "value" outside of an array scope. Please fix that.

avatar itbra
itbra - comment - 12 Mar 2015

Thanks for pointing me to the issue. Finally its passing all tests. I'll add one more test case with a non-empty events-array.

avatar zero-24 zero-24 - change - 12 Mar 2015
Easy No Yes
avatar itbra
itbra - comment - 12 Mar 2015

There we go. Extra test for empty or non-empty events array added and passed.

avatar zero-24 zero-24 - change - 12 Mar 2015
Category Libraries Unit Tests
avatar designbengel
designbengel - comment - 14 Mar 2015

Sorry i couldn´t test successfully. By using your code above with the patch nothing happens by click on the markers.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6381.
avatar designbengel designbengel - test_item - 14 Mar 2015 - Tested unsuccessfully
avatar itbra
itbra - comment - 14 Mar 2015

Of course it works. I tested it right this second via copy+paste the above example 1:1. You have to apply the patch to JGoogleEmbedMaps first so that the events are registered on marker creation. Click the markers and watch the text changing in the monitor container or on the map - when you click one of the two having an event bound.
NOTE:
Only 2 out of the 5 markers receive an event in my example just to demonstrate the different ways of marker creation. One changes the map center and the other outputs Clicked: Test Marker 4 to the monitor container.

avatar designbengel
designbengel - comment - 14 Mar 2015

Oh sorry, don´t know how to apply something to JGoogleEmbedMaps. I think i tested it wrong.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6381.
avatar itbra itbra - change - 16 Mar 2015
Title
Bind event(s) to map marker
Bind event(s) to map and marker
avatar itbra
itbra - comment - 16 Mar 2015

After integrating the event binding to markers and fixing the corresponding unit tests i have now created another PR to add event handlers for map events.

avatar itbra itbra - change - 17 Mar 2015
Title
Bind event(s) to map and marker
JGoogleEmbedMaps::addMarker with event(s)
avatar Erftralle
Erftralle - comment - 18 Mar 2015

What do you think about this?

I find it a usefull addition, thanks!

@test: Works fine for me.

avatar itbra
itbra - comment - 19 Mar 2015

@Erftralle thanks for testing and your feedback.
Are there maybe more testers willing to cpy and paste the above example and report back?

avatar Rivaner Rivaner - test_item - 24 Oct 2015 - Tested successfully
avatar Rivaner
Rivaner - comment - 24 Oct 2015

I have tested this item :white_check_mark: successfully on 7bb7f93

It works.


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

avatar DavidTrenkle DavidTrenkle - test_item - 24 Oct 2015 - Tested successfully
avatar DavidTrenkle
DavidTrenkle - comment - 24 Oct 2015

I have tested this item :white_check_mark: successfully on 7bb7f93

@test works with the example code


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

avatar KlausKrippeit KlausKrippeit - test_item - 24 Oct 2015 - Tested successfully
avatar KlausKrippeit
KlausKrippeit - comment - 24 Oct 2015

I have tested this item :white_check_mark: successfully on 7bb7f93

@test successful


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

avatar KlausKrippeit KlausKrippeit - test_item - 24 Oct 2015 - Tested successfully
avatar KlausKrippeit
KlausKrippeit - comment - 24 Oct 2015

I have tested this item :white_check_mark: successfully on 7bb7f93

@test successful


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

avatar zero-24 zero-24 - change - 24 Oct 2015
Milestone Added:
Status Pending Ready to Commit
avatar zero-24
zero-24 - comment - 24 Oct 2015

RTC. Thanks


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

avatar joomla-cms-bot joomla-cms-bot - change - 24 Oct 2015
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 24 Oct 2015
Labels Added: ?
avatar roland-d
roland-d - comment - 25 Oct 2015

Thanks everybody. Merged into 3.5-dev with commit 269b781

avatar roland-d roland-d - change - 25 Oct 2015
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2015-10-25 15:47:54
Closed_By roland-d
avatar wilsonge wilsonge - change - 17 Jan 2016
Labels Removed: ?

Add a Comment

Login with GitHub to post a comment