Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am very new to openlayers. I have done showing map and whenever we click on the map it is showing marker. But i need to open the popup when i click on the marker.

The following code has some problem. When i click on marker popup is displaying but at the corner it is displaying. I want to display the popup on the marker it self

<html>
<body>
  <div id="mapdiv"></div>
  <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
  <script>
    map = new OpenLayers.Map("mapdiv");
    map.addLayer(new OpenLayers.Layer.OSM());

    var lonLat = new OpenLayers.LonLat( -0.1279688 ,51.5077286 )
          .transform(
            new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
            map.getProjectionObject() // to Spherical Mercator Projection
          );

    var zoom=16;
    var markers = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markers);

    map.events.register("click", map , function(e){
   var opx = map.getLonLatFromPixel(e.xy) ;
   var marker = new OpenLayers.Marker(opx);
   markers.addMarker(marker);
   marker.events.register("click", marker, function(e){
   popup = new OpenLayers.Popup("chicken",
                   map.getLonLatFromPixel(e.xy),
                   new OpenLayers.Size(200,200),
                   "example popup",
                   true);

map.addPopup(popup);
  }); 
});

    map.setCenter (lonLat, zoom);
  </script>
</body>
</html>
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Try this:

  popup = new OpenLayers.Popup.FramedCloud("chicken",
                         marker.lonlat,
                         new OpenLayers.Size(200, 200),
                         "example popup",
                         null, true);

enter image description here

share|improve this answer
    
thank you very much... –  Ramesh Kotha Mar 28 '12 at 16:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.