【问题标题】:offset for anchored popup in openlayersopenlayers中锚定弹出窗口的偏移量
【发布时间】:2012-08-17 17:08:40
【问题描述】:

我正在使用 Openlayers-2.12 版本。 但是锚定的弹出偏移无法正常工作。尽管我已将相对定位设为“tr”,但它会在地图的另一半显示左侧的弹出窗口。

var popup = new OpenLayers.Popup.Anchored("popup");
var offset = {'size':new OpenLayers.Size(10,12),'offset':new OpenLayers.Pixel(0,-12)};
popup.offset = offset;
popup.relativePosition = "tr";

有什么帮助吗?

【问题讨论】:

    标签: openlayers


    【解决方案1】:

    我在回答我自己的问题时认为它可能对其他人有所帮助。 如果我只使用弹出窗口而不是锚定弹出窗口,它工作正常。

    【讨论】:

    • offset 属性被移除了吗?我在当前的规范中没有看到它,它似乎没有任何影响。
    【解决方案2】:

    它看起来而不是偏移属性,它们可以访问用于计算 x,y 位置的函数。

    popup.calculateNewPx = function(px){
        // modify OpenLayers.Pixel object here
        return px;
    }
    

    参考:http://dev.openlayers.org/docs/files/OpenLayers/Popup/Anchored-js.html#OpenLayers.Popup.Anchored.calculateNewPx

    更具体地说,这就是我最终要做的。

    popup.calculateNewPx = function(px){
        if (popup.size !== null){
            switch (popup.relativePosition){
                case 'tl':
                    px = px.add((popup.size.w * -1) - popup.offset, (popup.size.h * -1) - popup.offset);
                    break;
                case 'bl':
                    px = px.add((popup.size.w * -1) - popup.offset, popup.offset);
                    break;
                case 'tr':
                    px = px.add(popup.offset, (popup.size.h * -1) - popup.offset);
                    break;
                case 'br':
                    px = px.add(popup.offset, popup.offset);
                    break;
            }
        }
        return px;
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      相关资源
      最近更新 更多