Search code examples
openlayers

popup in openlayers


What is the difference between popup and Frame and FrameColud?

And,it seems that the direction of the popup is depended on the location of the marker relatived to the map. The pop may be above or under the marker.

For example:

Above:

enter image description here

Below:

enter image description here

Now,I want to know how to make the popup always at the above of the marker?


Solution

  • Well,I answer this question myself.

    You can override the calculateRelativePosition function for FramedCloud like this:

    OpenLayers.FramedCloud.prototype.calculateRelativePosition=function(){
      return 'tr';
    }
    

    And this function is inherited from OpenLayers.Popup.Anchored.

    calculateRelativePosition:function(px) {

    var lonlat = this.map.getLonLatFromLayerPx(px);
    
    var extent = this.map.getExtent();
    var quadrant = extent.determineQuadrant(lonlat);
    
    return OpenLayers.Bounds.oppositeQuadrant(quadrant); 
    

    },