[OpenLayers-Commits] r11173 - in sandbox/cmoullet/openlayers: . build examples lib/OpenLayers/Control tests tests/Control tests/Format

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon Feb 21 06:55:07 EST 2011


Author: cmoullet
Date: 2011-02-21 03:55:06 -0800 (Mon, 21 Feb 2011)
New Revision: 11173

Added:
   sandbox/cmoullet/openlayers/build/tests.cfg
   sandbox/cmoullet/openlayers/examples/anchor-permalink.html
   sandbox/cmoullet/openlayers/examples/anchor-permalink.js
   sandbox/cmoullet/openlayers/tests/Control/ArgParser.html
Modified:
   sandbox/cmoullet/openlayers/
   sandbox/cmoullet/openlayers/lib/OpenLayers/Control/ArgParser.js
   sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Permalink.js
   sandbox/cmoullet/openlayers/tests/BaseTypes.html
   sandbox/cmoullet/openlayers/tests/Control/Permalink.html
   sandbox/cmoullet/openlayers/tests/Format/Text.html
   sandbox/cmoullet/openlayers/tests/OLLoader.js
   sandbox/cmoullet/openlayers/tests/list-tests.html
Log:
Merge with trunk



Property changes on: sandbox/cmoullet/openlayers
___________________________________________________________________
Modified: svn:mergeinfo
   - /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11165
   + /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11172

Copied: sandbox/cmoullet/openlayers/build/tests.cfg (from rev 11172, trunk/openlayers/build/tests.cfg)
===================================================================
--- sandbox/cmoullet/openlayers/build/tests.cfg	                        (rev 0)
+++ sandbox/cmoullet/openlayers/build/tests.cfg	2011-02-21 11:55:06 UTC (rev 11173)
@@ -0,0 +1,10 @@
+# This build config is supposed to be used for the units tests with "mode=build"
+
+[first]
+
+[last]
+
+[include]
+
+[exclude]
+OpenLayers.js

Copied: sandbox/cmoullet/openlayers/examples/anchor-permalink.html (from rev 11172, trunk/openlayers/examples/anchor-permalink.html)
===================================================================
--- sandbox/cmoullet/openlayers/examples/anchor-permalink.html	                        (rev 0)
+++ sandbox/cmoullet/openlayers/examples/anchor-permalink.html	2011-02-21 11:55:06 UTC (rev 11173)
@@ -0,0 +1,27 @@
+<html>
+    <head>
+        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /> 
+        <meta name="apple-mobile-web-app-capable" content="yes" />
+        <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
+        <link rel="stylesheet" href="style.css" type="text/css" />
+        <title>AnchorPermalink Example</title>
+        <script src="../lib/OpenLayers.js"></script>
+        <script src="anchor-permalink.js"></script>
+    </head>
+    <body onload="init()">
+        <h1 id="title">AnchorPermalink Example</h1>
+        <div id="tags">
+            anchor, permalink
+        </div>
+        <p id="shortdesc">
+            Place a permalink in the anchor of the url. 
+        </p>
+        <div id="map" class="smallmap"></div>
+        <div id="docs">
+            <p>
+                See the <a href="anchor-permalink.js" target="_blank">anchor-permalink.js
+                source</a> to see how this is done.
+            </p> 
+        </div>
+    </body>
+</html>

Copied: sandbox/cmoullet/openlayers/examples/anchor-permalink.js (from rev 11172, trunk/openlayers/examples/anchor-permalink.js)
===================================================================
--- sandbox/cmoullet/openlayers/examples/anchor-permalink.js	                        (rev 0)
+++ sandbox/cmoullet/openlayers/examples/anchor-permalink.js	2011-02-21 11:55:06 UTC (rev 11173)
@@ -0,0 +1,13 @@
+function init() {
+    var map = new OpenLayers.Map({
+        div: "map",
+        projection: new OpenLayers.Projection("EPSG:900913"),
+        displayProjection: new OpenLayers.Projection("EPSG:4326"),
+        layers: [
+            new OpenLayers.Layer.OSM()
+        ]
+    });
+    if (!map.getCenter()) map.zoomToMaxExtent();
+
+    map.addControl(new OpenLayers.Control.Permalink({anchor: true}));
+}

Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Control/ArgParser.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Control/ArgParser.js	2011-02-21 11:54:15 UTC (rev 11172)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Control/ArgParser.js	2011-02-21 11:55:06 UTC (rev 11173)
@@ -64,6 +64,22 @@
         OpenLayers.Control.prototype.initialize.apply(this, arguments);
     },
 
+    getParameters: function(url) {
+        url = url || window.location.href;
+        var parameters = OpenLayers.Util.getParameters(url);
+
+        // If we have an chchor in the url use it to split the url
+        var index = url.indexOf('#');
+        if (index > 0) {
+            // create an url to parce on the getParameters
+            url = '?' + url.substring(index + 1, url.length);
+
+            OpenLayers.Util.extend(parameters,
+                    OpenLayers.Util.getParameters(url));
+        }
+        return parameters;
+    },
+    
     /**
      * Method: setMap
      * Set the map property for the control. 
@@ -92,7 +108,7 @@
         }
         if (i == this.map.controls.length) {
 
-            var args = OpenLayers.Util.getParameters();
+            var args = this.getParameters();
             // Be careful to set layer first, to not trigger unnecessary layer loads
             if (args.layers) {
                 this.layers = args.layers;

Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Permalink.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Permalink.js	2011-02-21 11:54:15 UTC (rev 11172)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Permalink.js	2011-02-21 11:55:06 UTC (rev 11173)
@@ -36,6 +36,16 @@
     element: null,
     
     /** 
+     * APIProperty: anchor
+     * {Boolean} This option changes 3 things:
+     *     the character '#' is used in place of the character '?',
+     *     the window.href is updated if no element is provided.
+     *     When this option is set to true it's not recommend to provide
+     *     a base without provide an element.
+     */
+    anchor: false,
+
+    /** 
      * APIProperty: base
      * {String}
      */
@@ -59,14 +69,27 @@
      * Parameters: 
      * element - {DOMElement} 
      * base - {String} 
-     * options - {Object} options to the control. 
+     * options - {Object} options to the control.
+     *
+     * Or for anchor:
+     * options - {Object} options to the control.
      */
     initialize: function(element, base, options) {
-        OpenLayers.Control.prototype.initialize.apply(this, [options]);
-        this.element = OpenLayers.Util.getElement(element);        
-        this.base = base || document.location.href;
+        if (element !== null && typeof element == 'object' && !OpenLayers.Util.isElement(element)) {
+            options = element;
+            this.base = document.location.href;
+            OpenLayers.Control.prototype.initialize.apply(this, [options]);
+            if (this.element != null) {
+                this.element = OpenLayers.Util.getElement(this.element);
+            }
+        }
+        else {
+            OpenLayers.Control.prototype.initialize.apply(this, [options]);
+            this.element = OpenLayers.Util.getElement(element);
+            this.base = base || document.location.href;
+        }
     },
-
+    
     /**
      * APIMethod: destroy
      */
@@ -122,7 +145,7 @@
     draw: function() {
         OpenLayers.Control.prototype.draw.apply(this, arguments);
           
-        if (!this.element) {
+        if (!this.element && !this.anchor) {
             this.element = document.createElement("a");
             this.element.innerHTML = OpenLayers.i18n("permalink");
             this.element.href="";
@@ -146,13 +169,19 @@
      * Method: updateLink 
      */
     updateLink: function() {
+        var separator = this.anchor ? '#' : '?';
         var href = this.base;
-        if (href.indexOf('?') != -1) {
-            href = href.substring( 0, href.indexOf('?') );
+        if (href.indexOf(separator) != -1) {
+            href = href.substring( 0, href.indexOf(separator) );
         }
 
-        href += '?' + OpenLayers.Util.getParameterString(this.createParams());
-        this.element.href = href;
+        href += separator + OpenLayers.Util.getParameterString(this.createParams());
+        if (this.anchor && !this.element) {
+            window.location.href = href;
+        }
+        else {
+            this.element.href = href;
+        }
     }, 
     
     /**

Modified: sandbox/cmoullet/openlayers/tests/BaseTypes.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/BaseTypes.html	2011-02-21 11:54:15 UTC (rev 11172)
+++ sandbox/cmoullet/openlayers/tests/BaseTypes.html	2011-02-21 11:55:06 UTC (rev 11173)
@@ -298,6 +298,13 @@
         //run again to make sure the arguments are handled correctly
         newFoo(g_Arg3, g_Arg4);
     }
+    
+    function test_Function_Void(t) {
+        
+        t.plan(1);
+        t.eq(OpenLayers.Function.Void(), undefined, "returns undefined");
+        
+    }
 
     function test_Function_bindAsEventListener(t) {
         t.plan(4);

Copied: sandbox/cmoullet/openlayers/tests/Control/ArgParser.html (from rev 11172, trunk/openlayers/tests/Control/ArgParser.html)
===================================================================
--- sandbox/cmoullet/openlayers/tests/Control/ArgParser.html	                        (rev 0)
+++ sandbox/cmoullet/openlayers/tests/Control/ArgParser.html	2011-02-21 11:55:06 UTC (rev 11173)
@@ -0,0 +1,26 @@
+<html>
+<head>
+  <script src="../OLLoader.js"></script>
+  <script type="text/javascript">
+      function test_getParameters(t) {
+          t.plan(4);
+
+          var c = new OpenLayers.Control.ArgParser(), p;
+
+          p = c.getParameters('http://example.com?fook=foov&bark=barv');
+          t.eq(p, {fook: 'foov', bark: 'barv'}, 'a) params are correct');
+
+          p = c.getParameters('http://example.com#fook=foov&bark=barv');
+          t.eq(p, {fook: 'foov', bark: 'barv'}, 'b) params are correct');
+
+          p = c.getParameters('http://example.com?a=b&b=c#fook=foov&bark=barv');
+          t.eq(p, {a: 'b', b: 'c', fook: 'foov', bark: 'barv'},
+               'c) params are correct');
+
+          p = c.getParameters('http://example.com?a=b&b=c&fook=a&bark=b#fook=foov&bark=barv');
+          t.eq(p, {a: 'b', b: 'c', fook: 'foov', bark: 'barv'},
+               'd) params are correct');
+        }
+    </script>
+</head>
+</html>

Modified: sandbox/cmoullet/openlayers/tests/Control/Permalink.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Control/Permalink.html	2011-02-21 11:54:15 UTC (rev 11172)
+++ sandbox/cmoullet/openlayers/tests/Control/Permalink.html	2011-02-21 11:55:06 UTC (rev 11173)
@@ -4,11 +4,67 @@
   <script type="text/javascript">
     var map; 
     function test_Control_Permalink_constructor (t) {
-        t.plan( 2 );
+        t.plan(42);
     
         control = new OpenLayers.Control.Permalink();
-        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
-        t.eq( control.displayClass,  "olControlPermalink", "displayClass is correct" );
+        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
+        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
+        t.eq(control.base, document.location.href, "base is correct");
+        t.ok(!control.anchor, "anchor is correct");
+
+        control = new OpenLayers.Control.Permalink('permalink', 'test.html');
+        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
+        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
+        t.eq(control.base, 'test.html', "base is correct");
+        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
+        t.ok(!control.anchor, "anchor is correct");
+
+        control = new OpenLayers.Control.Permalink('permalink');
+        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
+        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
+        t.eq(control.base, document.location.href, "base is correct");
+        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
+        t.ok(!control.anchor, "anchor is correct");
+
+        control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink'));
+        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
+        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
+        t.eq(control.base, document.location.href, "base is correct");
+        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
+        t.ok(!control.anchor, "anchor is correct");
+
+        control = new OpenLayers.Control.Permalink({anchor: true});
+        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
+        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
+        t.eq(control.base, document.location.href, "base is correct");
+        t.ok(control.element == null, "element is null");
+        t.ok(control.anchor, "anchor is correct");
+
+        control = new OpenLayers.Control.Permalink({anchor: false});
+        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
+        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
+        t.eq(control.base, document.location.href, "base is correct");
+        t.ok(!control.anchor, "anchor is correct");
+
+        control = new OpenLayers.Control.Permalink({});
+        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
+        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
+        t.eq(control.base, document.location.href, "base is correct");
+        t.ok(!control.anchor, "anchor is correct");
+
+        control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html'});
+        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
+        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
+        t.eq(control.base, 'test.html', "base is correct");
+        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
+        t.ok(!control.anchor, "anchor is correct");
+
+        control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html', anchor: true});
+        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
+        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
+        t.eq(control.base, 'test.html', "base is correct");
+        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
+        t.ok(control.anchor, "anchor is correct");
     }
     function test_Control_Permalink_uncentered (t) {
         t.plan( 1 );
@@ -226,7 +282,45 @@
         OpenLayers.Util.getParameters = old_getParameters;
         OpenLayers.Projection.transform = old_transform;
     }
+    function test_Control_Permalink_Anchor (t) {
+        t.plan(3);
     
+        control = new OpenLayers.Control.Permalink({anchor: true});
+        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
+        map = new OpenLayers.Map('map');
+        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
+        map.addLayer(layer);
+        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, {'isBaseLayer': false});
+        map.addLayer(layer);
+        layer.setVisibility(true);
+        if (!map.getCenter())  map.zoomToMaxExtent();
+        map.addControl(control);
+        map.pan(5, 0, {animate:false});
+        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getParameterString(control.createParams()), "zoom=2&lat=0&lon=1.75781&layers=BT"), 'pan sets permalink');
+        
+        map.layers[1].setVisibility(false);
+        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getParameterString(control.createParams()), "zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink');
+    }
+    
+    function test_Control_Permalink_AnchorBaseElement (t) {
+        t.plan(3);
+    
+        control = new OpenLayers.Control.Permalink('permalink', document.location.href, {anchor: true});
+        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
+        map = new OpenLayers.Map('map');
+        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
+        map.addLayer(layer);
+        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, {'isBaseLayer': false});
+        map.addLayer(layer);
+        layer.setVisibility(true);
+        if (!map.getCenter())  map.zoomToMaxExtent();
+        map.addControl(control);
+        map.pan(5, 0, {animate:false});
+        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"#zoom=2&lat=0&lon=1.75781&layers=BT"), 'pan sets permalink');
+        
+        map.layers[1].setVisibility(false);
+        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"#zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink');
+    }
   </script>
 </head>
 <body>

Modified: sandbox/cmoullet/openlayers/tests/Format/Text.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Format/Text.html	2011-02-21 11:54:15 UTC (rev 11172)
+++ sandbox/cmoullet/openlayers/tests/Format/Text.html	2011-02-21 11:55:06 UTC (rev 11173)
@@ -8,7 +8,7 @@
         var features = format.read(OpenLayers.Util.getElement("content").value);
         t.eq(features[0].style.externalGraphic, format.defaultStyle.externalGraphic, "style is set to defaults if no style props set in text file");
         var features = format.read(OpenLayers.Util.getElement("contentMarker").value);
-        t.eq(features[0].style.externalGraphic, "../../img/marker.png", "marker set correctly by default.");
+        t.eq(features[0].style.externalGraphic, OpenLayers.Util.getImagesLocation() + "marker.png", "marker set correctly by default.");
         
         var features = format.read(OpenLayers.Util.getElement("content2").value);
         t.eq(features.length, 2, "two features read");

Modified: sandbox/cmoullet/openlayers/tests/OLLoader.js
===================================================================
--- sandbox/cmoullet/openlayers/tests/OLLoader.js	2011-02-21 11:54:15 UTC (rev 11172)
+++ sandbox/cmoullet/openlayers/tests/OLLoader.js	2011-02-21 11:55:06 UTC (rev 11173)
@@ -1,11 +1,25 @@
 // Adding a mode parameter with "build" as value in the run-tests.html will 
 // make usage of the build version of the library.
-var regexS = "[\\?&]mode=([^&#]*)";
-var regex = new RegExp( regexS );
+// get the OLLoader.js script location
+
+var r = new RegExp("(^|(.*?\\/))(" + "OLLoader.js" + ")(\\?|$)"),
+    s = document.getElementsByTagName('script'),
+    src, m, l = "";
+for(var i=0, len=s.length; i<len; i++) {
+    src = s[i].getAttribute('src');
+    if(src) {
+        var m = src.match(r);
+        if(m) {
+            l = m[1];
+            break;
+        }
+    }
+}
+
+var regex = new RegExp( "[\\?&]mode=([^&#]*)" );
 var href = window.parent.location.href;
-var url = href.substring(0, href.lastIndexOf('/') + 1);
 var results = regex.exec( href );
-url += (results && results[1] == 'build') ? 
+l += (results && results[1] == 'build') ? 
     "../build/OpenLayers.js" : "../lib/OpenLayers.js"; 
-scriptTag = "<script src='" + url + "'></script>"; 
+scriptTag = "<script src='" + l + "'></script>"; 
 document.write(scriptTag);

Modified: sandbox/cmoullet/openlayers/tests/list-tests.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/list-tests.html	2011-02-21 11:54:15 UTC (rev 11172)
+++ sandbox/cmoullet/openlayers/tests/list-tests.html	2011-02-21 11:55:06 UTC (rev 11173)
@@ -10,6 +10,7 @@
     <li>Console.html</li>
     <li>Control.html</li>
     <li>Control/Attribution.html</li>
+    <li>Control/ArgParser.html</li>
     <li>Control/Button.html</li>
     <li>Control/DragFeature.html</li>
     <li>Control/DragPan.html</li>



More information about the Commits mailing list