I had the same issue, once the event is registered to a specific Maker it
triggers for all the other Marker's as well. Finally, I was able to solve
it. I had to register seperate events for each marker. Following is my code:

        var makerCount=0; // I want only 2 Markers to be shown :
Source,Destination
        
    function setMarkers(x,y){
        var icon = new
OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset);  
        
     if(makerCount<2){
    
        if(makerCount==0){  // Source
           var location = new OpenLayers.LonLat(x,y); 
                        
           var size = new OpenLayers.Size(21,25);
           var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
                    
                var sourceMarker=new OpenLayers.Marker(location,icon)
                sourceMarker.events.register('mousedown', sourceMarker,
function(evt) { 
                    alert('Source :: X='+ x + ' , Y=' + y); 
                        OpenLayers.Event.stop(evt); }); 
      
                    
                markers.addMarker(sourceMarker); 
                markers.setOpacity(0.2);
                makerCount++;
        }else{ // Destination
        
                var location = new OpenLayers.LonLat(x,y); 
                
                var size = new OpenLayers.Size(21,25);
            var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
            var halfIcon = icon.clone();  
        
                var destinationMarker=new OpenLayers.Marker(location,halfIcon)
                destinationMarker.events.register('mousedown', 
destinationMarker,
function(evt) { 
                    alert('Destination :: X='+ x + ' , Y=' + y); 
                        OpenLayers.Event.stop(evt); 
                   });                  
            markers.addMarker(destinationMarker); 
            halfIcon.setOpacity(0.5);
                makerCount++;
        }
        
     }
    }

--
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Attaching-events-to-several-markers-tp6330887p7081032.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to