[Improvement SOLVED] Close marker info when clicking another

Phoca Maps - displaying maps in Joomla! CMS
Yomas
Phoca Newbie
Phoca Newbie
Posts: 1
Joined: 17 Oct 2012, 15:13

[Improvement SOLVED] Close marker info when clicking another

Post 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 ^^
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

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

Post by Jan »

Hi, thank you for the guide.

Jan
If you find Phoca extensions useful, please support the project
talora
Phoca Newbie
Phoca Newbie
Posts: 9
Joined: 13 Aug 2012, 19:19

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

Post 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
talora
Phoca Newbie
Phoca Newbie
Posts: 9
Joined: 13 Aug 2012, 19:19

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

Post 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
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

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

Post by Jan »

Hi, implemented in 2.0.6

Jan
If you find Phoca extensions useful, please support the project
talora
Phoca Newbie
Phoca Newbie
Posts: 9
Joined: 13 Aug 2012, 19:19

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

Post by talora »

Nice to hear that! :)
Eddie-DC
Phoca Newbie
Phoca Newbie
Posts: 8
Joined: 09 Feb 2013, 06:13

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

Post 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
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

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

Post by Jan »

Try to see if you get e.g. some javascript error on your site, maybe this can cause it :idea:

Jan
If you find Phoca extensions useful, please support the project
Eddie-DC
Phoca Newbie
Phoca Newbie
Posts: 8
Joined: 09 Feb 2013, 06:13

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

Post 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.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

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

Post by Jan »

Hmm, testing now and get no such problems, really no idea what can be wrong, will test it in different browsers too
If you find Phoca extensions useful, please support the project
Post Reply