[OpenLayers-Users] why the popups have same content?

dolphintroop thymeland at hotmail.com
Fri Mar 1 04:16:29 PST 2013


Hi,Yves G:
Thanks for your help, now the content of popup is displayed normally,and a
new problem is appeared, I just add extra infomation in coodCollection
array, depend this infomation, the marker could change the icon accordingly,
and now I get all the icon name as this: "img/mini_circle.png",  the color
parameter is right.
//*******************************************

	markers = new OpenLayers.Layer.Markers("Markers2");
		map.addLayer(markers);

		var size = new OpenLayers.Size(21, 25);
		var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);

		//
		for ( var i = 0; i < (coodCollection1.length / 3); i++) {

			var lon = coodCollection1[i * 3];
			var lat = coodCollection1[i * 3 + 1];
			var color = coodCollection1[i * 3 + 2];

			var size = new OpenLayers.Size(21, 25);
			var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
			var iconName;
			// color:0 red,1 blue,2 gold,3 green
		
			alert("color is "+color);
			switch (color) {
			case 0:
				iconName = 'img/marker.png';
				break;
			case 1:
				iconName = 'img/marker-blue.png';
				break;
			case 2:
				iconName = 'img/marker-gold.png';
				break;
			case 3:
				iconName = 'img/marker-green.png';
				break;
			default:
				iconName = 'img/mini_circle.png';
			}

			var icon = new OpenLayers.Icon(iconName, size, offset);

			marker = new OpenLayers.Marker(new OpenLayers.LonLat(lon, lat),
					icon.clone());
			alert("1color is "+color);
			marker.events.register("mouseover", marker, popupHandler(marker,
					coodCollection1, i));//
			marker.events.register('mouseout', marker, function(evt) {
				popup.hide();
			});

			markers.addMarker(marker);
//********************************************
It looks should be the closures issue too, andI try several function factory
way, it's not work.
one of my code is as below:
//---------------------------------
function makeName(coodCollection,x) {
  return function() {
 
 			switch (coodCollection[x * 3 + 2]) {
			case 0:
				iconName = 'img/marker.png';
				break;
			case 1:
				iconName = 'img/marker-blue.png';
				break;
			case 2:
				iconName = 'img/marker-gold.png';
				break;
			case 3:
				iconName = 'img/marker-green.png';
				break;
			default:
				iconName = 'img/mini_circle.png';
			}
 
 return iconName;
  }; 
} 

var iconName = makeName(coodCollection,i);
//---------------------------------

but it returned the text file of the function, how about your idea?





--
View this message in context: http://osgeo-org.1560.n6.nabble.com/why-the-popups-have-same-content-tp5037498p5037735.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list