Click event listener to existing marker.

29 views
Skip to first unread message

Kedor

unread,
Sep 19, 2011, 4:12:02 PM9/19/11
to google-map...@googlegroups.com

I got a problem. I am making a map where u can add markers, polylines and polygons using "tools". Like MS Paint and tools there. U click on tool, and then do whatever u want on map. The thing is, i am adding markers without any listeners, so i cant click them - cuz i want that tool just to put marker in chosed place.

And my problem is to create a tool, which would let me to delete these markers. But to do that, my tool would need to add click event listener to markers.. and they were created some time ago. Is that possible? Cuz when i try just to make addeventlistener (marker, 'click, xxx()) i get the error that marker is not defined.

I wont post whole code here, cuz its a lot of it, but if you need any part, just ask, i will post it asap

xelawho

unread,
Sep 19, 2011, 8:09:36 PM9/19/11
to Google Maps JavaScript API v3
> And my problem is to create a tool, which would let me to delete these
> markers. But to do that, my tool would need to add click event listener to
> markers.. and they were created some time ago. Is that possible? Cuz when i
> try just to make addeventlistener (marker, 'click, xxx()) i get the error
> that marker is not defined.

does the delete have to happen by clicking on the marker? you could
have a pull-down list at the side that deletes the markers on the
onchange?

JKurtock

unread,
Sep 20, 2011, 10:41:19 AM9/20/11
to Google Maps JavaScript API v3
Add your markers with listeners, just don't pay any attention (return
from the listener) until your "delete" tool is selected.

Or, maintain a table of markers (you're almost certain to need to do
that for all your entities if you're trying something like MS Paint).
When the delete tool is selected, and a point is clicked, search your
table of markers by the latlng of the point clicked to find the
"nearest" one.

- Jeff
Reply all
Reply to author
Forward
0 new messages