Gmap3 - Forum

Gmap3 exchange platform

You are not logged in.

Ads
(server costs 27.50€ per month)


#1 2012-09-27 20:48:46

bgordon
Member
Registered: 2012-09-27
Posts: 3

Help With Trigger On External Click - Think I Am Close

1.  Lovin' GMAP3.  Thanks for developing it.  Very versatile and I have got my project (phase 1) built in no time and working great.

2. Cannot quite figure out how to trigger the click event on a marker from an external link via javascript.  I have tried the v3 api syntax but suspect that I am missing something in relation to the GMAP3 library.  Could anyone help me out here?  I am sure others will benefit from this.

I am showing a map with markers and infobox data from an ajax request with a resulting JSON array.  Works great.  I assign a click event to the marker and it works fine.  I am using parsing that same JSON array to populate a datatable with a

<a href="#" id="link" arid="X">Click Me</a>

X is actually the incrementing marker counter I used when building the JSON array, so it would start with 0 and build to whatever value represents all my markers.  I am expecting to use this value to tell GMAP3 which marker I want to pass the click event to...  if this though process is wrong then I am really confused.

My JSON array object is stored in markerlist and passed to the function below... which works great but I cannot seem to trigger those clicks from my datatable links... (see my jquery code below to grab those clicks and attempt to pass them along to the map)

My map code is:

function display( markerlist ) {
            	
		$("#map").gmap3({action:'clear'});
		
		$("#map").gmap3(
		  	{action: 'init',
			  options:{
				center:true, 
				zoom:13,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				mapTypeControl: true,
				mapTypeControlOptions: {
						style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
				},
				navigationControl: true,
				scrollwheel: true,
				streetViewControl: true
				}
			},
			{action: 'addMarkers',
				radius:100,
				markers: markerlist,
				clusters:{
							maxZoom: 10,
							// This style will be used for clusters with more than 0 markers
							20: {
							content: '<div class="cluster cluster-1">CLUSTER_COUNT</div>',
							width: 53,
							height: 52
							},
							// This style will be used for clusters with more than 20 markers
							50: {
							content: '<div class="cluster cluster-2">CLUSTER_COUNT</div>',
							width: 56,
							height: 55
							},
							// This style will be used for clusters with more than 50 markers
							100: {
							content: '<div class="cluster cluster-3">CLUSTER_COUNT</div>',
							width: 66,
							height: 65
							}
						
					},
				marker: {
					options: {
						
						clickable: true
						},
					events:{
						click: function(marker,event,data) {
							$(this).gmap3({action: 'clear', name : 'infowindow'});
							$(this).gmap3({action: 'addinfowindow', anchor: marker, options: { content:
							'<div class="text"><strong><div style="color:navy;">' + data.itype + '</strong><br/><div id="address" snum="' + data.streetnum + '" snam="' + data.streetnam + '" styp="' + data.streettyp + '">'+ data.iaddress +'</div><br/>' + data.inum + '<br/>'+ data.datetime +'</div><hr>'+data.notes+'</div>'} })
						},  
						mouseover: function(marker, event, data){
							$(this).gmap3(
								{ action:'clear', name:'overlay'},
								{ action:'addOverlay',
									latLng: marker.getPosition(),
									content:  	'<div class="infobulle">' +
												'<div class="bg"></div>' +
												'<div class="text">' + data.itype +'</div>' +
												'</div>' +
												'<div class="arrow"></div>',
									offset: {
										x:-46,
										y:-73
									}
								});
						},
						mouseout: function(){
							$(this).gmap3({action:'clear', name:'overlay'});
							}
			
					}, //end events
					callback: function(result){
						if (result){
						  //not doing anything with a callback at this time
						} else {
						alert('Bad callback...');
						}
					} //end callbacks
				} // end marker
			
				}
				,{action:"autofit"} //end action
					
				);
				
				
				$("a#link").live('click',function(markerlist){ // this works and I can get my arid ok, but the trigger won't work
					var arid = $(this).attr('arid');
					google.maps.event.trigger(markerlist[arid], 'click');
					return false;
				});

							
				
			};

Any help would really be appreciated and am sure will be useful to others!

Thanks gurus!

Offline

Ads
(server costs 27.50€ per month)


#2 2012-09-28 22:01:06

jbdemonte
Administrator
From: Pourrières, France
Registered: 2011-11-21
Posts: 580

Re: Help With Trigger On External Click - Think I Am Close

why don't you use the "get" function to get the marker and then trigger your event on it

Offline

#3 2012-09-30 15:47:26

bgordon
Member
Registered: 2012-09-27
Posts: 3

Re: Help With Trigger On External Click - Think I Am Close

Can you give an example based on my code above?  I am not sure of the syntax.

Offline

#4 2012-10-02 05:13:06

jbdemonte
Administrator
From: Pourrières, France
Registered: 2011-11-21
Posts: 580

Re: Help With Trigger On External Click - Think I Am Close

hum, i didn't saw you were using the clustering feature,
you'll have to wait the version 5, because in 4, clustering feature is like a black box and markers are ephemere
in 5, you'll have to add an id or a tag to each marker, and the "get" it thanks to this property

Offline

#5 2012-10-02 15:02:08

bgordon
Member
Registered: 2012-09-27
Posts: 3

Re: Help With Trigger On External Click - Think I Am Close

Can you point me in the right direction to do that until V5?  I need some code sample to set the id or marker and then to get it so I can trigger a click or move to it etc.  Thanks!

Offline

#6 2012-10-03 05:30:40

jbdemonte
Administrator
From: Pourrières, France
Registered: 2011-11-21
Posts: 580

Re: Help With Trigger On External Click - Think I Am Close

you can't find a marker thought the clusterer feature, markers are created and deleted by the clustering feature on the fly,
if you remove this feature and use an external one to make the clustering, you can get markers thanks to the "tag" property

Offline

Board footer

Powered by FluxBB