Page 1 of 2

[Improvement SOLVED] Close marker info when clicking another

Posted: 17 Oct 2012, 15:48
by Yomas
Hi all !

I've been searching on the forum how to make a marker infowindow close when opened, when you click on another marker.
I've solved it and thought maybe it could help some !

In administrator/component/com_phocamaps/helpers/phocamapmaps.php ->

Line 305

Code: Select all

	function setMap() {

		// Not var as the map is global variable so not disable the global effect

		return 'var myinfowindow;'."\n".$this->_map.' = new google.maps.Map(document.getElementById(\''.$this->_name.'\'), '.$this->_options.');'."\n";

		//adds a global variable called myinfowindow

	}

Line 759

Code: Select all

		$output .= ' google.maps.event.addListener(markerPhocaMarker'.$name.$this->_id.', \'click\', function() {'."\n"
		
			.'	if(myinfowindow) myinfowindow.close();'."\n"//check if windowinfo is opened and close it before opening another


			.'   infoPhocaWindow'.$name.$this->_id.'.open('.$this->_map.', markerPhocaMarker'.$name.$this->_id.' );'."\n"
			
			.'myinfowindow = infoPhocaWindow'.$name.$this->_id."\n" //pass the infoPhocaWindow elements to myinfowindow

			.' });'."\n";

		if ($open) {

			$output .= '   google.maps.event.trigger(markerPhocaMarker'.$name.$this->_id.', \'click\');'."\n";

		}

		return $output;

	}

And that's it !!

Enjoy and please comment if you have a better idea ^^

Re: [Improvement SOLVED] Close marker info when clicking ano

Posted: 19 Oct 2012, 16:25
by Jan
Hi, thank you for the guide.

Jan

Re: [Improvement SOLVED] Close marker info when clicking ano

Posted: 20 Nov 2012, 13:01
by talora
Hi!

I liked your idea a lot! However, the file name/path seems to be incorrect. I found in

administrator\components\com_phocamaps\helpers

the file "phocamapsmap.php" to be the most probable one, but the line numbers don't match. I'm running PhocaMaps 2.0.5.

Could you please give me some advice?


Thanks!

Best regards,

Luis Talora

Re: [Improvement SOLVED] Close marker info when clicking ano

Posted: 20 Nov 2012, 13:52
by talora
Nevermind... I've got it! Thanks a lot for this nice improvement! What I did:

1. I've opened "administrator\components\com_phocamaps\helpers\phocamapsmap.php".
2. Around the line 151, I've replace the entire original funcion setMap() with the following one:

Code: Select all

	function setMap() {
		// Not var as the map is global variable so not disable the global effect
		// By Luis Talora - https://www.phoca.cz/forum/viewtopic.php?f=38&t=21288
		//--- Original --- return $this->_map.' = new google.maps.Map(document.getElementById(\''.$this->_name.'\'), '.$this->_options.');'."\n";
		//adds a global variable called myinfowindow
		return 'var myinfowindow;'."\n".$this->_map.' = new google.maps.Map(document.getElementById(\''.$this->_name.'\'), '.$this->_options.');'."\n";
	}
3. Around the line 379, I´ve replace this (original) code:

Code: Select all

		$output .= ' google.maps.event.addListener(markerPhocaMarker'.$name.$this->_id.', \'click\', function() {'."\n"
			.'   infoPhocaWindow'.$name.$this->_id.'.open('.$this->_map.', markerPhocaMarker'.$name.$this->_id.' );'."\n"
			.' });'."\n";
		if ($open) {
			$output .= '   google.maps.event.trigger(markerPhocaMarker'.$name.$this->_id.', \'click\');'."\n";
		}
		return $output;
With this one:

Code: Select all

		$output .= ' google.maps.event.addListener(markerPhocaMarker'.$name.$this->_id.', \'click\', function() {'."\n"
		.'   if(myinfowindow) myinfowindow.close();'."\n"//check if windowinfo is opened and close it before opening another
		.'   infoPhocaWindow'.$name.$this->_id.'.open('.$this->_map.', markerPhocaMarker'.$name.$this->_id.' );'."\n"
		.'myinfowindow = infoPhocaWindow'.$name.$this->_id."\n" //pass the infoPhocaWindow elements to myinfowindow
		.' });'."\n";
		if ($open) {
			$output .= '   google.maps.event.trigger(markerPhocaMarker'.$name.$this->_id.', \'click\');'."\n";
		}
		return $output;
And that's it!

Thank you again, Yomas, for this nice trick!

Mr. Jan: if you allow me, I kindly suggest this to become a permanent improvement, for future releases... Maybe, with the option to disable/enable it...

Regards,

Luis Talora

Re: [Improvement SOLVED] Close marker info when clicking ano

Posted: 21 Nov 2012, 21:37
by Jan
Hi, implemented in 2.0.6

Jan

Re: [Improvement SOLVED] Close marker info when clicking ano

Posted: 21 Nov 2012, 22:56
by talora
Nice to hear that! :)

Re: [Improvement SOLVED] Close marker info when clicking ano

Posted: 23 Feb 2013, 20:52
by Eddie-DC
Thanks for the great component Jan.
The "Close Opened Window" doesn't seem to work. I selected "Yes - Close Opened Window" and clear cache but it doesn't seem to work. When I select another marker, the previous one doesn't close as supposed to. Is anyone having this issue? I also have the latest component 2.0.6. Thanks

Re: [Improvement SOLVED] Close marker info when clicking ano

Posted: 24 Feb 2013, 21:50
by Jan
Try to see if you get e.g. some javascript error on your site, maybe this can cause it :idea:

Jan

Re: [Improvement SOLVED] Close marker info when clicking ano

Posted: 24 Feb 2013, 23:37
by Eddie-DC
I see, yea I initially thought there was a conflict with other modules and possibly javascript errors. However, I disabled all components and modules and I still have the same issue, the previous marker doesn't close when opening a new marker.

Re: [Improvement SOLVED] Close marker info when clicking ano

Posted: 28 Feb 2013, 18:33
by Jan
Hmm, testing now and get no such problems, really no idea what can be wrong, will test it in different browsers too