Hi, If you change the order of your code, then you get what you want.
Create the layer Register the event for the layer Add the feature If you add your feature before you register the event, then the feature is added before the listener could listen. Arnd -----Ursprüngliche Nachricht----- Von: [email protected] [mailto:[email protected]] Im Auftrag von Puneet Kishor Gesendet: Freitag, 7. Oktober 2011 01:48 An: [email protected] Betreff: [OpenLayers-Users] featureadded The following code is supposed to create a Google Maps base layer, and a point using an external graphic that is rotated (az) and has height (rate) described by the attributes passed when creating the point. A "featureadded" event is supposed to create a popup anchored at the point showing "az" and "rate". The code doesn't work. The base layer is created but neither the point nor the popup are created. Suggestions? var proj = { "google": new OpenLayers.Projection("EPSG:900913"), "latlng": new OpenLayers.Projection("EPSG:4326") }; map = new OpenLayers.Map('map', { "maxExtent": new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508), "maxResolution": 156543.0339, "proj": proj, "units": "meters" }); map.addLayer(new OpenLayers.Layer.Google("Google Physical", {type: google.maps.MapTypeId.TERRAIN})); map.setCenter(new OpenLayers.LonLat(-89, 43).transform(proj.latlng, proj.google), 2); var styleMap = new OpenLayers.StyleMap({ "default": { externalGraphic: "arrow.png", rotation: "${az}", graphicWidth:6, graphicHeight: "${rate}" } }); var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {styleMap: styleMap}); // create a point feature var points = []; var p = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point(-72, 42).transform(proj.latlng, proj.google), {attributes: {az: 76, rate: 33}}, {styleMap: styleMap} ); points.push(p); vectorLayer.addFeatures(points); vectorLayer.events.on({ "featureadded": function(evt) { feature = evt.feature; var str = ""; for (var i in feature.attributes) { str += "<b>" + i + ":</b> " + feature.attributes[i] + "<br />"; } map.addPopup(new OpenLayers.Popup.FramedCloud( "featurePopup", feature.geometry.getBounds().getCenterLonLat(), new OpenLayers.Size(50, 30), str, null, true, null )); } }); map.addLayer(vectorLayer); _______________________________________________ Users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/openlayers-users _______________________________________________ Users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/openlayers-users
