maps - GoogleMaps API v3 - Trigger event from link in Infowindow -



maps - GoogleMaps API v3 - Trigger event from link in Infowindow -

i have listener right-click context menu allows me perform actions specific particular infowindow. instance, here code opens , fills directions panel:

google.maps.event.addlistener(contextmenu, 'menu_item_selected', function(latlng, eventname){ switch(eventname){ case 'directions_from_click': showdirections(); geocoder.geocode({latlng: latlng}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { if (results[0]) { faddress = results[0].formatted_address; $('#start').val(faddress); $('#panelwrapper').focus(); } } }); $('#panelwrapper').focus(); break; case 'directions_to_click': showdirections(); geocoder.geocode({latlng: latlng}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { if (results[0]) { faddress = results[0].formatted_address; $('#end').val(faddress); $('#panelwrapper').focus(); } } }); $('#panelwrapper').focus(); break; } });

in add-on right-click context menu, i'd have link in infowindow performs same action onclick:

<a class="fromlink">directions here</a>

how add together listener link perform similar context menu? i've been experimenting adddomlistener function, i'm not sure if that's need.

i couldn't find in api, ended passing in latlng via onclick event function fill in direction input. rather ugly, sort of this:

function addmessagemarker(marker, addlinfo){ var position = string(marker.getposition()); var fromlink = '<a class="infolink" onclick="getfrom(&quot;' + position + '&quot;)">directions here</a> - '; ... //bunch of other stuff } function getfrom(position) { showdirections(); //convert string value latlng var latlng = position.replace("(",""); latlng = latlng.replace(")",""); latlng = latlng.replace(" ",""); latlngarr = latlng.split(","); lat = parsefloat(latlngarr[0]); lng = parsefloat(latlngarr[1]); latlng = new google.maps.latlng(lat,lng); geocoder.geocode({latlng: latlng}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { if (results[0]) { faddress = results[0].formatted_address; $('#start').val(faddress); } } }); $('#panelwrapper').focus(); }

maps

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -