Posted by mshaver on June 6, 2006 at 6:42pm
Jump to:
| Project: | GMap Module |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | webgeer |
| Status: | active |
Issue Summary
Is it possible to open an info window from a link on another page?
Comments
#1
I don't know what you mean?
Could you give an example of how it would work?
Thanks
James
(webgeer)
#2
On your GMap demo page you have a marker with a number "1" and when you click on the marker it opens the info window with "Kits Pool" in the bubble. What I would like to do is have a link to that specific marker, which would open the info window on the map page. This link would be on another page or even in a block next to the map. Sort of like this functionality:
http://www.econym.demon.co.uk/googlemaps/examples/map2.htm
Great module by the way!
#3
I understand. That is a good idea.
I've thought about how this idea can be implemented. I think it can be done.
How this will work is that the php associative array will have a new item 'id'. In js the overlay will then be assigned to the js variable gmapMarker[id]. Then for your link you would be able to setup a <a onClick="gmapOpenInfo(gmapMarker['myid']);"> (Or something like that)
However, this will have to wait until I do a big js reorganization that I am planning. This will probably be a few weeks away...
James
#4
I've got a similar need and I created a brute force solution that could probably use some work. I thought I'd post here to share where I'm at in case it is useful. Additionally, any suggestions concerning my methods are welcome.
I'm working on a module that allows users to search for spaces using a combined list and gmap interface. The gmap is being built by a function in my module that invokes gmap functions. I need to create a link next to each node that opens the info window for that corresponding marker. I've got this working, but I wanted to check and see if there is a better way to do this. Here is my current (probably flawed) strategy:
The list of nodes comes from a theme function in my module. (I'm not currently using views.module for a number of reasons.) While iterating through the nodes to display their information, I am checking for $node->location['latitude']. If present, I add a line of javascript that packs information for the node into a javascript array. I also add a link which calls a javascript function that looks for this array entry and opens an info window. It looks something like this:
function theme_spacefinder_results($nodes = array(), $center = array()){
// additional code here
$js_output = '';
$node_count = 0; // this allows us to match the markers up
// go through each returned node
foreach($nodes as $s){
$list_output = '';
// add mapping elements if we have location data
// TODO: This linkk to js probably doesn't degrade gracefully
if($s->location['latitude']){
$node_count++;
$js_output .= ' output = \''. theme_spacefinder_marker_html($s) .'\';'."\n";
$js_output .= ' arr['.$s->nid.'] = new Array("'. $s->location['latitude'] .'","'. $s->location['longitude'] .'",output);'."\n";
$list_output .= theme_spacefinder_list_maplink($s->nid, $node_count);
$list_output .= '<div class="spacefinder_result_text_mapped">'."\n";
}
else {
// by defaul these classes are the same, but I've broken them out just in case
$list_output .= '<div class="spacefinder_result_text_unmapped">'."\n";
$additional_notes = t('No address was supplied.');
}
// etc.
$rows[] = array($list_output);
}
$output .= "\n<script>\n";
$output .= 'function spacefinder_click_list(nid){'."\n";
$output .= ' var arr = new Array();'."\n";
$output .= $js_output;
$output .= ' viewmap.openInfoWindowHtml(new GLatLng(arr[nid][0], arr[nid][1]), arr[nid][2]);'."\n";
$output .= '}'."\n";
$output .= '</script>'."\n";
$output .= theme('table', $header, $rows)."\n";
}
/**
*
* TODO: ie makes gray backgrounds for these markers and needs png fix
*/
function theme_spacefinder_list_maplink($nid, $node_count){
global $base_url;
$markername = variable_get('spacefinder_markername', 'number');
$output = '';
$output .= '<div class="spacefinder_maplink"><a href="JavaScript:spacefinder_click_list(\''. $nid .'\')" id="list_link_'.$nid.'">';
//$output .= $node_count;
if (file_exists(variable_get('gmap_markerfiles',drupal_get_path('module', 'gmap').'/markers').'/'.$markername.$node_count.'.png')) {
$mymarker=$base_url.'/'.variable_get('gmap_markerfiles',drupal_get_path('module', 'gmap') .'/markers').'/'.$markername.$node_count.'.png';
}
elseif (file_exists(variable_get('gmap_markerfiles',drupal_get_path('module', 'gmap').'/markers').'/'.$markername.'.png')) {
$mymarker=$base_url.'/'.variable_get('gmap_markerfiles',drupal_get_path('module', 'gmap') .'/markers').'/'.$markername.'.png';
}
$output .= '<img src="'. $mymarker .'" border="0" alt="'. $node_count .'" />'."\n";
$output .= '</a></div>'."\n";
return $output;
}
This is pretty cutup, so my apologies if there is something missing and it doesn't make sense, but hopefully it will give you enough of an idea of my current method.
As I understood it, there was no way to reference the info window object / information that gmap uses, so I had to make my own. If there's something that I missed, please let me know.
I'm also not sure about the javascript method I used, as it's probalby not in line with drupal best practices.
Any advice would be appreciated. Otherwise, please consider this a use scenario to consider while you are working on the javascript variable redesign that you mentioned above.
ps- After we complete this project, we are considering releasing the module as a contrib.
#5
Did this ever get released?
We are looking for the same function and will try this on our site. But a modules would be nice ( -:
Thanks
#6
I'm looking for the same function too. Was this release or some more info on this?
#7
Check out www.buyctgrown.com do a search on say kale.
I would like to release this as a module / view
#8
This is a fantastic feature - I'd love to use it if you release it.
And a great website - good to see seasonal food being promoted.
#9
I would love to release it.
It is somewhat messy though.
Should I just create a project page and put it on there as is?
--
#10
I've never done this, so can't give you any concrete advice.
The procedure for adding a standalone module is at http://www.betterenough.org/node/56 and http://drupal.org/contributors-guide
However it is probably worth doing something that ties it in more closely with the GMap module as it builds on this module. Try getting in touch with bdragon either through his profile (http://drupal.org/user/53081) or on IRC (he's on #drupal a lot) and ask his advice on whether to add it as a patch to GMap, or to add it to gmap_addons.module (http://drupal.org/project/gmap_addons).
I'm just starting work with another addon to GMap that was developed by someone else, which I'm helping to contribute back to the module - so please let me know how you get on and we can help each other with this!
Cheers,
Thomas
#11
I will contact him now.
Keep in touch if I fall behind on this.
The best thing for this is to get it so others can work on it.
Right now it is an ugly hack in the template.php file.
#12
Nice to know I wasn't the only person intrigued by this idea.
The Atlanta Journal-Constitution has a very nice example of this idea in action. You can click on any marker to get an info bubble, but you can also click on any of the text links next to the map to get the corresponding bubble to pop up.
Since it's a working example, someone might also be able to figure out how to reverse-engineer it, too.
#13
I found a bit more information about this from digging through groups.google.com. From this thread it looks like this code snippet may a start toward the answer:
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(mystring);
gmarkers[index] = marker;
});
The testing page mentioned in this thread is still up: http://alx.al.umces.edu/~jchurch/testing/research_sitemap.html
If you click on any of the text links below the map, the correct infoWindow opens.
#14
Full support of this feature!
Thanks for the module btw.
#15
This is a really cool feature. Any update on its status?
#16
Subscribing
#17
http://drupal.org/node/791998#comment-2959290
try this solution
#18
That worked great. Thanks. I just placed this javascript in my page.tpl.php:
<script>
$(document).ready(function(){
$('.views-field-nothing a').each(function(i){
$(this).bind('click', function(){
GEvent.trigger(Drupal.settings.gmap.auto1map.markers[i].marker, "click");
return false;
});
});
});
</script>
Now, I just can't get it to zoom to the right marker. I have this set on the link:
onClick=" Drupal.gmap.getMap('gmap-auto1map-gmap0').map.setZoom(17)But, it doesn't seem to zoom to the proper marker. Any ideas?