after i add a marker with an image, how can i catch the mouse click on it on client side?
Catch client side click on marker
Dan,
It can be achieved by registering mouse click event on Marker Overlay at client side, please see the attached demo for detail.
Thanks,
Ben
1243-Post_6340.zip (7.34 KB)
Ben,
thanks for the quick reply. is there a way to add custom attributes to the marker so i know which marker was clicked?
Dan,
Currently we don’t support this; because map maintains feature object on server side, while maintains OpenLayers.Marker on the client side, they only share some simple properties such as ID and position, etc.
We don’t allow adding custom attributes to the client marker through server features because if there are too much data on the client side, it will cause performance issue on the client side.
By the way, could you please tell us your exactly requirement so that we provide you a better solution.
Thanks,
Howard
Hi Howard,
my application displays a list of objects on one frame and a map on another frame. when a user clicks a marker on the map i need on client side to invoke some code in the object list frame.
assuming that the ID is a string and i can put unlimited data in it, i can put it pseudo xml like <tag1>data</tag1><tag2>data2</tag2> and parse that where needed. if indeed that is the case, and folliowing ben’s sample above, how do i get the ID of the marker clicked?
Dan,
Regarding to your case, SimpleMarkerOverlay is a better choice which directly maintains Markers object on the server side. But one thing I want to point out is that SimpleMarkerOverlay adds all the markers on the client side no matter the markers display or not in the viewport; if the count of markers are too many, it may cause performance issue on the client side. Please see the attached sample for detail.
Hope it makes sense.
Please let us know if you have more questions.
Thanks,
Howard
1257-Post_6340.zip (7.19 KB)