Page 1 of 1

Maps API Marker Overlay

Posted: 22 Aug 2013, 14:58
by Unitycorn
Hi,

I'm using joomla 2.5.11 with the Phoca Maps 2.0.6 module and plugin.

Since i like to have "control" over the markers, i'd like to use the overlay function setMap(map) (google maps API).

When i got it right, i need to have an javascript array of all the markers shown in the map.

Can i use markerArray.push(markerV) somehow after the marker is created via $map->setMarker(...) in the phocamaps.php file?

Please help!

Re: Maps API Marker Overlay

Posted: 23 Aug 2013, 17:06
by Jan
Hi, no experiences with this feature, so yes, the php code needs to be customized but I am not able to say which part :idea:
Jan

Re: Maps API Marker Overlay

Posted: 27 Aug 2013, 13:22
by Unitycorn
Hi again.

I've found a solution, so i post it here (maybe it's useful for someone with similar problems):

First, to define our javaScript array to store the markers in, just after

Code: Select all

$output .= $map->startJScData();
add the line

Code: Select all

$output .= "markersArray = []; \n";



Now that we have our array, we can fill it by adding

Code: Select all

$output .= "markersArray.push(markerPhocaMarker".$markerV->id."PlgPM1);\n";
right after

Code: Select all

$map->setMarker($markerV->id,$markerV->title,$markerV->description,$markerV->latitude, $markerV->longitude, $iconOutput['icon'], $iconOutput['iconid'], $text, $markerV->contentwidth, $markerV->contentheight,  $markerV->markerwindow,  $iconOutput['iconshadow'], $iconOutput['iconshape']);


I guess it's not working if you have more than 1 map on your website, because "M1" stands for "Map One". So i case of multiple maps, this has to be more dynamic.

Because i wanted to use the overlay-function for displaying/hiding specific categories, i had to store the catid of each marker with it into the array.

To do so, i added the line

Code: Select all

$output .= "markerPhocaMarker".$markerV->id."PlgPM1.category=".$markerV->catid.";\n";
before i "pushed" the marker into the array.

Now you can loop through your markersArray and manipulate each marker's behavior.

For example:

Code: Select all

var category = 2;
for (var i = 0; i < markersArray.length; i++ ) {
           if(markersArray[i].category == category){
               markersArray[i].setMap(null);
           }
}
to hide each marker with catid = 2.

I hope this was helpful, i'll add the URL to the website when it goes public, so you can see the result. :wink: