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 using the GeoExt example and used the same code in my application. This is my code

The problem I am facing is that the Popup box in my application on http://128.196.142.94/geo/test/test.html is stationary. Where ever you may click, the popup simply does not move. Not sure where I am going wrong?

share|improve this question
    
I had to wrap the link in code since gis stack was not allowing me to post it as a link. You can copy it and paste it in your url. –  Sam007 Aug 2 '12 at 2:23
add comment

2 Answers

up vote 1 down vote accepted

anchored: false should be anchored: true:

if (!popup) {
    popup = new GeoExt.Popup({
        title: "Popup",
        width: 200,
        maximizable: true,
        collapsible: true,
        map: mapPanel.map,
        anchored: true,
        listeners: {
            close: function() {
                // closing a popup destroys it, but our reference is truthy
                popup = null;
            }
        }
    });
}

And remove location: loc.xy from popup definition.

loc.xy is undefined and if you have a look into GeoExt Popup.js source you can find that in this case anchored property automatically sets to false.

UPDATE:

It looks like you are using old version of geoext library. I've adapted your example for working with this version:

var mapPanel, popup;

Ext.onReady(function() {

    function addToPopup(loc) {

        if (!popup) {
            popup = new GeoExt.Popup({
                title: "Popup",
                width: 200,
                maximizable: true,
                collapsible: true,
                map: mapPanel.map,
                /* Fix #1
                   loc - object of OpenLayers.Pixel class
                */
                location: loc,
                anchored: true,
                listeners: {
                    close: function() {
                        popup = null;
                    }
                }
            });
        }

        popup.add({
            xtype: "box",
            autoEl: {
                /* Fix #2
                   Convert pixel coordinates to LonLat
                */
                html: "You clicked on (" + mapPanel.map.getLonLatFromViewPortPx(loc).lon.toFixed(2) + ", " + mapPanel.map.getLonLatFromViewPortPx(loc).lat.toFixed(2) + ")"
            }
        });

        /* Fix #3
           It is not necessary because location was defined within constructor
        */
        //popup.location = loc;

        popup.doLayout();
        popup.show();
    }

    var mapPanel = new GeoExt.MapPanel({
        title: "Map",
        renderTo: "container",
        width: 650, height: 356,
        layers: [
            new OpenLayers.Layer.WMS(
                "Global Imagery",
                "http://maps.opengeo.org/geowebcache/service/wms",
                {layers: "bluemarble"}
            )
        ],
        center: [0, 0],
        zoom: 2
    });

    var control = new OpenLayers.Control.Click({
        trigger: function(evt) {
            /* Fix #4
               Get pixel coordinates from click and send to popup constructor 
            */
            var loc = evt.xy;
            if (popup) popup.close();
            addToPopup(loc);
        }
    });

    mapPanel.map.addControl(control);
    control.activate();

});
share|improve this answer
    
Nope it is not working. Made the change, you can check the link, it seems indifferent to the change –  Sam007 Aug 2 '12 at 16:00
    
@Sam007 I've updated my answer please check it out. –  drnextgis Aug 3 '12 at 2:44
    
Sorry @drnextgis still unchanged. here is the entire code, dpaste.de/poV4P, I might have forgotten something that you might find it in the code. The application is still live, if you want to check. –  Sam007 Aug 3 '12 at 16:37
    
@Sam007 please check update of my answer. –  drnextgis Aug 5 '12 at 12:29
    
@Sam007 did you try proposed solution? –  drnextgis Aug 8 '12 at 22:08
show 1 more comment

Try to add these variables to the top of your code. Sometimes if you don't define the variable, OpenLayers has a problem

var panel, popup;

I hope it helps you...

share|improve this answer
    
already done. It was giving me an error before, but I added it and now at-least I can see the popup –  Sam007 Aug 2 '12 at 6:58
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.