[OpenLayers-Users] Looping through unique markers?

Heidt, Christopher M. CHRISTOPHER.M.HEIDT at saic.com
Fri Feb 27 13:21:33 EST 2009


 
Every browser cept ie7 is throwing "XMLHttpRequest.create is not
function"
-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
On Behalf Of David Raasch
Sent: Friday, February 27, 2009 12:35 PM
To: users at openlayers.org
Subject: Re: [OpenLayers-Users] Looping through unique markers?


 
OK, I discovered where apparently, this is known to happen when using
Vector layers.  And I had forgotten to comment-out my Vector layer
completely when switching over to using a Marker layer instead.  So,
I've got that part of it solved.

That leaves me with:

1) How to get each marker to have its own unique function? ( I know
right now it's just an "alert", but I plan on making that function
trigger a pop-up with some marker-specific HTML code in it in the near
future).
2) Why do none of the markers (or the circle, for that matter) display
in Firefox?

Thanks!

-= Dave =-


-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
On Behalf Of David Raasch
Sent: Friday, February 27, 2009 10:44 AM
To: users at openlayers.org
Subject: Re: [OpenLayers-Users] Looping through unique markers?

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-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
On Behalf Of David Raasch
Sent: Friday, February 27, 2009 8:13 AM
To: users at 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 at 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 at 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 at openlayers.org
http://openlayers.org/mailman/listinfo/users



More information about the Users mailing list