自定义的Openlayers.Popup.FreshCloud继承自Openlayers.Popup.Framed,实现了比较简洁的冒泡效果,详细代码如下

/**
* Class: OpenLayers.Popup.FramedCloud

* Inherits from: 
*  - <OpenLayers.Popup.Framed>
*/
OpenLayers.Popup.FreshCloud =
  OpenLayers.Class(OpenLayers.Popup.Framed, {       /** 
      * Property: contentDisplayClass
      * {String} The CSS class of the popup content div.
      */
      contentDisplayClass: "olFreshCloudPopupContent",       /**
      * APIProperty: autoSize
      * {Boolean} Framed Cloud is autosizing by default.
      */
      autoSize: true,       /**
      * APIProperty: panMapIfOutOfView
      * {Boolean} Framed Cloud does pan into view by default.
      */
      panMapIfOutOfView: true,       /**
      * APIProperty: imageSize
      * {<OpenLayers.Size>}
      */
      imageSize: new OpenLayers.Size(1276, 736),       /**
      * APIProperty: isAlphaImage
      * {Boolean} The FramedCloud does not use an alpha image (in honor of the 
      *     good ie6 folk out there)
      */
      isAlphaImage: false,       /** 
      * APIProperty: fixedRelativePosition
      * {Boolean} The Framed Cloud popup works in just one fixed position.
      */
      fixedRelativePosition: false,       /**
      * Property: positionBlocks
      * {Object} Hash of differen position blocks, keyed by relativePosition
      *     two-character code string (ie "tl", "tr", "bl", "br")
      */
      positionBlocks: {
          "tl": {
              'offset': new OpenLayers.Pixel(55, 0),
              'padding': new OpenLayers.Bounds(5, 35, 5, 5),
              'blocks': [
                { // top-left
                    size: new OpenLayers.Size('auto', 'auto'),
                    anchor: new OpenLayers.Bounds(0, 35, 5, 0),
                    position: new OpenLayers.Pixel(0, 0)
                },
                { //top-right
                    size: new OpenLayers.Size(5, 'auto'),
                    anchor: new OpenLayers.Bounds(null, 35, 0, 0),
                    position: new OpenLayers.Pixel(-1271, 0)
                },
                { //bottom-left
                    size: new OpenLayers.Size('auto', 5),
                    anchor: new OpenLayers.Bounds(0, 30, 5, null),
                    position: new OpenLayers.Pixel(0, -641)
                },
                { //bottom-right
                    size: new OpenLayers.Size(5, 5),
                    anchor: new OpenLayers.Bounds(null, 30, 0, null),
                    position: new OpenLayers.Pixel(-1271, -641)
                },
                { // stem
                    size: new OpenLayers.Size(42, 33),
                    anchor: new OpenLayers.Bounds(null, 0, 30, null),
                    position: new OpenLayers.Pixel(-5, -699)
                }
            ]
          },
          "tr": {
              'offset': new OpenLayers.Pixel(-50,0),
              'padding': new OpenLayers.Bounds(5, 35, 5, 5),
              'blocks': [
                { // top-left
                    size: new OpenLayers.Size('auto', 'auto'),
                    anchor: new OpenLayers.Bounds(0, 35, 5, 0),
                    position: new OpenLayers.Pixel(0, 0)
                },
                { //top-right
                    size: new OpenLayers.Size(5, 'auto'),
                    anchor: new OpenLayers.Bounds(null, 35, 0, 0),
                    position: new OpenLayers.Pixel(-1271, 0)
                },
                { //bottom-left
                    size: new OpenLayers.Size('auto', 5),
                    anchor: new OpenLayers.Bounds(0, 30, 5, null),
                    position: new OpenLayers.Pixel(0, -641)
                },
                { //bottom-right
                    size: new OpenLayers.Size(5, 5),
                    anchor: new OpenLayers.Bounds(null, 30, 0, null),
                    position: new OpenLayers.Pixel(-1271, -641)
                },
                { // stem
                    size: new OpenLayers.Size(42, 33),
                    anchor: new OpenLayers.Bounds(33, 0, null, null),
                    position: new OpenLayers.Pixel(-5, -699)
                }
            ]
          },
          "bl": {
              'offset': new OpenLayers.Pixel(52, 0),
              'padding': new OpenLayers.Bounds(4, 4, 4, 35),
              'blocks': [
                { // top-left
                    size: new OpenLayers.Size('auto', 'auto'),
                    anchor: new OpenLayers.Bounds(0, 5, 5, 30),
                    position: new OpenLayers.Pixel(0, 0)
                },
                { //top-right
                    size: new OpenLayers.Size(5, 'auto'),
                    anchor: new OpenLayers.Bounds(null, 5, 0, 30),
                    position: new OpenLayers.Pixel(-1271, 0)
                },
                { //bottom-left
                    size: new OpenLayers.Size('auto', 5),
                    anchor: new OpenLayers.Bounds(0, 0, 5, null),
                    position: new OpenLayers.Pixel(0, -641)
                },
                { //bottom-right
                    size: new OpenLayers.Size(5, 5),
                    anchor: new OpenLayers.Bounds(null, 0, 0, null),
                    position: new OpenLayers.Pixel(-1271, -641)
                },
                { // stem
                    size: new OpenLayers.Size(42, 32),
                    anchor: new OpenLayers.Bounds(null, null, 30, 2),
                    position: new OpenLayers.Pixel(-52, -697)
                }
            ]
          },
          "br": {
              'offset': new OpenLayers.Pixel(-50, 5),
              'padding': new OpenLayers.Bounds(5, 5, 0, 35),
              'blocks': [
                { // top-left
                    size: new OpenLayers.Size('auto', 'auto'),
                    anchor: new OpenLayers.Bounds(0, 5, 5, 30),
                    position: new OpenLayers.Pixel(0, 0)
                },
                { //top-right
                    size: new OpenLayers.Size(5, 'auto'),
                    anchor: new OpenLayers.Bounds(null, 5, 0, 30),
                    position: new OpenLayers.Pixel(-1271, 0)
                },
                { //bottom-left
                    size: new OpenLayers.Size('auto', 5),
                    anchor: new OpenLayers.Bounds(0, 0, 5, null),
                    position: new OpenLayers.Pixel(0, -641)
                },
                { //bottom-right
                    size: new OpenLayers.Size(5, 5),
                    anchor: new OpenLayers.Bounds(null, 0, 0, null),
                    position: new OpenLayers.Pixel(-1275, -641)
                },
                { // stem
                    size: new OpenLayers.Size(42, 32),
                    anchor: new OpenLayers.Bounds(30, null, null, 2),
                    position: new OpenLayers.Pixel(-52, -697)
                }
            ]
          }
      },       /**
      * APIProperty: minSize
      * {<OpenLayers.Size>}
      */
      minSize: new OpenLayers.Size(105, 10),       /**
      * APIProperty: maxSize
      * {<OpenLayers.Size>}
      */
      maxSize: new OpenLayers.Size(1200, 660),       /** 
      * Constructor: OpenLayers.Popup.FramedCloud
      * 
      * Parameters:
      * id - {String}
      * lonlat - {<OpenLayers.LonLat>}
      * contentSize - {<OpenLayers.Size>}
      * contentHTML - {String}
      * anchor - {Object} Object to which we'll anchor the popup. Must expose 
      *     a 'size' (<OpenLayers.Size>) and 'offset' (<OpenLayers.Pixel>) 
      *     (Note that this is generally an <OpenLayers.Icon>).
      * closeBox - {Boolean}
      * closeBoxCallback - {Function} Function to be called on closeBox click.
      */
      initialize: function (id, lonlat, contentSize, contentHTML, anchor, closeBox,
                        closeBoxCallback) {           this.imageSrc = OpenLayers.Util.getImageLocation('fresh-popup-relative.gif');
          OpenLayers.Popup.Framed.prototype.initialize.apply(this, arguments);
          this.contentDiv.className = this.contentDisplayClass;
      },       CLASS_NAME: "OpenLayers.Popup.FreshCloud"

}); 

JS文件地址:http://files.cnblogs.com/wanfeng/FreshCloud.js

图片地址: http://files.cnblogs.com/wanfeng/fresh-popup-relative.gif

openlayers中实现自定冒泡的效果的更多相关文章

  1. OpenLayers中的图层

    OpenLayers有多个不同的图层类,每一个都可以连接到不同的地图服务器.例如通过Layer.WMS类可以连接到WMS地图服务器,通过Layer.Google类可以连接到谷歌地图服务器.OpenLa ...

  2. 理解JavaScript中的事件处理 阻止冒泡event.stopPropagation();

    原文地址:http://www.cnblogs.com/binyong/articles/1750263.html 这篇文章对于了解Javascript的事件处理机制非常好,将它全文转载于此,以备不时 ...

  3. 在WPF中使用PlaneProjection模拟动态3D效果

    原文:在WPF中使用PlaneProjection模拟动态3D效果 虽然在WPF中也集成了3D呈现的功能,在简单的3D应用中,有时候并不需要真实光影的3D场景.毕竟使用3D引擎会消耗很多资源,有时候使 ...

  4. OpenLayers中的图层(转载)

    作者:田念明出处:http://www.cnblogs.com/nianming/本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法 ...

  5. WPF中的事件及冒泡事件和隧道事件(预览事件)的区别

    WPF快速指导10:WPF中的事件及冒泡事件和隧道事件(预览事件)的区别   WPF快速指导10:WPF中的事件及冒泡事件和隧道事件(预览事件)的区别 本文摘要: 1:什么是路由事件: 2:中断事件路 ...

  6. openlayers中单击获取要素

    openlayers中单击获取要素 分类专栏: GIS 总结 OpenLayers   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接: ...

  7. Web 开发中很实用的10个效果【附源码下载】

    在工作中,我们可能会用到各种交互效果.而这些效果在平常翻看文章的时候碰到很多,但是一时半会又想不起来在哪,所以养成知识整理的习惯是很有必要的.这篇文章给大家推荐10个在 Web 开发中很有用的效果,记 ...

  8. 在IE6、IE7中实现块元素的inline-block效果

    在IE6.IE7中实现块元素的inline-block效果有以下两种方法: 1先使用display:inline-block属性触发layout,然后再定义display:inline让块元素呈现内联 ...

  9. bootstrap中table页面做省市区级联效果(级联库见前面级联编辑)(非select下拉框)

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

随机推荐

  1. Codeforces Round #325 (Div. 2) D bfs

    D. Phillip and Trains time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. 【转】以 java 为例,总结下 appium 里的一方法的使用心得

    转自:http://testerhome.com/topics/1043 1.关于没有name,没有ID的元素的定位---通用篇解题思路:因为没有name,id:其实剩下的选择已不多,要么xpath, ...

  3. GithubPage 的简单使用

    这是我第一次写博客,主要是记录自己前端学习的经历.这次写一下GitHubpage 的简单使用.我用这里并没有想挂博客,主要是挂自己的一些小作品应用到简历中. 第一步: 首先先注册Github账号,创建 ...

  4. hdu2348题解

    又恬不知耻的开始写题解了,暑假到了,QAQ然而想我这样的弱逼是没有暑假的sad,还是老老实实刷题吧. 题目大意:给一个小车的宽度和长度和两条道路的宽度,判断小车能否通过. 思路:可以先看下面的图,我们 ...

  5. 浅谈P NP NPC

    P问题:多项式时间内可以找到解的问题,这个解可以在多项式时间内验证. NP问题:有多项式时间内可以验证的解的问题,而并不能保证可以在多项式时间内找到这个解. 比如汉密尔顿回路,如果找到,在多项式时间内 ...

  6. grep命令学习

    grep(Globally search a Regular Expression and Print), 全面搜索正则表达式并把行打印出来,是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把 ...

  7. Base64加密与MD5的区别?

    MD5是一种不可逆的摘要算法.而Base64是一种编码方式,主要用于将二进制数据转换为文本数据,方便使用HTTP协议等,是可逆的.无论多少二进制数据,在MD5算法一定的情况下,都会变成一个定长的数据, ...

  8. POI2012

    现在才开始写 POI 是不是太弱了? -Rendezvous 怎么说呢,我发现我的代码好长啊-长啊-长啊-长长长长长长长长长长长长长长长长长长长长长长啊- 大概就是在一个内向树上搞一个类似 lca 的 ...

  9. Python之路,day9-Python基础

    回顾:抽象方法@staticmethod 不能访问类的任何属性@classmethod 类方法 只能访问公有属性@property 属性方法 , 把一个方法变成一个静态属性def sayhi() pa ...

  10. iOS NSTimer使用详解 开启、关闭、移除

    定时器定时器详解ios定时器关闭定时器NSTimer 一,要使用一个定时器首先要定义一个定时器: @property (strong, nonatomic) NSTimer *myTimer;//定时 ...