diff options
Diffstat (limited to 'misc/openlayers/lib/OpenLayers/Popup')
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Popup/Anchored.js | 195 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Popup/Framed.js | 343 | ||||
-rw-r--r-- | misc/openlayers/lib/OpenLayers/Popup/FramedCloud.js | 227 |
3 files changed, 765 insertions, 0 deletions
diff --git a/misc/openlayers/lib/OpenLayers/Popup/Anchored.js b/misc/openlayers/lib/OpenLayers/Popup/Anchored.js new file mode 100644 index 0000000..9415546 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Popup/Anchored.js @@ -0,0 +1,195 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + + +/** + * @requires OpenLayers/Popup.js + */ + +/** + * Class: OpenLayers.Popup.Anchored + * + * Inherits from: + * - <OpenLayers.Popup> + */ +OpenLayers.Popup.Anchored = + OpenLayers.Class(OpenLayers.Popup, { + + /** + * Property: relativePosition + * {String} Relative position of the popup ("br", "tr", "tl" or "bl"). + */ + relativePosition: null, + + /** + * APIProperty: keepInMap + * {Boolean} If panMapIfOutOfView is false, and this property is true, + * contrain the popup such that it always fits in the available map + * space. By default, this is set. If you are creating popups that are + * near map edges and not allowing pannning, and especially if you have + * a popup which has a fixedRelativePosition, setting this to false may + * be a smart thing to do. + * + * For anchored popups, default is true, since subclasses will + * usually want this functionality. + */ + keepInMap: true, + + /** + * Property: anchor + * {Object} Object to which we'll anchor the popup. Must expose a + * 'size' (<OpenLayers.Size>) and 'offset' (<OpenLayers.Pixel>). + */ + anchor: null, + + /** + * Constructor: OpenLayers.Popup.Anchored + * + * Parameters: + * id - {String} + * lonlat - {<OpenLayers.LonLat>} + * contentSize - {<OpenLayers.Size>} + * contentHTML - {String} + * anchor - {Object} Object which must expose a 'size' <OpenLayers.Size> + * and 'offset' <OpenLayers.Pixel> (generally an <OpenLayers.Icon>). + * closeBox - {Boolean} + * closeBoxCallback - {Function} Function to be called on closeBox click. + */ + initialize:function(id, lonlat, contentSize, contentHTML, anchor, closeBox, + closeBoxCallback) { + var newArguments = [ + id, lonlat, contentSize, contentHTML, closeBox, closeBoxCallback + ]; + OpenLayers.Popup.prototype.initialize.apply(this, newArguments); + + this.anchor = (anchor != null) ? anchor + : { size: new OpenLayers.Size(0,0), + offset: new OpenLayers.Pixel(0,0)}; + }, + + /** + * APIMethod: destroy + */ + destroy: function() { + this.anchor = null; + this.relativePosition = null; + + OpenLayers.Popup.prototype.destroy.apply(this, arguments); + }, + + /** + * APIMethod: show + * Overridden from Popup since user might hide popup and then show() it + * in a new location (meaning we might want to update the relative + * position on the show) + */ + show: function() { + this.updatePosition(); + OpenLayers.Popup.prototype.show.apply(this, arguments); + }, + + /** + * Method: moveTo + * Since the popup is moving to a new px, it might need also to be moved + * relative to where the marker is. We first calculate the new + * relativePosition, and then we calculate the new px where we will + * put the popup, based on the new relative position. + * + * If the relativePosition has changed, we must also call + * updateRelativePosition() to make any visual changes to the popup + * which are associated with putting it in a new relativePosition. + * + * Parameters: + * px - {<OpenLayers.Pixel>} + */ + moveTo: function(px) { + var oldRelativePosition = this.relativePosition; + this.relativePosition = this.calculateRelativePosition(px); + + OpenLayers.Popup.prototype.moveTo.call(this, this.calculateNewPx(px)); + + //if this move has caused the popup to change its relative position, + // we need to make the appropriate cosmetic changes. + if (this.relativePosition != oldRelativePosition) { + this.updateRelativePosition(); + } + }, + + /** + * APIMethod: setSize + * + * Parameters: + * contentSize - {<OpenLayers.Size>} the new size for the popup's + * contents div (in pixels). + */ + setSize:function(contentSize) { + OpenLayers.Popup.prototype.setSize.apply(this, arguments); + + if ((this.lonlat) && (this.map)) { + var px = this.map.getLayerPxFromLonLat(this.lonlat); + this.moveTo(px); + } + }, + + /** + * 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); + }, + + /** + * Method: updateRelativePosition + * The popup has been moved to a new relative location, so we may want to + * make some cosmetic adjustments to it. + * + * Note that in the classic Anchored popup, there is nothing to do + * here, since the popup looks exactly the same in all four positions. + * Subclasses such as Framed, however, will want to do something + * special here. + */ + updateRelativePosition: function() { + //to be overridden by subclasses + }, + + /** + * Method: calculateNewPx + * + * Parameters: + * px - {<OpenLayers.Pixel>} + * + * Returns: + * {<OpenLayers.Pixel>} The the new px position of the popup on the screen + * relative to the passed-in px. + */ + calculateNewPx:function(px) { + var newPx = px.offset(this.anchor.offset); + + //use contentSize if size is not already set + var size = this.size || this.contentSize; + + var top = (this.relativePosition.charAt(0) == 't'); + newPx.y += (top) ? -size.h : this.anchor.size.h; + + var left = (this.relativePosition.charAt(1) == 'l'); + newPx.x += (left) ? -size.w : this.anchor.size.w; + + return newPx; + }, + + CLASS_NAME: "OpenLayers.Popup.Anchored" +}); diff --git a/misc/openlayers/lib/OpenLayers/Popup/Framed.js b/misc/openlayers/lib/OpenLayers/Popup/Framed.js new file mode 100644 index 0000000..cb2d5d9 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Popup/Framed.js @@ -0,0 +1,343 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Popup/Anchored.js + */ + +/** + * Class: OpenLayers.Popup.Framed + * + * Inherits from: + * - <OpenLayers.Popup.Anchored> + */ +OpenLayers.Popup.Framed = + OpenLayers.Class(OpenLayers.Popup.Anchored, { + + /** + * Property: imageSrc + * {String} location of the image to be used as the popup frame + */ + imageSrc: null, + + /** + * Property: imageSize + * {<OpenLayers.Size>} Size (measured in pixels) of the image located + * by the 'imageSrc' property. + */ + imageSize: null, + + /** + * APIProperty: isAlphaImage + * {Boolean} The image has some alpha and thus needs to use the alpha + * image hack. Note that setting this to true will have no noticeable + * effect in FF or IE7 browsers, but will all but crush the ie6 + * browser. + * Default is false. + */ + isAlphaImage: false, + + /** + * Property: positionBlocks + * {Object} Hash of different position blocks (Object/Hashs). Each block + * will be keyed by a two-character 'relativePosition' + * code string (ie "tl", "tr", "bl", "br"). Block properties are + * 'offset', 'padding' (self-explanatory), and finally the 'blocks' + * parameter, which is an array of the block objects. + * + * Each block object must have 'size', 'anchor', and 'position' + * properties. + * + * Note that positionBlocks should never be modified at runtime. + */ + positionBlocks: null, + + /** + * Property: blocks + * {Array[Object]} Array of objects, each of which is one "block" of the + * popup. Each block has a 'div' and an 'image' property, both of + * which are DOMElements, and the latter of which is appended to the + * former. These are reused as the popup goes changing positions for + * great economy and elegance. + */ + blocks: null, + + /** + * APIProperty: fixedRelativePosition + * {Boolean} We want the framed popup to work dynamically placed relative + * to its anchor but also in just one fixed position. A well designed + * framed popup will have the pixels and logic to display itself in + * any of the four relative positions, but (understandably), this will + * not be the case for all of them. By setting this property to 'true', + * framed popup will not recalculate for the best placement each time + * it's open, but will always open the same way. + * Note that if this is set to true, it is generally advisable to also + * set the 'panIntoView' property to true so that the popup can be + * scrolled into view (since it will often be offscreen on open) + * Default is false. + */ + fixedRelativePosition: false, + + /** + * Constructor: OpenLayers.Popup.Framed + * + * 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) { + + OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments); + + if (this.fixedRelativePosition) { + //based on our decided relativePostion, set the current padding + // this keeps us from getting into trouble + this.updateRelativePosition(); + + //make calculateRelativePosition always return the specified + // fixed position. + this.calculateRelativePosition = function(px) { + return this.relativePosition; + }; + } + + this.contentDiv.style.position = "absolute"; + this.contentDiv.style.zIndex = 1; + + if (closeBox) { + this.closeDiv.style.zIndex = 1; + } + + this.groupDiv.style.position = "absolute"; + this.groupDiv.style.top = "0px"; + this.groupDiv.style.left = "0px"; + this.groupDiv.style.height = "100%"; + this.groupDiv.style.width = "100%"; + }, + + /** + * APIMethod: destroy + */ + destroy: function() { + this.imageSrc = null; + this.imageSize = null; + this.isAlphaImage = null; + + this.fixedRelativePosition = false; + this.positionBlocks = null; + + //remove our blocks + for(var i = 0; i < this.blocks.length; i++) { + var block = this.blocks[i]; + + if (block.image) { + block.div.removeChild(block.image); + } + block.image = null; + + if (block.div) { + this.groupDiv.removeChild(block.div); + } + block.div = null; + } + this.blocks = null; + + OpenLayers.Popup.Anchored.prototype.destroy.apply(this, arguments); + }, + + /** + * APIMethod: setBackgroundColor + */ + setBackgroundColor:function(color) { + //does nothing since the framed popup's entire scheme is based on a + // an image -- changing the background color makes no sense. + }, + + /** + * APIMethod: setBorder + */ + setBorder:function() { + //does nothing since the framed popup's entire scheme is based on a + // an image -- changing the popup's border makes no sense. + }, + + /** + * Method: setOpacity + * Sets the opacity of the popup. + * + * Parameters: + * opacity - {float} A value between 0.0 (transparent) and 1.0 (solid). + */ + setOpacity:function(opacity) { + //does nothing since we suppose that we'll never apply an opacity + // to a framed popup + }, + + /** + * APIMethod: setSize + * Overridden here, because we need to update the blocks whenever the size + * of the popup has changed. + * + * Parameters: + * contentSize - {<OpenLayers.Size>} the new size for the popup's + * contents div (in pixels). + */ + setSize:function(contentSize) { + OpenLayers.Popup.Anchored.prototype.setSize.apply(this, arguments); + + this.updateBlocks(); + }, + + /** + * Method: updateRelativePosition + * When the relative position changes, we need to set the new padding + * BBOX on the popup, reposition the close div, and update the blocks. + */ + updateRelativePosition: function() { + + //update the padding + this.padding = this.positionBlocks[this.relativePosition].padding; + + //update the position of our close box to new padding + if (this.closeDiv) { + // use the content div's css padding to determine if we should + // padd the close div + var contentDivPadding = this.getContentDivPadding(); + + this.closeDiv.style.right = contentDivPadding.right + + this.padding.right + "px"; + this.closeDiv.style.top = contentDivPadding.top + + this.padding.top + "px"; + } + + this.updateBlocks(); + }, + + /** + * Method: calculateNewPx + * Besides the standard offset as determined by the Anchored class, our + * Framed popups have a special 'offset' property for each of their + * positions, which is used to offset the popup relative to its anchor. + * + * Parameters: + * px - {<OpenLayers.Pixel>} + * + * Returns: + * {<OpenLayers.Pixel>} The the new px position of the popup on the screen + * relative to the passed-in px. + */ + calculateNewPx:function(px) { + var newPx = OpenLayers.Popup.Anchored.prototype.calculateNewPx.apply( + this, arguments + ); + + newPx = newPx.offset(this.positionBlocks[this.relativePosition].offset); + + return newPx; + }, + + /** + * Method: createBlocks + */ + createBlocks: function() { + this.blocks = []; + + //since all positions contain the same number of blocks, we can + // just pick the first position and use its blocks array to create + // our blocks array + var firstPosition = null; + for(var key in this.positionBlocks) { + firstPosition = key; + break; + } + + var position = this.positionBlocks[firstPosition]; + for (var i = 0; i < position.blocks.length; i++) { + + var block = {}; + this.blocks.push(block); + + var divId = this.id + '_FrameDecorationDiv_' + i; + block.div = OpenLayers.Util.createDiv(divId, + null, null, null, "absolute", null, "hidden", null + ); + + var imgId = this.id + '_FrameDecorationImg_' + i; + var imageCreator = + (this.isAlphaImage) ? OpenLayers.Util.createAlphaImageDiv + : OpenLayers.Util.createImage; + + block.image = imageCreator(imgId, + null, this.imageSize, this.imageSrc, + "absolute", null, null, null + ); + + block.div.appendChild(block.image); + this.groupDiv.appendChild(block.div); + } + }, + + /** + * Method: updateBlocks + * Internal method, called on initialize and when the popup's relative + * position has changed. This function takes care of re-positioning + * the popup's blocks in their appropropriate places. + */ + updateBlocks: function() { + if (!this.blocks) { + this.createBlocks(); + } + + if (this.size && this.relativePosition) { + var position = this.positionBlocks[this.relativePosition]; + for (var i = 0; i < position.blocks.length; i++) { + + var positionBlock = position.blocks[i]; + var block = this.blocks[i]; + + // adjust sizes + var l = positionBlock.anchor.left; + var b = positionBlock.anchor.bottom; + var r = positionBlock.anchor.right; + var t = positionBlock.anchor.top; + + //note that we use the isNaN() test here because if the + // size object is initialized with a "auto" parameter, the + // size constructor calls parseFloat() on the string, + // which will turn it into NaN + // + var w = (isNaN(positionBlock.size.w)) ? this.size.w - (r + l) + : positionBlock.size.w; + + var h = (isNaN(positionBlock.size.h)) ? this.size.h - (b + t) + : positionBlock.size.h; + + block.div.style.width = (w < 0 ? 0 : w) + 'px'; + block.div.style.height = (h < 0 ? 0 : h) + 'px'; + + block.div.style.left = (l != null) ? l + 'px' : ''; + block.div.style.bottom = (b != null) ? b + 'px' : ''; + block.div.style.right = (r != null) ? r + 'px' : ''; + block.div.style.top = (t != null) ? t + 'px' : ''; + + block.image.style.left = positionBlock.position.x + 'px'; + block.image.style.top = positionBlock.position.y + 'px'; + } + + this.contentDiv.style.left = this.padding.left + "px"; + this.contentDiv.style.top = this.padding.top + "px"; + } + }, + + CLASS_NAME: "OpenLayers.Popup.Framed" +}); diff --git a/misc/openlayers/lib/OpenLayers/Popup/FramedCloud.js b/misc/openlayers/lib/OpenLayers/Popup/FramedCloud.js new file mode 100644 index 0000000..8ad8b94 --- /dev/null +++ b/misc/openlayers/lib/OpenLayers/Popup/FramedCloud.js @@ -0,0 +1,227 @@ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + +/** + * @requires OpenLayers/Popup/Framed.js + * @requires OpenLayers/Util.js + * @requires OpenLayers/BaseTypes/Bounds.js + * @requires OpenLayers/BaseTypes/Pixel.js + * @requires OpenLayers/BaseTypes/Size.js + */ + +/** + * Class: OpenLayers.Popup.FramedCloud + * + * Inherits from: + * - <OpenLayers.Popup.Framed> + */ +OpenLayers.Popup.FramedCloud = + OpenLayers.Class(OpenLayers.Popup.Framed, { + + /** + * Property: contentDisplayClass + * {String} The CSS class of the popup content div. + */ + contentDisplayClass: "olFramedCloudPopupContent", + + /** + * 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(44, 0), + 'padding': new OpenLayers.Bounds(8, 40, 8, 9), + 'blocks': [ + { // top-left + size: new OpenLayers.Size('auto', 'auto'), + anchor: new OpenLayers.Bounds(0, 51, 22, 0), + position: new OpenLayers.Pixel(0, 0) + }, + { //top-right + size: new OpenLayers.Size(22, 'auto'), + anchor: new OpenLayers.Bounds(null, 50, 0, 0), + position: new OpenLayers.Pixel(-1238, 0) + }, + { //bottom-left + size: new OpenLayers.Size('auto', 19), + anchor: new OpenLayers.Bounds(0, 32, 22, null), + position: new OpenLayers.Pixel(0, -631) + }, + { //bottom-right + size: new OpenLayers.Size(22, 18), + anchor: new OpenLayers.Bounds(null, 32, 0, null), + position: new OpenLayers.Pixel(-1238, -632) + }, + { // stem + size: new OpenLayers.Size(81, 35), + anchor: new OpenLayers.Bounds(null, 0, 0, null), + position: new OpenLayers.Pixel(0, -688) + } + ] + }, + "tr": { + 'offset': new OpenLayers.Pixel(-45, 0), + 'padding': new OpenLayers.Bounds(8, 40, 8, 9), + 'blocks': [ + { // top-left + size: new OpenLayers.Size('auto', 'auto'), + anchor: new OpenLayers.Bounds(0, 51, 22, 0), + position: new OpenLayers.Pixel(0, 0) + }, + { //top-right + size: new OpenLayers.Size(22, 'auto'), + anchor: new OpenLayers.Bounds(null, 50, 0, 0), + position: new OpenLayers.Pixel(-1238, 0) + }, + { //bottom-left + size: new OpenLayers.Size('auto', 19), + anchor: new OpenLayers.Bounds(0, 32, 22, null), + position: new OpenLayers.Pixel(0, -631) + }, + { //bottom-right + size: new OpenLayers.Size(22, 19), + anchor: new OpenLayers.Bounds(null, 32, 0, null), + position: new OpenLayers.Pixel(-1238, -631) + }, + { // stem + size: new OpenLayers.Size(81, 35), + anchor: new OpenLayers.Bounds(0, 0, null, null), + position: new OpenLayers.Pixel(-215, -687) + } + ] + }, + "bl": { + 'offset': new OpenLayers.Pixel(45, 0), + 'padding': new OpenLayers.Bounds(8, 9, 8, 40), + 'blocks': [ + { // top-left + size: new OpenLayers.Size('auto', 'auto'), + anchor: new OpenLayers.Bounds(0, 21, 22, 32), + position: new OpenLayers.Pixel(0, 0) + }, + { //top-right + size: new OpenLayers.Size(22, 'auto'), + anchor: new OpenLayers.Bounds(null, 21, 0, 32), + position: new OpenLayers.Pixel(-1238, 0) + }, + { //bottom-left + size: new OpenLayers.Size('auto', 21), + anchor: new OpenLayers.Bounds(0, 0, 22, null), + position: new OpenLayers.Pixel(0, -629) + }, + { //bottom-right + size: new OpenLayers.Size(22, 21), + anchor: new OpenLayers.Bounds(null, 0, 0, null), + position: new OpenLayers.Pixel(-1238, -629) + }, + { // stem + size: new OpenLayers.Size(81, 33), + anchor: new OpenLayers.Bounds(null, null, 0, 0), + position: new OpenLayers.Pixel(-101, -674) + } + ] + }, + "br": { + 'offset': new OpenLayers.Pixel(-44, 0), + 'padding': new OpenLayers.Bounds(8, 9, 8, 40), + 'blocks': [ + { // top-left + size: new OpenLayers.Size('auto', 'auto'), + anchor: new OpenLayers.Bounds(0, 21, 22, 32), + position: new OpenLayers.Pixel(0, 0) + }, + { //top-right + size: new OpenLayers.Size(22, 'auto'), + anchor: new OpenLayers.Bounds(null, 21, 0, 32), + position: new OpenLayers.Pixel(-1238, 0) + }, + { //bottom-left + size: new OpenLayers.Size('auto', 21), + anchor: new OpenLayers.Bounds(0, 0, 22, null), + position: new OpenLayers.Pixel(0, -629) + }, + { //bottom-right + size: new OpenLayers.Size(22, 21), + anchor: new OpenLayers.Bounds(null, 0, 0, null), + position: new OpenLayers.Pixel(-1238, -629) + }, + { // stem + size: new OpenLayers.Size(81, 33), + anchor: new OpenLayers.Bounds(0, null, null, 0), + position: new OpenLayers.Pixel(-311, -674) + } + ] + } + }, + + /** + * 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('cloud-popup-relative.png'); + OpenLayers.Popup.Framed.prototype.initialize.apply(this, arguments); + this.contentDiv.className = this.contentDisplayClass; + }, + + CLASS_NAME: "OpenLayers.Popup.FramedCloud" +}); |