Hmmm... I just realized that if I go to the map controls and turn off the circle and vector layers, then the events work for all icons, in the sense that they all activate an "alert" pop-up. Of course, the trouble is, all alerts say exactly the same thing, basically showing the text for point #571 only.
So, it looks like I've got two problems: Why is it that the Vector and Circle layers seem to be "interfering" with the click events? And apparently I have to figure out how to give each registered event instance a reference to its own unique "evt" function. -= Dave =- -----Original Message----- From: users-boun...@openlayers.org [mailto:users-boun...@openlayers.org] On Behalf Of David Raasch Sent: Friday, February 27, 2009 8:13 AM To: users@openlayers.org Subject: [OpenLayers-Users] Looping through unique markers? Greetings All! When I posted to the list last week, I had coded my little app to use FEATURES to draw marker icons and rig-up word-balloon pop-ups whenever they were clicked-on. However, the markers took a very, very long time to load. So, digging further into the archives of this discussion list, I discovered that, although using MARKERS to draw marker icons is considered to be "the old way of doing it", that way is apparently faster. So, I set about commenting-out the feature-adding/drawing lines in my code and inserting some lines that would loop through my array of data, draw each marker, and register an event for that marker. My problem is that I'm only getting the event to work on the FINAL marker in the array. I've posted my files here: http://www.davidraasch.com/ww/map_v4.html If you zoom in over that cluster near Chicago and click, eventually you'll trigger an alert message on the one marker, which is the last one in the array. It will say "You clicked on marker m571". Feel free to do a "view source", but here are the pertinent lines from my code: var markers_layer = new OpenLayers.Layer.Markers( "Markers Layer"); map.addLayer(markers_layer); var xml_points = xmlDoc.documentElement.getElementsByTagName("point"); var m = []; for (var i = 0; i < xml_points.length; i++) { var type = xml_points[i].getAttribute("type"); var thislat = (parseFloat(xml_points[i].getAttribute("lat"))); var thislng = (parseFloat(xml_points[i].getAttribute("lng"))); var html = xml_points[i].getAttribute("html"); {to reduce "noise" here for you, I'm leaving out the if-then statements that determine which exact icon graphic file to use, plus its height and width } // Code to push each point as a MARKER LAYER MARKER var size = new OpenLayers.Size(icon_width,icon_height); var offset = 0; // new OpenLayers.Pixel(-(icon_width/2), -icon_height); var icon = new OpenLayers.Icon(icon_image,size,offset); m[i] = new OpenLayers.Marker((new OpenLayers.LonLat(thislng,thislat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject())),icon); markers_layer.addMarker(m[i]); m[i].events.register ('click', m[i], function(evt) {alert ('You clicked on marker m'+ i); OpenLayers.Event.stop (evt); }) // alert("i="+ i); } // end of "for i = 0 to all POINTS (Originally, I was using just the variable "m1" to represent the markers, as taken from an example I found somewhere on the openlayers.org site. But then, in debugging it, I switched to using "m" as an array, just to make sure I did understand what we're trying to do here.) I should also mention that, for some reason, the markers don't even appear to load in Firefox! I can only see them in IE. ???? Any thoughts? Thanks! -= Dave =- _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.0.237 / Virus Database: 270.11.3/1974 - Release Date: 02/26/09 14:51:00 _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users