[OpenLayers-Commits] r12175 - in addins/bookmark: release release/2.1 release/2.2 trunk trunk/examples trunk/lib/OpenLayers/Control trunk/tests/Control

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Jul 20 15:11:12 EDT 2011


Author: hpbrantley
Date: 2011-07-20 12:11:11 -0700 (Wed, 20 Jul 2011)
New Revision: 12175

Added:
   addins/bookmark/release/2.1/
   addins/bookmark/release/2.1/README.txt
   addins/bookmark/release/2.2/
   addins/bookmark/release/2.2/README.txt
   addins/bookmark/trunk/README.txt
   addins/bookmark/trunk/examples/bookmark-cookie.html
Modified:
   addins/bookmark/trunk/examples/bookmark-custom.html
   addins/bookmark/trunk/lib/OpenLayers/Control/Bookmark.js
   addins/bookmark/trunk/tests/Control/Bookmark.html
Log:
2.2 version update

Added: addins/bookmark/release/2.1/README.txt
===================================================================
--- addins/bookmark/release/2.1/README.txt	                        (rev 0)
+++ addins/bookmark/release/2.1/README.txt	2011-07-20 19:11:11 UTC (rev 12175)
@@ -0,0 +1,122 @@
+Bookmark Control
+
+   1. Bookmark Control
+         1. Description
+         2. Examples
+         3. Installation and Use
+         4. Advanced Usage
+               1. Bookmarks with no containing DIV
+               2. Bookmarks Outside the Map
+               3. Passing A Function
+         5. Styling
+         6. Properties & Methods
+
+Description
+
+The Bookmark control provides a simple means to "bookmark" or "remember" a location. See OpenLayers Ticket #1583 for control history.
+
+Examples
+
+    * bookmark.html - A basic example of the Bookmark in action.
+    * bookmark-custom.html - An example demonstrating advanced configurations of the Bookmark control.
+
+Installation and Use
+
+   1. Use subversion to check out the Bookmark addin.
+   2. Place the Bookmark.js file in your Control directory (or alternatively, place it elsewhere and add a <script> tag to your page that points to it).
+   3. Use the build tools to create a single file build (or link to your OpenLayers.js file to run in development mode).
+   4. Add a stylesheet to your page to style the Bookmark, bookmark.css.
+   5. Construct a map and add a Bookmark to it with the following syntax:
+
+var map = new OpenLayers.Map("map");
+var bookmark = new OpenLayers.Control.Bookmark();
+
+/* when adding the control to the map, css elements are expected */
+map.addControl(bookmark);
+
+/* bookmark positions using a bounds object or string */
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033));
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033");
+
+Advanced Usage
+
+Bookmarks with no containing DIV
+
+The developer can allow interaction with the Bookmark control without adding it as a map control. Simply
+pass the map reference to the constructor. Using this method, the CSS declarations are not needed.
+
+var map = new OpenLayers.Map("map");
+var bookmark = new OpenLayers.Control.Bookmark({ 'map': map });
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033));
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033");
+
+Bookmarks Outside the Map
+
+<style>
+#myBookmarks { height: 200px; width: 15em; float: right; }
+#myBookmarks #olBookmarkElement { cursor : pointer; }
+</style>
+
+var map = new OpenLayers.Map("map");
+bookmark = new OpenLayers.Control.Bookmark({ 'div':OpenLayers.Util.getElement('myBookmarks'), 'title': 'Bookmarks outside the map' });
+map.addControl(bookmark);
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033));
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033");
+
+<body>
+<!-- Div to contain the bookmarks -->
+<div id="myBookmarks"></div>
+<div id="map"></div>
+</body>
+
+Passing A Function
+
+Passing a developer defined function and value. This function will be called when bookmark.zoomToLabel() or bookmark.zoomToId()
+methods are called. This can be triggered by the user clicking the bookmark in the DIV or, if no DIV is defined, using something similar to:
+
+var map = new OpenLayers.Map("map");
+var bookmark = new OpenLayers.Control.Bookmark();
+
+/* add a bookmark with user defined function and value */
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033),Msg,"Welcome to Boston");
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033",Msg,"Welcome to Boston");
+
+/* zoom to first found reference */
+bookmark.zoomTo(bookmark.find("boston")[0]);.
+
+function Msg(val) { alert(val); }
+
+Styling
+
+The look of the Bookmark contol is styled using CSS elements. If the Bookmark is used without a defining DIV, no CSS
+elements are required. See CSS examples bookmark.css.
+
+/* bookmark main div */
+.olControlBookmark {}
+
+/* bookmark content container */
+.olControlBookmarkContent {}
+
+/* bookmark title */
+.olControlBookmarkTitle {}
+
+/* bookmark data elements */
+.olControlBookmarkElements {}
+
+/* each row contains a remove element and link element */
+.olControlBookmarkRow {}
+.olControlBookmarkRemove {}
+.olControlBookmarkLink {}
+
+/* maximize and minimize buttons */
+.olControlBookmarkMaximizeButton {}
+.olControlBookmarkMinimizeButton {}
+
+Note: Rounding of the bookmark div corners is done by Rico outside of the class.
+
+OpenLayers.Rico.Corner.round( bookmark.div, {corners: "tl bl", bgColor: "transparent", color: "darkblue", blend: false});
+OpenLayers.Rico.Corner.changeOpacity(bookmark.contentDiv, 0.75);
+
+Properties & Methods
+
+See Bookmark.js for full descriptions.

Added: addins/bookmark/release/2.2/README.txt
===================================================================
--- addins/bookmark/release/2.2/README.txt	                        (rev 0)
+++ addins/bookmark/release/2.2/README.txt	2011-07-20 19:11:11 UTC (rev 12175)
@@ -0,0 +1,123 @@
+Bookmark Control
+
+   1. Bookmark Control
+         1. Description
+         2. Examples
+         3. Installation and Use
+         4. Advanced Usage
+               1. Bookmarks with no containing DIV
+               2. Bookmarks Outside the Map
+               3. Passing A Function
+         5. Styling
+         6. Properties & Methods
+
+Description
+
+The Bookmark control provides a simple means to "bookmark" or "remember" a location. See OpenLayers Ticket #1583 for control history.
+
+Examples
+
+    * bookmark.html - A basic example of the Bookmark in action.
+    * bookmark-custom.html - An example demonstrating advanced configurations of the Bookmark control.
+    * bookmark-cookie.html - An example demonstrating usage of storing bookmarks in a cookie.
+
+Installation and Use
+
+   1. Use subversion to check out the Bookmark addin.
+   2. Place the Bookmark.js file in your Control directory (or alternatively, place it elsewhere and add a <script> tag to your page that points to it).
+   3. Use the build tools to create a single file build (or link to your OpenLayers.js file to run in development mode).
+   4. Add a stylesheet to your page to style the Bookmark, bookmark.css.
+   5. Construct a map and add a Bookmark to it with the following syntax:
+
+var map = new OpenLayers.Map("map");
+var bookmark = new OpenLayers.Control.Bookmark();
+
+/* when adding the control to the map, css elements are expected */
+map.addControl(bookmark);
+
+/* bookmark positions using a bounds object or string */
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033));
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033");
+
+Advanced Usage
+
+Bookmarks with no containing DIV
+
+The developer can allow interaction with the Bookmark control without adding it as a map control. Simply
+pass the map reference to the constructor. Using this method, the CSS declarations are not needed.
+
+var map = new OpenLayers.Map("map");
+var bookmark = new OpenLayers.Control.Bookmark({ 'map': map });
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033));
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033");
+
+Bookmarks Outside the Map
+
+<style>
+#myBookmarks { height: 200px; width: 15em; float: right; }
+#myBookmarks #olBookmarkElement { cursor : pointer; }
+</style>
+
+var map = new OpenLayers.Map("map");
+bookmark = new OpenLayers.Control.Bookmark({ 'div':OpenLayers.Util.getElement('myBookmarks'), 'title': 'Bookmarks outside the map' });
+map.addControl(bookmark);
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033));
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033");
+
+<body>
+<!-- Div to contain the bookmarks -->
+<div id="myBookmarks"></div>
+<div id="map"></div>
+</body>
+
+Passing A Function
+
+Passing a developer defined function and value. This function will be called when bookmark.zoomToLabel() or bookmark.zoomToId()
+methods are called. This can be triggered by the user clicking the bookmark in the DIV or, if no DIV is defined, using something similar to:
+
+var map = new OpenLayers.Map("map");
+var bookmark = new OpenLayers.Control.Bookmark();
+
+/* add a bookmark with user defined function and value */
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033),Msg,"Welcome to Boston");
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033",Msg,"Welcome to Boston");
+
+/* zoom to first found reference */
+bookmark.zoomTo(bookmark.find("boston")[0]);.
+
+function Msg(val) { alert(val); }
+
+Styling
+
+The look of the Bookmark contol is styled using CSS elements. If the Bookmark is used without a defining DIV, no CSS
+elements are required. See CSS examples bookmark.css.
+
+/* bookmark main div */
+.olControlBookmark {}
+
+/* bookmark content container */
+.olControlBookmarkContent {}
+
+/* bookmark title */
+.olControlBookmarkTitle {}
+
+/* bookmark data elements */
+.olControlBookmarkElements {}
+
+/* each row contains a remove element and link element */
+.olControlBookmarkRow {}
+.olControlBookmarkRemove {}
+.olControlBookmarkLink {}
+
+/* maximize and minimize buttons */
+.olControlBookmarkMaximizeButton {}
+.olControlBookmarkMinimizeButton {}
+
+Note: Rounding of the bookmark div corners is done by Rico outside of the class.
+
+OpenLayers.Rico.Corner.round( bookmark.div, {corners: "tl bl", bgColor: "transparent", color: "darkblue", blend: false});
+OpenLayers.Rico.Corner.changeOpacity(bookmark.contentDiv, 0.75);
+
+Properties & Methods
+
+See Bookmark.js for full descriptions.

Added: addins/bookmark/trunk/README.txt
===================================================================
--- addins/bookmark/trunk/README.txt	                        (rev 0)
+++ addins/bookmark/trunk/README.txt	2011-07-20 19:11:11 UTC (rev 12175)
@@ -0,0 +1,141 @@
+Bookmark Control
+
+   1. Bookmark Control
+         1. Description
+         2. Examples
+         3. Installation and Use
+         4. Advanced Usage
+               1. Bookmarks with no containing DIV
+               2. Bookmarks Outside the Map
+               3. Passing A Function
+         5. Styling
+         6. Properties & Methods
+
+Description
+
+The Bookmark control provides a simple means to "bookmark" or "remember" a location. See OpenLayers Ticket #1583 for control history.
+
+Examples
+
+    * bookmark.html - A basic example of the Bookmark in action.
+    * bookmark-custom.html - An example demonstrating advanced configurations of the Bookmark control.
+    * bookmark-cookie.html - An example demonstrating usage of storing bookmarks in a cookie.
+
+Installation and Use
+
+   1. Use subversion to check out the Bookmark addin.
+   2. Place the Bookmark.js file in your Control directory (or alternatively, place it elsewhere and add a <script> tag to your page that points to it).
+   3. Use the build tools to create a single file build (or link to your OpenLayers.js file to run in development mode).
+   4. Add a stylesheet to your page to style the Bookmark, bookmark.css.
+   5. Construct a map and add a Bookmark to it with the following syntax:
+
+var map = new OpenLayers.Map("map");
+var bookmark = new OpenLayers.Control.Bookmark();
+
+/* when adding the control to the map, css elements are expected */
+map.addControl(bookmark);
+
+/* bookmark positions using a bounds object or string */
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033));
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033");
+
+Advanced Usage
+
+Bookmarks with no containing DIV
+
+The developer can allow interaction with the Bookmark control without adding it as a map control. Simply
+pass the map reference to the constructor. Using this method, the CSS declarations are not needed.
+
+var map = new OpenLayers.Map("map");
+var bookmark = new OpenLayers.Control.Bookmark({ 'map': map });
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033));
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033");
+
+Bookmarks Outside the Map
+
+<style>
+#myBookmarks { height: 200px; width: 15em; float: right; }
+#myBookmarks #olBookmarkElement { cursor : pointer; }
+</style>
+
+var map = new OpenLayers.Map("map");
+bookmark = new OpenLayers.Control.Bookmark({ 'div':OpenLayers.Util.getElement('myBookmarks'), 'title': 'Bookmarks outside the map' });
+map.addControl(bookmark);
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033));
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033");
+
+<body>
+<!-- Div to contain the bookmarks -->
+<div id="myBookmarks"></div>
+<div id="map"></div>
+</body>
+
+Passing A Function
+
+Passing a developer defined function and value. This function will be called when bookmark.zoomToLabel() or bookmark.zoomToId()
+methods are called. This can be triggered by the user clicking the bookmark in the DIV or, if no DIV is defined, using something similar to:
+
+var map = new OpenLayers.Map("map");
+var bookmark = new OpenLayers.Control.Bookmark();
+
+/* add a bookmark with user defined function and value */
+bookmark.add("BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033),Msg,"Welcome to Boston");
+bookmark.add("BOSTON TOO","-71.401901,41.989908,-70.698776,42.693033",Msg,"Welcome to Boston");
+
+/* zoom to first found reference */
+bookmark.zoomTo(bookmark.find("boston")[0]);.
+
+function Msg(val) { alert(val); }
+
+Storing in a cookie
+
+Version 2.2 added functions to handle cookie IO:
+
+store()
+Store the content of the stack into a cookie.
+
+toString()
+Returns the stack in a string in the format:
+Bookmark name seperated by : bounds | (if multiple)
+<name>:<llx>,<lly>,<urx>,<ury>|
+
+load()
+Load the contents of the cookie into the stack.
+
+expire()
+Remove the cookie.
+
+Styling
+
+The look of the Bookmark contol is styled using CSS elements. If the Bookmark is used without a defining DIV, no CSS
+elements are required. See CSS examples bookmark.css.
+
+/* bookmark main div */
+.olControlBookmark {}
+
+/* bookmark content container */
+.olControlBookmarkContent {}
+
+/* bookmark title */
+.olControlBookmarkTitle {}
+
+/* bookmark data elements */
+.olControlBookmarkElements {}
+
+/* each row contains a remove element and link element */
+.olControlBookmarkRow {}
+.olControlBookmarkRemove {}
+.olControlBookmarkLink {}
+
+/* maximize and minimize buttons */
+.olControlBookmarkMaximizeButton {}
+.olControlBookmarkMinimizeButton {}
+
+Note: Rounding of the bookmark div corners is done by Rico outside of the class.
+
+OpenLayers.Rico.Corner.round( bookmark.div, {corners: "tl bl", bgColor: "transparent", color: "darkblue", blend: false});
+OpenLayers.Rico.Corner.changeOpacity(bookmark.contentDiv, 0.75);
+
+Properties & Methods
+
+See Bookmark.js for full descriptions.

Added: addins/bookmark/trunk/examples/bookmark-cookie.html
===================================================================
--- addins/bookmark/trunk/examples/bookmark-cookie.html	                        (rev 0)
+++ addins/bookmark/trunk/examples/bookmark-cookie.html	2011-07-20 19:11:11 UTC (rev 12175)
@@ -0,0 +1,101 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title>OpenLayers Bookmark Example</title>
+    <link rel="stylesheet" href="http://openlayers.org/api/theme/default/style.css" type="text/css" />
+    <link rel="stylesheet" href="http://www.openlayers.org/dev/examples/style.css" type="text/css" />
+    <link rel="stylesheet" href="../theme/default/bookmark.css" type="text/css" />
+    <style type="text/css">
+        body { position: relative; }
+        #map {
+            width: 512px;
+            height: 512px;
+            border: 1px solid black;
+            position: relative;
+        }
+        #logWindow {
+            width: 512px;
+            height: 50px;
+            border: 1px solid black;
+            position: relative;
+        }
+        #myBookmarks {
+            height: 200px;
+            width: 15em;
+            float: right;
+         }
+         #myBookmarks #olBookmarkElement {
+            cursor : pointer;
+         }
+        input[type="button"] { border: 1px solid black; }
+    </style>
+    <script src="http://openlayers.org/api/OpenLayers.js"></script>
+    <script src="../lib/OpenLayers/Control/Bookmark.js"></script>
+    <script type="text/javascript">
+        var map, bookmarks;
+        var logWindow = document.getElementById('logWindow');
+        function initMap(){
+            map = new OpenLayers.Map('map', { controls: [], theme: null });
+            map.addControl(new OpenLayers.Control.Navigation());
+
+            // no attachment to div
+            bookmarks = new OpenLayers.Control.Bookmark({ 'map':map });
+            bookmarks.add("ATLANTA","-85.085373,33.114328,-83.679123,34.520578");
+            bookmarks.add("BOSTON","-71.401901,41.989908,-70.698776,42.693033");
+
+            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
+                "http://labs.metacarta.com/wms/vmap0",
+                {layers: 'basic'}, {'displayInLayerSwitcher':false} );
+
+            map.addLayer(ol_wms);
+            if (!map.getCenter()) map.zoomToMaxExtent();
+        }
+        function writeLog(data) {
+            if(typeof logWindow == "undefined") {
+               var logWindow = document.getElementById('logWindow');
+            }
+            logWindow.innerHTML=data+"<br />";
+        }
+    </script>
+  </head>
+  <body onload="initMap()">
+    <h1 id="title">Bookmark Control Example</h1>
+    <div id="tags"></div>
+    <p id="shortdesc">
+      Demonstrates the use of Bookmarks storage in a cookie.<br />
+    </p>
+    <div id="map"></div>
+    <div id="docs">
+      <p>This demonstrates use of the Bookmarks storage in a Cookie.</p>
+   </div>
+   <div id="logWindow"></div>
+   <div>
+      <input type="button" value="Show Stack" onclick="javascript:writeLog(bookmarks.toString());">
+      <input type="button" value="Clear Stack" onclick="javascript:writeLog(bookmarks.clear());">
+      <input type="button" value="Cookie Status" onclick="javascript:writeLog(bookmarks.check());">
+      <input type="button" value="Store Stack" onclick="javascript:writeLog(bookmarks.store());">
+      <input type="button" value="Load Cookie" onclick="javascript:writeLog(bookmarks.load());">
+      <input type="button" value="Clear Cookie" onclick="javascript:writeLog(bookmarks.expire());">
+      <br /><br />
+      Use these links to test the navigation. If nothing happens when you click, that<br />
+      bookmark is no longer defined or not found.<br /><br />
+      Click
+      <a noref onclick="javascript:f=bookmarks.find('atlanta');if(f!=false)bookmarks.zoomToLabel(f[0][1]);" style="text-decoration:underline;cursor:pointer;">here</a> to go to Atlanta
+      or
+      <a noref onclick="javascript:f=bookmarks.find('boston');if(f!=false)bookmarks.zoomToLabel(f[0][1]);" style="text-decoration:underline;cursor:pointer;">here</a> to go to Boston.
+      <br /><br />
+      Testing process<br /><br />
+      When you first load, two bookmarks are created.
+      <ol>
+         <li>Click "Show Stack" to view them.</li>
+         <li>Click "Cookie Status" to see if a cookie has been previously defined. <br />
+         If not, you should see false.</li>
+         <li>Click "Store Stack".</li>
+         <li>If yes, you should see the contents as a string.</li>
+         <li>You can close your browser and revisit this page.</li>
+         <li>Upon returning, click "Clear Stack" to remove all bookmarks.</li>
+         <li>Click "Load Cookie" to repopulate the stack. Navigation should function normally.</li>
+         <li>Remove the cookie with "Clear Cookie".</li>
+     </ol>
+   </div>
+  </body>
+</html>

Modified: addins/bookmark/trunk/examples/bookmark-custom.html
===================================================================
--- addins/bookmark/trunk/examples/bookmark-custom.html	2011-07-20 17:26:52 UTC (rev 12174)
+++ addins/bookmark/trunk/examples/bookmark-custom.html	2011-07-20 19:11:11 UTC (rev 12175)
@@ -88,8 +88,8 @@
          <input type="button" value="Add Current View" onclick="if(document.getElementById('name').value != ''){ bookmarks.addView(document.getElementById('name').value) } else { alert('Need a name') }">&nbsp;&nbsp;&nbsp;&nbsp;
          <input type="button" value="Remove" onclick="if(document.getElementById('name').value != ''){ bookmarks.remove(document.getElementById('name').value) } else { alert('Need a name') }">&nbsp;&nbsp;
          <input type="button" value="Remove All" onclick="bookmarks.clear()"><br /><br />
-	 Bookmarks without a DIV?  Click <a noref onclick="javascript:bookmarks3.zoomToLabel(bookmarks3.find('atlanta')[0][1]);" style="text-decoration:underline;cursor:pointer;">here</a> to go to Atlanta or
-	 <a noref onclick="javascript:bookmarks3.zoomToLabel(bookmarks3.find('boston')[0][1]);" style="text-decoration:underline;cursor:pointer;">here</a>
+	 Bookmarks without a DIV?  Click <a noref onclick="javascript:f=bookmarks.find('atlanta');if(f!=false)bookmarks.zoomToLabel(f[0][1]);" style="text-decoration:underline;cursor:pointer;">here</a> to go to Atlanta or
+	 <a noref onclick="javascript:f=bookmarks.find('boston');if(f!=false)bookmarks.zoomToLabel(f[0][1]);" style="text-decoration:underline;cursor:pointer;">here</a>
          to go to Boston.<br /><br />
          Added the ability to pass a user defined function to be execute when the user clicks the bookmark.  Click the Boston
          or Atlanta links above.

Modified: addins/bookmark/trunk/lib/OpenLayers/Control/Bookmark.js
===================================================================
--- addins/bookmark/trunk/lib/OpenLayers/Control/Bookmark.js	2011-07-20 17:26:52 UTC (rev 12174)
+++ addins/bookmark/trunk/lib/OpenLayers/Control/Bookmark.js	2011-07-20 19:11:11 UTC (rev 12175)
@@ -49,6 +49,44 @@
      */
     allowRemove: true,
 
+    /**
+     * APIProperty: allowDuplicates
+     * {Boolean}  Allow the bookmarks to be duplicated. If not, overwrite
+     *            existing.
+     *      Default to false.
+     */
+    allowDuplicates: false,
+
+    /**
+     * Property: cookieName
+     * {String}
+     */
+    cookieName: "olBookMark",
+
+    /**
+     * Property: cookieExpires
+     * {Integer} Default days to expire the cookie.
+     */
+    cookieExpires: 30,
+
+    /**
+     * Property: cookiePath
+     * {String}
+     */
+    cookiePath: "/",
+
+    /**
+     * Property: cookieSeperator
+     * {String} Seperates the label and bounds.
+     */
+    cookieSeperator: ":",
+
+    /**
+     * Property: cookieDelimiter
+     * {String} Seperates bookmarks.
+     */
+    cookieDelimiter: "|",
+ 
     // DOM Elements
 
     /**
@@ -128,12 +166,18 @@
      *     "-180,-180,180,180"
      *
      * Returns:
-     * {Boolean} False if limit reached. True if added successfully.
+     * {Boolean} false if limit reached. true if added successfully.
      */
     add: function(label, bounds, func, param) {
       if(this.stack.length == this.limit && this.limit != 0) {
+         OpenLayers.Console.log("limit reached");
          return false;  // limit reached
       }
+      if(!this.allowDuplicates) {
+        if(this.find(label)) {
+            this.remove(label, true);
+        }
+      }
       func = (typeof func == "undefined") ? function() {} : func;
       param = (typeof param == "undefined" || param.length == 0) ? "" : param;
       label = (label == "undefined" || label.length == 0) ? "NONAME" : label;
@@ -142,6 +186,7 @@
                         "func": func,
                         "param": param,
                         "id": this.stack.length });
+      OpenLayers.Console.log(label + " added with bounds " + bounds);
       this.stackState = true;
       this.redraw();
       return true;
@@ -154,6 +199,7 @@
     clear: function() {
       this.initStack();
       this.redraw();
+      return true;
     },
 
     /**
@@ -167,8 +213,9 @@
      * {Boolean} False if not found or not allowed to remove.
      */
     /* FIXME  - not sure i'm stopping observation correctly*/
-    remove: function(label) {
-      if(!this.allowRemove) {
+    remove: function(label, force) {
+      var force = force||false
+      if(!this.allowRemove && !force) {
          return false;
       }
       label = label.toUpperCase();
@@ -211,7 +258,6 @@
       for(var i=0; i<this.stack.length; i++) {
          if(regEx.test(this.stack[i].label)) {
             rt.push([this.stack[i].id,this.stack[i].label]);
-            //return this.stack[i].label; // return first found
          }
       }
       return (rt.length == 0 ? false : rt);
@@ -239,7 +285,9 @@
          this.stack[id].func(this.stack[id].param);
          found=true;
        } else {
-         // index is misaligned, search the stack for the correct id.
+         // index is misaligned, search the stack for the correct id,
+         // then reindex.
+         OpenLayers.Console.log("stack misaligned. searching for id.");
          for( var i=0; i<this.stack.length; i++ ) {
             if( this.stack[i].id == id ) {
                if( typeof this.stack[i].bounds == "object" ) {
@@ -253,6 +301,7 @@
                break;  // break out of for when found
             }
          }
+         this.reindex();
        }
        return found;
     },
@@ -283,20 +332,13 @@
      * {Boolean} False if not found
      */
     zoomToLabel: function(label) {
-      if( label != false ) {
-         for(var i=0; i<this.stack.length; i++) {
-            if( this.stack[i].label.toUpperCase() == label.toUpperCase() ) {
-               if( typeof this.stack[i].bounds == "object" ) {
-                  this.map.zoomToExtent( this.stack[i].bounds );
-               } else {
-                  this.map.zoomToExtent( new OpenLayers.Bounds.fromString(
-                                          this.stack[i].bounds) );
-               }
-               this.stack[i].func(this.stack[i].param);
-               return true;
-            }
-         }
+      f = this.find(label);
+      if(f != false) {
+         OpenLayers.Console.log("found label " + f[0][1]);
+         this.zoomToId(f[0][0]);
+         return true;
       }
+      OpenLayers.Console.log(label + " not found");
       return false;
     },
 
@@ -346,6 +388,7 @@
      * after sortStack, add or remove.
      */
     reindex: function() {
+       OpenLayers.Console.log("reindexing");
        for( var i=0; i<this.stack.length; i++ ) {
           this.stack[i].id = i;
        }
@@ -353,6 +396,95 @@
     },
 
     /**
+     * APIMethod: store
+     * Store the contents of the stack to a cookie referenced by
+     * cookieName.
+     */
+    store: function( value, expires) {
+      var expires = expires||this.cookieExpires
+      var value   = value||this.toString();
+      if (expires) {
+         var date = new Date();
+         date.setTime(date.getTime()+(expires*24*60*60*1000));
+         expires = "; expires="+date.toGMTString();
+      }
+      document.cookie = this.cookieName +"="+ value +
+                        expires + "; path=" + this.cookiePath;
+      OpenLayers.Console.log("cookie stored");
+      return true;
+    },
+
+    /**
+     * Method: toString
+     * Convert stack array to string
+     *
+     * Returns:
+     * String. label + cookieSeperator + bounds + cookieDelimiter
+     */
+    toString: function() {
+      var toString = "";
+      for(var i=0; i<this.stack.length; i++) {
+         toString += this.stack[i].label + this.cookieSeperator +
+                     ( typeof this.stack[i].bounds == "object"
+                        ? this.stack[i].bounds.toBBOX()
+                        : this.stack[i].bounds ) + this.cookieDelimiter;
+      }
+      toString = toString.substr(0, toString.length-1);
+      OpenLayers.Console.log(toString);
+      return toString;
+    },
+
+    /**
+     * APIMethod: load
+     * Load the contents of the cookie referenced by cookieName
+     * to the stack.
+     *
+     * Returns:
+     * false if not found.
+     */
+    load: function() {
+      var allCookies=document.cookie.split(";");
+      f = this.check();
+      if(f != false) {
+         var items = f.split(this.cookieDelimiter);
+         for(var ii in items) {
+            var bookmark = items[ii].split(this.cookieSeperator);
+            this.add(bookmark[0],bookmark[1]);
+         }
+         return true;
+      }
+      OpenLayers.Console.log("cookie not found");
+      return false;
+    },
+
+    /**
+     * APIMethod: check
+     * Check for the existance of cookie referenced by cookieName
+     *
+     * Returns:
+     * {String} contents of cookie if found.
+     * false if not found.
+     */
+    check: function() {
+      var allCookies=document.cookie.split(";");
+      for(var i in allCookies) {
+         keyval = allCookies[i].split("=");
+         if(keyval[0].replace(/^\s+|\s+$/g,"") == this.cookieName) {
+            return keyval[1];
+         }
+      }
+      OpenLayers.Console.log("cookie not found");
+      return false;
+   },
+    /**
+     * APIMethod: expire
+     * Expire cookie referenced by cookieName.
+     */
+    expire: function() {
+      return this.store("", -1);
+    },
+
+    /**
      * APIMethod: maximizeControl
      * Set up the labels and divs for the control
      *
@@ -656,4 +788,4 @@
     CLASS_NAME: "OpenLayers.Control.Bookmark"
 });
 
-OpenLayers.Control.Bookmark.VERSION_NUMBER = '2.1';
\ No newline at end of file
+OpenLayers.Control.Bookmark.VERSION_NUMBER = '2.2';
\ No newline at end of file

Modified: addins/bookmark/trunk/tests/Control/Bookmark.html
===================================================================
--- addins/bookmark/trunk/tests/Control/Bookmark.html	2011-07-20 17:26:52 UTC (rev 12174)
+++ addins/bookmark/trunk/tests/Control/Bookmark.html	2011-07-20 19:11:11 UTC (rev 12175)
@@ -83,6 +83,7 @@
         t.ok(found.length == 1, "correctly found single bookmark");
 
         found = "";
+        control.allowDuplicates = true;
         control.add( "BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033) );
         control.add( "BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033) );
         found = control.find("BOSTON");
@@ -105,7 +106,7 @@
 
         var mapExtent = map.getExtent().toBBOX();
         control.add( "BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033) );
-        control.zoomToLabel(control.find("BOSTON")[0]);
+        control.zoomToLabel(control.find("BOSTON")[0][1]);
         var currentExtent = map.getExtent().toBBOX();
 
         // note: the map extents may not match due to map zoom levels/resolutions. all
@@ -195,6 +196,52 @@
         control.clear();
         t.ok(control.stack.length == 0, "correctly clear bookmark");
     }
+
+    function test_Control_Bookmark_store_expire (t) {
+        t.plan( 3 );
+
+        var map = new OpenLayers.Map('map');
+        var control = new OpenLayers.Control.Bookmark();
+        map.addControl(control);
+
+        control.add( "BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033) );
+        t.ok(control.stack.length == 1, "correctly added bookmark using object");
+        control.store();
+        t.ok(control.check() != false, "correctly added bookmark cookie");
+        control.expire();
+        t.ok(control.check() == false, "correctly expired bookmark cookie");
+    }
+
+    function test_Control_Bookmark_load (t) {
+        t.plan( 5 );
+
+        var map = new OpenLayers.Map('map');
+        var control = new OpenLayers.Control.Bookmark();
+        map.addControl(control);
+
+        control.add( "BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033) );
+        t.ok(control.stack.length == 1, "correctly added bookmark using object");
+        control.store();
+        t.ok(control.check() != false, "correctly added bookmark cookie");
+        control.clear();
+        t.ok(control.stack.length == 0, "correctly clear bookmark");
+        control.load();
+        t.ok(control.check() != false, "correctly loaded bookmark cookie");
+        control.expire();
+        t.ok(control.check() == false, "correctly expired bookmark cookie");
+    }
+
+    function test_Control_Bookmark_toString (t) {
+        t.plan( 1 );
+
+        var map = new OpenLayers.Map('map');
+        var control = new OpenLayers.Control.Bookmark();
+        map.addControl(control);
+
+        control.add( "BOSTON", new OpenLayers.Bounds(-71.401901,41.989908,-70.698776,42.693033) );
+        t.ok(typeof control.toString() == "string", "correctly returned bookmark as string");
+    }
+
   </script>
 </head>
 <body>



More information about the Commits mailing list