[OpenLayers-Users] Avoid colliding Popups

Erik Uzureau euzuro at gmail.com
Thu Feb 19 09:59:17 EST 2009


On Thu, Feb 19, 2009 at 06:35, Perry Cox <cleolas at googlemail.com> wrote:

>
> Hello,
>
> My Problem: I'm adding several popups (FramedCloud) to my map, i.e. that
> multiple popups shall be open at same time. But the popups overlapp very
> often, though there would be enough free space if the popup would have been
> drawn in another direction (e.g. "top-right" instead of "bottom-left").
>
> Now the questions:
>
> - Is there a method for optimizing the "drawing-direction" of several
> popups in relation to each other?
>

Hi Perry,

this function does not exist right now, but it sounds like it might be a
handy bit of code to have around in the library (i.e. a nice contribution!)



>
> - Is there a method for influencing the "drawing-direction" of a
> FramedCloud-Popup. My assumption is, that a FramedCloud is drawn relative to
> the AnchorPosition on the map: If it's anchor is in the top-left quadrant of
> the actual view, then the FramedCloud will open to bottom-right. Is that
> correct? May I influence this behaviour?
>

There is indeed. The entry point you are looking for is a function called

calculateRelativePosition()

It is first defined in Popup.Anchored:

    /**
     * Method: calculateRelativePosition
     *
     * Parameters:
     * px - {<OpenLayers.Pixel>}
     *
     * Returns:
     * {String} The relative position ("br" "tr" "tl" "bl") at which the
popup
     *     should be placed.
     */
    calculateRelativePosition:function(px) {
        var lonlat = this.map.getLonLatFromLayerPx(px);

        var extent = this.map.getExtent();
        var quadrant = extent.determineQuadrant(lonlat);

        return OpenLayers.Bounds.oppositeQuadrant(quadrant);
    },



As you can see, it finds the popup's lonlat, determines in which of the four
quadrants of the map it lies,
and then returns the "opposite quadrant". The return is a string ("br" "tr"
"tl" "bl") indicating the direction
relative to the anchor in which to draw the popup.

What you would want to do in your patch is to modify that function so that
the calculation of the
returned relative position is based on the positions of the other popus, not
merely the opposite quadrant.

Sounds like a fun programming challenge.... good luck!
Erik



>
>
> Thanks, perry
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090219/d4895d2d/attachment.html


More information about the Users mailing list