/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the * full text of the license. */ /** * @requires OpenLayers/Control.js */ /** * Class: OpenLayers.Control.Bookmark * A bookmark view control. Store an array of locations * refrenced by a label. * * Inherits from: * - */ OpenLayers.Control.Bookmark = OpenLayers.Class(OpenLayers.Control, { /** * Property: type * {String} */ type: OpenLayers.Control.TYPE_TOOL, /** * Property: stackState * {Boolean} Flag to indicate if the control needs to be redrawn. We have * this in order to avoid unnecessarily redrawing the control. */ stackState: true, /** * APIProperty: limit * {Integer} Optional limit on the number of bookmark items to retain. * Default is 50. 0 is no limit. */ limit: 50, /** * APIProperty: stack * {Array} Array of items in the list. */ stack: null, /** * APIProperty: allowRemove * {Boolean} Allow the bookmark to be removed. * Default to true. */ allowRemove: true, // DOM Elements /** * Property: contentDiv * {DOMElement} */ contentDiv: null, /** * Property: dataLblDiv * {DOMElement} */ dataLblDiv: null, /** * Property: dataElementDiv * {DOMElement} */ dataElementDiv: null, /** * Property: minimizeDiv * {DOMElement} */ minimizeDiv: null, /** * Property: maximizeDiv * {DOMElement} */ maximizeDiv: null, /** * Constructor: OpenLayers.Control.Bookmark * * Parameters: * options - {func} An optional object whose properties will be used * to extend the control. */ initialize: function(options) { OpenLayers.Control.prototype.initialize.apply(this, [options]); this.initStack(); }, /** * APIMethod: destroy * Destroy the control. */ /* FIXME - not sure i'm stopping observation correctly*/ destroy: function() { this.stack=null; OpenLayers.Event.stopObservingElement(this.div); OpenLayers.Event.stopObservingElement(this.minimizeDiv); OpenLayers.Event.stopObservingElement(this.maximizeDiv); OpenLayers.Control.prototype.destroy.apply(this); }, /** * Method: initStack * Initialize the stack and get ready for adds. */ initStack: function() { this.stack = []; this.stackState = true; }, /** * APIMethod: add * Add an item to the stack as label, bounds. If no label is specified * "NONAME" is used. * * Parameters: * label - {String} Label reference to this bookmark * bounds - {Object or String} * Object is a OpenLayers.bounds object or * String representation of bounds in format of * "-180,-180,180,180" * * Returns: * {Boolean} False if limit reached. True if added successfully. */ add: function(label, bounds, func, param) { if(this.stack.length == this.limit && this.limit != 0) { return false; // limit reached } func = (typeof func == "undefined") ? function() {} : func; param = (typeof param == "undefined" || param.length == 0) ? "" : param; label = (label == "undefined" || label.length == 0) ? "NONAME" : label; this.stack.push({ "label":label.toUpperCase(), "bounds":bounds, "func": func, "param": param, "id": this.stack.length }); this.stackState = true; this.redraw(); return true; }, /** * APIMethod: clear * Clear and reset the stack then redraw the div. */ clear: function() { this.initStack(); this.redraw(); }, /** * APIMethod: remove * Remove item from the stack. * * Parameters: * label - {String} Remove from the stack referenced by label. * * Returns: * {Boolean} False if not found or not allowed to remove. */ /* FIXME - not sure i'm stopping observation correctly*/ remove: function(label) { if(!this.allowRemove) { return false; } label = label.toUpperCase(); for(var i=0; i y) ? 1 : 0)); }, /** * Method: sortById * Sort stack by id values. Called by sort(). */ sortById: function(a, b) { var x = a.id; var y = b.id; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }, /** * APIMethod: reindex * Reindex stack; realign id with stack index. Usually called * after sortStack, add or remove. */ reindex: function() { for( var i=0; i} bookmark * - {String} label * - {String} action */ onBookmarkClick: function(e) { switch(this.action) { case "remove": this.bookmark.remove(this.label); break; case "zoom": default: this.bookmark.zoomToLabel(this.label); break } OpenLayers.Event.stop(e); }, /** * Method: showControls * Hide/Show all controls depending on whether we are * minimized or not * * Parameters: * minimize - {Boolean} */ showControls: function(minimize) { this.maximizeDiv.style.display = minimize ? "block" : "none"; this.minimizeDiv.style.display = minimize ? "none" : "block"; this.contentDiv.style.display = minimize ? "none" : "block"; }, /** * Method: showToggle * Hide/Show the toggle depending on whether the control is minimized * * Parameters: * minimize - {Boolean} */ showToggle: function(minimize) { this.maximizeDiv.style.display = minimize ? "block" : "none"; this.minimizeDiv.style.display = minimize ? "none" : "block"; }, /** * Method: ignoreEvent * * Parameters: * evt - {Event} */ ignoreEvent: function(evt) { OpenLayers.Event.stop(evt); }, /** * Method: mouseDown * Register a local 'mouseDown' flag so that we'll know whether or not * to ignore a mouseUp event * * Parameters: * evt - {Event} */ mouseDown: function(evt) { this.isMouseDown = true; this.ignoreEvent(evt); }, /** * Method: mouseUp * If the 'isMouseDown' flag has been set, that means that the drag was * started from within the control, and thus we can * ignore the mouseup. Otherwise, let the Event continue. * * Parameters: * evt - {Event} */ mouseUp: function(evt) { if (this.isMouseDown) { this.isMouseDown = false; this.ignoreEvent(evt); } }, CLASS_NAME: "OpenLayers.Control.Bookmark" }); OpenLayers.Control.Bookmark.VERSION_NUMBER = '2.1';