Weird behaviour of event listeners
I have a listener for a click event on a map and on the marker. When I click on the marker, also the function that is attached to the map is fired. Why? Isn't a marker overlay?
Another thing is that also with double click listeners react, and this is wrong for sure. What am I doing wrong?
[CODE]
var newOfficeMarker = new nokia.maps.map.StandardMarker(
new nokia.maps.geo.Coordinate(0, 0),
{draggable: true}
);
function selectionOfNewOffice(){
newOfficeMarker.addListener("click", function(evt){
alert("Test2");
map.objects.remove(newOfficeMarker);
}, true);
addNewOfficeMarkerListener = function(evt){
alert("Test1");
if(evt.currentTarget == map && map.objects.indexOf(newOfficeMarker)<0)
map.objects.add(newOfficeMarker);
};
map.addListener("click", addNewOfficeMarkerListener, true);
}
[/CODE]
Re: Weird behaviour of event listeners
Event behaviour is described in detail in the API reference documentation here: [url]http://api.maps.nokia.com/en/apireference/2.2.1/symbols/nokia.maps.dom.EventTarget.html[/url] It explains that events will propagate through the DOM so the [B]MapDisplay [/B]will also receive an event when the [B]MapMarker[/B] is clicked. You can stop this by using methods such as [B] stopImmediatePropagation()[/B] Consider this code snippet:
[CODE] var map = new nokia.maps.map.Display(mapContainer, {
zoomLevel: 4, //zoom level for the map
center: [50.5,15.5], // center coordinates
components : [
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.ScaleBar()]
});
map.addListener("click", function(evt) {
console.log(evt);
});
var marker = new nokia.maps.map.StandardMarker([50.5,15.5]);
marker.addListener("click", function(evt) {
console.log(evt);
evt.stopImmediatePropagation();
});
map.objects.add(marker);[/CODE]
Clicking on the marker will not fire the map "click" listener.