Page 1 of 1

Creat a link to marker, need improves

Posted: 26 Jun 2011, 13:18
by rxcfirst
I spend hours trying to find a way to create a link to open a marker on the map, it turns out that the code that does it

Code: Select all

	google.maps.event.addListener(markerPhocaMarker1PlgPM1, 'click', function() {
   				infoPhocaWindow1PlgPM1.open(mapPhocaMapPlgPM1, markerPhocaMarker1PlgPM1 );
 					});

			google.maps.event.trigger(markerPhocaMarker1PlgPM1, 'click'); 
is part of "getPhocaMapPlgPM1()" function which create the whole map

The only idea I came up was to basically copy above code with every related variables, and put the into a new function, and this new function basically create the exactly same marker on top of the old one. Just went into the source code and copy the following section and put them into a new function

Code: Select all

	  var phocaImage7PlgPM1 = new google.maps.MarkerImage(YOUR OWN VALUE);
 			var phocaPoint1PlgPM1 = new google.maps.LatLng(YOUR OWN VALUE);
 			var markerPhocaMarker1PlgPM1 = new google.maps.Marker({
 					title:"YOUR OWN VALUE", 
   				icon:phocaImage7PlgPM1, 
   				position: phocaPoint1PlgPM1, 
  				 map: mapPhocaMapPlgPM1
 					});
 			var infoPhocaWindow1PlgPM1 = new google.maps.InfoWindow({
   				content:YOUR OWN VALUE
 					});
 					
 			google.maps.event.addListener(markerPhocaMarker1PlgPM1, 'click', function() {
   				infoPhocaWindow1PlgPM1.open(mapPhocaMapPlgPM1, markerPhocaMarker1PlgPM1 );
 					});

			google.maps.event.trigger(markerPhocaMarker1PlgPM1, 'click'); 
The problem is that for every marker on the map a function is required, and if any changes are made in the component, you have to change it in the function. :(

Is there not a better solution? :idea:

Re: Creat a link to marker, need improves

Posted: 27 Jun 2011, 04:20
by rxcfirst
I just found another alternative, if we can declare "markerPhocaMarker[id]PlgPM1" outside the function, then "google.maps.event.trigger(markerPhocaMarker[id]PlgPM1, 'click')" would work.

But I could not find the file that generates the following scripts

Code: Select all

 var markerPhocaMarker8PlgPM1 = new google.maps.Marker({
 title:"[your own value]", 
   icon:phocaImage7PlgPM1, 
   position: phocaPoint8PlgPM1, 
   map: mapPhocaMapPlgPM1
 });
If somehow I can remove "var" in above scripts, and declare "var markerPhocaMarker[id]PlgPM1" before the function, then the rest is easy.

Re: Creat a link to marker, need improves

Posted: 27 Jun 2011, 10:09
by rxcfirst
2 days of mucking around, finally. It should very easy for any devs but quite hard for someone like me who has no experience in php nor java. Anyway, just thought I'd share it, maybe consider make this as a standard feature.


public_html/administrator/components/com_phocamaps/helpers/phocamapsmap.php

added the following code that declare the marker outside the function for future reference.

Code: Select all

    function varMarker($name){

                $output .=' var markerPhocaMarker'.$name.$this->_id.';'."\n";
                $output .=' function openmarker'.$name.'() {'."\n";
                $output .=' google.maps.event.trigger(markerPhocaMarker'.$name.$this->_id.', \'click\');'."\n\n";
                $output .='}';
                return $output;
        }
remove "var" from

Code: Select all

$output .= ' var markerPhocaMarker'.$name.$this->_id.' = new google.maps.Marker({' ."\n" . ' title:"'.$title.'"'; 
/home/xtronix1/public_html/plugins/content/phocamaps/phocamaps.php

added the following code in the plugin to call above function before the make map function

Code: Select all

// define Markers
                if (isset($markerp) && !empty($markerp)) {
                         foreach ($markerp as $key => $markerV) {
				if ((isset($markerV->longitude) && $markerV->longitude != '')
				&& (isset($markerV->latitude) && $markerV->latitude != '')) {
                                         $output .= $map->varMarker($markerV->id);
                                         }
                         }
                }
As the result, I can do href="openmarker[id]()" to open any marker on map, now it only works if 1 map in the page, but that can be changed easily.

Re: Creat a link to marker, need improves

Posted: 22 Jul 2011, 02:47
by sd12013
Any idea on the proper URL syntax to create a link from my home page that will open an article with an embedded map with that specific marker info bubble open?

I was thinking something like site.com/index.php/2011-07-13-00-28-03/north-america&openmarker&id=2

But that didn't seem to work. I'm sure I just have the wrong syntax in the link. :x

Re: Creat a link to marker, need improves

Posted: 22 Jul 2011, 22:09
by sd12013
Can you give us an example of the exact code you attach in your href? Does the id number of the location go in the parenthesis?

And does your solution work if the link and the map are on the same page but the link is in a module? Or does the link have to be in the article as well?