User tests: Successful: Unsuccessful:
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: " + 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: " + 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?
Labels |
Added:
?
|
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.
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.
Easy | No | ⇒ | Yes |
There we go. Extra test for empty or non-empty events array added and passed.
Category | ⇒ | Libraries Unit Tests |
Sorry i couldn´t test successfully. By using your code above with the patch nothing happens by click on the markers.
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.
Oh sorry, don´t know how to apply something to JGoogleEmbedMaps. I think i tested it wrong.
Title |
|
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.
Title |
|
@Erftralle thanks for testing and your feedback.
Are there maybe more testers willing to cpy and paste the above example and report back?
I have tested this item successfully on 7bb7f93
It works.
I have tested this item successfully on 7bb7f93
@test works with the example code
I have tested this item successfully on 7bb7f93
@test successful
I have tested this item successfully on 7bb7f93
@test successful
Milestone |
Added: |
||
Status | Pending | ⇒ | Ready to Commit |
RTC. Thanks
Labels |
Added:
?
|
Labels |
Added:
?
|
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-10-25 15:47:54 |
Closed_By | ⇒ | roland-d |
Labels |
Removed:
?
|
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.