[OpenLayers-Users] Attaching events to several markers

steveyoung stephen.young at chello.at
Wed May 4 09:47:17 EDT 2011


I am trying to attach an event to each market so that when I click on a
marker a circle is drawn around it. This works for the first marker I click
on but when I click on another marker, after drawing a ring around one
marker, the second event is ignored and another marker is placed on the
layer on top of the one I clicked on.

I have been messing with this for a couple of hours now but I can't figure
it out and I'm getting tired, therefore any suggestions would be gratefully
received.

My code is here: 

function addMarker(lonlat){
	var size = new OpenLayers.Size(25, 30), gpoint,
	offset = new OpenLayers.Pixel(-(size.w / 2), -size.h),
	icon2 = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',
size,offset);
	markers[markerCount] = new OpenLayers.Marker(lonlat, icon2);
	gpoint = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
	markerCoords.push(gpoint);
	newMarkersLayer.addMarker(markers[markerCount]);
	markers[markerCount].events.register('mousedown', markers[markerCount],
function(evt) {
	drawCircle(lonlat);
	OpenLayers.Event.stop(evt);
	 });
	if (markerCount > 0) {
		drawLine();		
	}
	markerCount++
	return;
}

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Attaching-events-to-several-markers-tp6330887p6330887.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list