| | 98 | * Property: border |
|---|
| | 99 | * {String} the border size of the popup. (eg 2px) |
|---|
| | 100 | */ |
|---|
| | 101 | border: "", |
|---|
| | 102 | |
|---|
| | 103 | /** |
|---|
| | 104 | * Property: contentDiv |
|---|
| | 105 | * {DOMElement} a reference to the element that holds the content of |
|---|
| | 106 | * the div. |
|---|
| | 107 | */ |
|---|
| | 108 | contentDiv: null, |
|---|
| | 109 | |
|---|
| | 110 | /** |
|---|
| | 111 | * Property: groupDiv |
|---|
| | 112 | * {DOMElement} First and only child of 'div'. The group Div contains the |
|---|
| | 113 | * 'contentDiv' and the 'closeDiv'. |
|---|
| | 114 | */ |
|---|
| | 115 | groupDiv: null, |
|---|
| | 116 | |
|---|
| | 117 | /** |
|---|
| | 118 | * Property: closeDiv |
|---|
| | 119 | * {DOMElement} the optional closer image |
|---|
| | 120 | */ |
|---|
| | 121 | closeDiv: null, |
|---|
| | 122 | |
|---|
| | 123 | /** |
|---|
| | 124 | * APIProperty: autoSize |
|---|
| | 125 | * {Boolean} Resize the popup to auto-fit the contents. |
|---|
| | 126 | * Default is false. |
|---|
| | 127 | */ |
|---|
| | 128 | autoSize: false, |
|---|
| | 129 | |
|---|
| | 130 | /** |
|---|
| | 131 | * APIProperty: minSize |
|---|
| | 132 | * {<OpenLayers.Size>} Minimum size allowed for the popup's contents. |
|---|
| | 133 | */ |
|---|
| | 134 | minSize: null, |
|---|
| | 135 | |
|---|
| | 136 | /** |
|---|
| | 137 | * APIProperty: maxSize |
|---|
| | 138 | * {<OpenLayers.Size>} Maximum size allowed for the popup's contents. |
|---|
| | 139 | */ |
|---|
| | 140 | maxSize: null, |
|---|
| | 141 | |
|---|
| | 142 | /** |
|---|
| | 143 | * APIProperty: margin |
|---|
| | 144 | * {<OpenLayers.Bounds>} Outside margin of the popup. Used to prevent |
|---|
| | 145 | * the popup from getting too close to the map border. |
|---|
| | 146 | */ |
|---|
| | 147 | margin: null, |
|---|
| | 148 | |
|---|
| | 149 | /** |
|---|
| | 150 | * APIProperty: panMapIfOutOfView |
|---|
| | 151 | * {Boolean} When drawn, pan map such that the entire popup is visible in |
|---|
| | 152 | * the current viewport (if necessary). |
|---|
| | 153 | * Default is false. |
|---|
| | 154 | */ |
|---|
| | 155 | panMapIfOutOfView: false, |
|---|
| | 156 | |
|---|
| | 157 | /** |
|---|
| 467 | | px = this.calculateRelativePosition(px, this.size); |
|---|
| 468 | | |
|---|
| 469 | | this.div.style.left = px.x + "px"; |
|---|
| 470 | | this.div.style.top = px.y + "px"; |
|---|
| | 544 | if ((px != null) && (this.div != null)) { |
|---|
| | 545 | px = this.calculateRelativePosition(px, this.size); |
|---|
| | 546 | this.div.style.left = px.x + "px"; |
|---|
| | 547 | this.div.style.top = px.y + "px"; |
|---|
| | 548 | } |
|---|
| | 549 | |
|---|
| | 550 | if (this.panMapIfOutOfView) { |
|---|
| | 551 | this.panIntoView(); |
|---|
| | 552 | } |
|---|
| | 553 | |
|---|
| | 628 | /** |
|---|
| | 629 | * Method: addCloseBox |
|---|
| | 630 | * |
|---|
| | 631 | * Parameters: |
|---|
| | 632 | * callback - {Function} The callback to be called when the close button |
|---|
| | 633 | * is clicked. |
|---|
| | 634 | */ |
|---|
| | 635 | addCloseBox: function(callback) { |
|---|
| | 636 | |
|---|
| | 637 | // close icon |
|---|
| | 638 | var closeSize = new OpenLayers.Size(17,17); |
|---|
| | 639 | var img = OpenLayers.Util.getImagesLocation() + "close.gif"; |
|---|
| | 640 | this.closeDiv = OpenLayers.Util.createAlphaImageDiv( |
|---|
| | 641 | this.id + "_close", null, closeSize, img |
|---|
| | 642 | ); |
|---|
| | 643 | |
|---|
| | 644 | //this is a workaround since API respect won't let us mandate |
|---|
| | 645 | // padding be a Bounds object. This needs to be removed in 3.0 |
|---|
| | 646 | // |
|---|
| | 647 | this.fixPadding(); |
|---|
| | 648 | |
|---|
| | 649 | this.closeDiv.style.right = this.padding.right + "px"; |
|---|
| | 650 | this.closeDiv.style.top = this.padding.top + "px"; |
|---|
| | 651 | this.groupDiv.appendChild(this.closeDiv); |
|---|
| | 652 | |
|---|
| | 653 | var closePopup = callback || function(e) { |
|---|
| | 654 | this.hide(); |
|---|
| | 655 | OpenLayers.Event.stop(e); |
|---|
| | 656 | }; |
|---|
| | 657 | OpenLayers.Event.observe(this.closeDiv, "click", |
|---|
| | 658 | OpenLayers.Function.bindAsEventListener(closePopup, this)); |
|---|
| | 659 | }, |
|---|
| | 660 | |
|---|
| | 661 | /** |
|---|
| | 662 | * Method: panIntoView |
|---|
| | 663 | * Pans the map such that the popup is totaly viewable (if necessary) |
|---|
| | 664 | */ |
|---|
| | 665 | panIntoView: function() { |
|---|
| | 666 | |
|---|
| | 667 | var mapSize = this.map.getSize(); |
|---|
| | 668 | |
|---|
| | 669 | //start with the top left corner of the popup, in px, |
|---|
| | 670 | // relative to the viewport |
|---|
| | 671 | var origTL = this.map.getViewPortPxFromLayerPx( new OpenLayers.Pixel( |
|---|
| | 672 | parseInt(this.div.style.left), |
|---|
| | 673 | parseInt(this.div.style.top) |
|---|
| | 674 | )); |
|---|
| | 675 | var newTL = origTL.clone(); |
|---|
| | 676 | |
|---|
| | 677 | //new left (compare to margins, using this.size to calculate right) |
|---|
| | 678 | if (origTL.x < this.margin.left) { |
|---|
| | 679 | newTL.x = this.margin.left; |
|---|
| | 680 | } else |
|---|
| | 681 | if ( (origTL.x + this.size.w) > (mapSize.w - this.margin.right)) { |
|---|
| | 682 | newTL.x = mapSize.w - this.margin.right - this.size.w; |
|---|
| | 683 | } |
|---|
| | 684 | |
|---|
| | 685 | //new top (compare to margins, using this.size to calculate bottom) |
|---|
| | 686 | if (origTL.y < this.margin.top) { |
|---|
| | 687 | newTL.y = this.margin.top; |
|---|
| | 688 | } else |
|---|
| | 689 | if ( (origTL.y + this.size.h) > (mapSize.h - this.margin.bottom)) { |
|---|
| | 690 | newTL.y = mapSize.h - this.margin.bottom - this.size.h; |
|---|
| | 691 | } |
|---|
| | 692 | |
|---|
| | 693 | var dx = origTL.x - newTL.x; |
|---|
| | 694 | var dy = origTL.y - newTL.y; |
|---|
| | 695 | |
|---|
| | 696 | this.map.pan(dx, dy); |
|---|
| | 697 | }, |
|---|
| 553 | | this.events.register("mousedown", this, this.onmousedown); |
|---|
| 554 | | this.events.register("mousemove", this, this.onmousemove); |
|---|
| 555 | | this.events.register("mouseup", this, this.onmouseup); |
|---|
| 556 | | this.events.register("click", this, this.onclick); |
|---|
| 557 | | this.events.register("mouseout", this, this.onmouseout); |
|---|
| 558 | | this.events.register("dblclick", this, this.ondblclick); |
|---|
| 559 | | this.events.register("mouseover", this, this.onmouseover); |
|---|
| 560 | | }, |
|---|
| | 722 | this.events.on({ |
|---|
| | 723 | "mousedown": this.onmousedown, |
|---|
| | 724 | "mousemove": this.onmousemove, |
|---|
| | 725 | "mouseup": this.onmouseup, |
|---|
| | 726 | "onmouseover": this.onmouseover, |
|---|
| | 727 | "click": this.onclick, |
|---|
| | 728 | "mouseout": this.onmouseout, |
|---|
| | 729 | "dblclick": this.ondblclick, |
|---|
| | 730 | scope: this |
|---|
| | 731 | }); |
|---|
| | 732 | |
|---|
| | 733 | }, |
|---|