VEMap.AttachEvent("oncontextmenu", function) firing twice

I am trying to add a pushpin to the map by right clicking on it. I am using AttachEvent with oncontextmenu event. I notice the event fires twice for any function. Am i doing something wrong Here is the code sample. (the map is created as a response to a XHR request)

var VEControls = Class.create();
VEControls.prototype = {
initialize: function(){
var url = "/maps/defaultLatLong";
var opt = {
// Use GET
method: 'get',
// Handle successful response
onSuccess: function(req) {
var latLong = req.responseText.parseJSON();
if(latLong){
map = new VEMap('mapHolder');
map.LoadMap(new VELatLong(latLong["lat"], latLong["long"]),
15 ,'r' ,false);
map.AttachEvent("oncontextmenu",
function(event){
try{
pin = new VEPushpin(iterator,
new VELatLong(event.view.LatLong.Latitude, event.view.LatLong.Longitude),
null,
'My pushpin',
'This is pushpin number ');
map.AddPushpin(pin);
iterator++;
new Ajax.Request("/maps/", opt);
}
catch(err){
}
}
);
}
}
}

var mapLatLong = new Ajax.Request(url, opt);
}

}

var control = new VEControls();
var iterator = 1;



Answer this question

VEMap.AttachEvent("oncontextmenu", function) firing twice

  • Ritesh Tijoriwala

    Hello,

    Actually, he is using e.view correctly. I've had some problems with that but I've found out that there are two properties:
    e.view.latlong => center of the map (with .latitude and .longitude)
    e.view.LatLong => event coordinates on the map (with .Latitude and .Longitude)

  • Nuno_Salvado

    its happening to me to. very annoying - what are we doing wrong

  • Tryston02

    I'm having the same problem.
    It only seems to effect Firefox rather than IE and only after i've moved / resized the map or browser window, but i've yet to replicate it in a consistent method.
    But it's very frustrating!


  • EtherealSky

    I dont know why your event is fired twice,

    but another thing i c in your code is, you try to get the latlong from the event.view arguments of the oncontextmenu event.

    if its ok for you to get only the map center, then use it,

    if you want the latlong of the point you clicked, you must also attach onclick, and store the latlong in a temporary variable from inside the onclick handler.



  • VEMap.AttachEvent("oncontextmenu", function) firing twice