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 have a fixed size FramedCloud Popup that I want to position relative to the point calling it, always above the point and with its right side 50px to the right of the point.

I am looking at the API and see positionBlocks and blocks, but I do not understand how to use them and if that's what I need. I'm really looking for.

I tried setting popup.relativePosition, hoping to find an offset parameter somewhere, but relative position doesn't seem to be having any effect.

var vector = new OpenLayers.Layer.Vector("Points",{
    eventListeners:{
        'featureselected':function(evt){
            var feature = evt.feature;
            var popup = new OpenLayers.Popup.FramedCloud("popup",
                OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
                new OpenLayers.Size(275,71),
                "<div style='font-size:.8em'><h3>" + feature.attributes.title +"</h3></div>",
                null,
                true
            );
            popup.imageSrc = 'img/popup.png';
            popup.autoSize = false;
            popup.imageSize = new OpenLayers.Size(275,71);
            popup.relativePosition = "bl"
            popup.fixedRelativePosition = true;
            //popup.positionBlocks = {}
            feature.popup = popup;
            map.addPopup(popup);
        },
        'featureunselected':function(evt){
            var feature = evt.feature;
            map.removePopup(feature.popup);
            feature.popup.destroy();
            feature.popup = null;
        }
    }
});
share|improve this question
    
Maybe a typo ";" here popup.relativePosition = "bl"? –  Niculita Mihai Feb 1 '13 at 6:41
    
In the end I chanted it to a Popup.Anchored bc that seemed to be the only one with an offset property.. which is odd.. I would imagine that would always be useful –  Damon Feb 1 '13 at 14:56
add comment

1 Answer

As far as I can tell there is no way to position a popup with FramedCloud so I used Anchored:

var vector = new OpenLayers.Layer.Vector("Points",{
    eventListeners:{
        'featureselected':function(evt){
            var feature = evt.feature;
            var popup = new OpenLayers.Popup.Anchored("popup",
                OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
                new OpenLayers.Size(275,71),
                "<div id='pincontent' onclick='pindetails()'><h3 data-description='"+  feature.attributes.content +"'>" + feature.attributes.title +"</h3></div>",
                null,
                false
            );
            popup.imageSrc = 'img/popup.png';
            popup.autoSize = false;
            popup.backgroundColor = 'transparent';
            var offset = {'size':new OpenLayers.Size(0,0),'offset':new OpenLayers.Pixel(-74,-10)};
            popup.anchor = offset;
            popup.panMapIfOutOfView = true;
            popup.imageSize = new OpenLayers.Size(275,71);
            popup.relativePosition = "br"
            popup.calculateRelativePosition = function () {
                 return 'tr';
            }
            feature.popup = popup;
            map.addPopup(popup);
        },
        'featureunselected':function(evt){
            var feature = evt.feature;
            map.removePopup(feature.popup);
            feature.popup.destroy();
            feature.popup = null;
        }

    }
});
share|improve this answer
    
FramedCloud is a subclass of Anchored and works the same way, at least for me. –  Andrew Mao Aug 5 '13 at 21:01
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.