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

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

    var lonLat = new OpenLayers.LonLat( -0.1279688 ,51.5077286 )
            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.events.register("click", map , function(e){
   var opx = map.getLonLatFromPixel(e.xy) ;
   var marker = new OpenLayers.Marker(opx);
   marker.events.register("click", marker, function(e){
   popup = new OpenLayers.Popup("chicken",
                   new OpenLayers.Size(200,200),
                   "example popup",


    map.setCenter (lonLat, zoom);

Try this:

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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