Trouble adding js event Listener on Gmap map (gmap module)

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by steev on February 9, 2011 at 5:53pm

I'm trying to write a Drupal module that will add UTM coordinate fields to a location form, such that they'll interact properly with the GMap map as well as with the Latitude and Longitude fields - i.e. when the map is clicked, the UTM coordinates get calculated and populated along with the Lat/Long ones, and if the Lat/Long coordinates are changed by typing in the fields, the UTM coordinates change also, as well as the map, and vice versa.

I have the coordinate translation and everything else working except for clicking the map. I'm trying to add a Listener to the map so that when it's clicked, a change event will get triggered on the lat/long fields, which would in turn trigger the updating of the UTM fields. But, I can't seem to get the Listener to work. here's what I have so far (this is a snippet of my js file for my module, location_utm.js):

$(document).ready(function() {
var themap = document.getElementById("gmap-auto1map-gmap0");

Drupal.gmap.addHandler('gmap', function (themap) {
var obj = this;

var clickListener = GEvent.addListener(obj, "click", function() {

/* when the map gets clicked, trigger change event on the lat/long
fields so that the utm fields get updated too. */
$('#gmap-auto1map-locpick_longitude0').change();
$('#gmap-auto1map-locpick_latitude0').change();



});
});
});

I've tried a lot of different slight variations of this code but can't seem to get it right. Or maybe there's a totally different better way to do what I'm trying to do besides using a Listener. I'd appreciate any advice.
thanks,
steev

Comments

boot

Posted by ultimike on February 10, 2011 at 8:17pm

I've done something similar - but in a slightly different way. Maybe this will point you in the right direction:

Drupal.gmap.addHandler('gmap', function(elem) {
// the overall Drupal GMap object, the Google Map object is then obj.map
var obj = this;
obj.bind("boot",function() {
GEvent.addListener(obj.map,"moveend",function() {
// do stuff
});
});
});

-mike

Location and Mapping

Group organizers

Group categories

Wiki type

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /