i wanted to remove a particular marker from a collection of markers
using the context menu. My application works in such a way that when
the user right clicks on any particular marker a context menu appears
and when the user selects to remove the marker frm the context menu,
then the marker shud get removed and the context menu shud disappear.
Besides if the user right-clicks on the map then the context menu shud
display the zoom in and out options. In either case the context menu
shud disappear after the user clicks on any option of his choice.
In my case the marker gets removed but the context menu does not
disappear and i get the error that 'a is not defined'. I am storing
all the markers in an array so that i can delete them easily but
somehow its not working. Similarly on right click on map the zoom in
and out work fine but the context menu does not disappear. My
Javascript is as follows:
var MarkersArray = []; // global
...........
...........
createMarker: function(point, html) {
var marker = new GMarker(point); //point is a GLatLng
var map = this.getMap();
map.addOverlay(marker);
MarkersArray.push(marker);
var clickedpixel;
var contextmenu = document.createElement('div');
contextmenu.style.visibility = "hidden";
contextmenu.style.background = "#ffffff";
contextmenu.style.border = "1px solid #8888FF";
contextmenu.innerHTML = '<a href="javascript:void(0)"><div
class="context- menu"> Zoom In<\/div><\/a>'
+ '<a href="javascript:void
(0)"><div class="context-menu"> Zoom Out<\/div><\/a>';
var contextmenumarker = document.createElement('div');
contextmenumarker.style.visibility = "hidden";
contextmenumarker.style.background = "#ffffff";
contextmenumarker.style.border = "1px solid #8888FF";
contextmenumarker.innerHTML = '<a href="javascript:void
(0)"><div class="context-menu"> Remove Marker<\/div><\/a>';
GEvent.addListener(map, "singlerightclick", function(a, b,
marker) {
clickedPixel = a;
var x = a.x;
var y = a.y;
if (x > map.getSize().width - 120) {
x = map.getSize().width - 120
}
if (y > map.getSize().height - 100) {
y = map.getSize().height - 100
}
var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize
(x, y));
if (marker) {
if (marker instanceof GMarker) {
pos.apply(contextmenumarker);
contextmenumarker.style.visibility = "visible";
map.getContainer().appendChild(contextmenumarker);
//this is not working for me
GEvent.addDomListener
(contextmenumarker.firstChild, "click", function() {
map.removeOverlay(marker);
contextmenumarker.style.visiibility =
"hidden";
});
}
}
else {
pos.apply(contextmenu);
contextmenu.style.visibility = "visible";
map.getContainer().appendChild(contextmenu);
}
});
//map left click
GEvent.addListener(map, "click", function() {
contextmenu.style.visibility = "hidden";
contextmenumarker.style.visibility = "hidden";
});
GEvent.addDomListener(contextmenu.firstChild, "click", function
() {
map.zoomIn();
contextmenu.style.visibility = "hidden"; //this is not
working for me
});
GEvent.addDomListener(contextmenu.firstChild.nextSibling,
"click", function() {
map.zoomOut();
contextmenu.style.visibility = "hidden"; //this is not
working for me
});
return marker;
},
...........
..........
..........
functionxyz function(){
...........
..........
var marker = this.createMarker(point, place.address);
this.getMap().setCenter(point, 8);
}
Kindly help me out in this. I am struck on this big time. Any help
would be appreciated
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---