[OpenLayers-Users] Marker with popup

benkyma ben at kymatic.net
Wed Feb 16 09:46:43 EST 2011


I'm trying to dynamically create markers and associate them with a popup, so
that when the user hovers a marker, a popup with product info appears.  The
placement of the popups is always wrong though. The following function
attempts to create this marker from an object containing properties
longitude, latitude and actId:

	updateProductActivity: function(obj){
		var lonLat = new OpenLayers.LonLat( obj.longitude ,obj.latitude )
	      	.transform(
	        new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
	        this.map.getProjectionObject() // to Spherical Mercator Projection
	      	);
			var newMark = new OpenLayers.Marker(lonLat);
			newMark.id= obj.actId;
			var contVar = this;
			console.log(obj.longitude+"  "+obj.latitude);

			
			newMark.events.register('mouseover',newMark,function(evt){
				var popup = new OpenLayers.Popup("popup_"+this.id,
		                   new OpenLayers.LonLat(this.lonlat.lon,this.lonlat.lan),
		                   new OpenLayers.Size(200,200),
		                   "example popup",
		                   true);
				this.map.addPopup(popup);
			})
			//newMark.icon = this.markerIcon.clone();
			this.markers.addMarker(newMark);

			contVar.map.panTo(lonLat);
			
		},
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Marker-with-popup-tp6032030p6032030.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list