[OpenLayers-Commits] r5671 - in sandbox/tschaub/history: examples lib/OpenLayers/Control
commits at openlayers.org
commits at openlayers.org
Mon Jan 7 12:47:08 EST 2008
Author: tschaub
Date: 2008-01-07 12:47:08 -0500 (Mon, 07 Jan 2008)
New Revision: 5671
Modified:
sandbox/tschaub/history/examples/navigation-history.html
sandbox/tschaub/history/lib/OpenLayers/Control/NavigationHistory.js
Log:
fixing late binding issue and demonstrating button controls
Modified: sandbox/tschaub/history/examples/navigation-history.html
===================================================================
--- sandbox/tschaub/history/examples/navigation-history.html 2008-01-07 08:25:15 UTC (rev 5670)
+++ sandbox/tschaub/history/examples/navigation-history.html 2008-01-07 17:47:08 UTC (rev 5671)
@@ -14,9 +14,6 @@
function init(){
map = new OpenLayers.Map('map');
- nav = new OpenLayers.Control.NavigationHistory();
- map.addControl(nav);
-
var layer = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
@@ -25,6 +22,24 @@
map.addLayer(layer);
map.zoomToMaxExtent();
+
+ nav = new OpenLayers.Control.NavigationHistory();
+ map.addControl(nav);
+
+ prev = new OpenLayers.Control({
+ type: OpenLayers.Control.BUTTON,
+ trigger: function() {nav.previous();},
+ active: true
+ });
+ map.addControl(prev);
+
+ next = new OpenLayers.Control({
+ type: OpenLayers.Control.BUTTON,
+ trigger: function() {nav.next();},
+ active: true
+ });
+ map.addControl(next);
+
}
</script>
</head>
@@ -39,9 +54,8 @@
</p>
<div id="map"></div>
- zoom to
- <a href="javascript: void nav.previous();">previous</a> |
- <a href="javascript: void nav.next();">next</a><br />
+ zoom to <button onclick="prev.trigger();">previous</button>
+ <button onclick="next.trigger();">next</button><br />
<div id="docs"></div>
</body>
Modified: sandbox/tschaub/history/lib/OpenLayers/Control/NavigationHistory.js
===================================================================
--- sandbox/tschaub/history/lib/OpenLayers/Control/NavigationHistory.js 2008-01-07 08:25:15 UTC (rev 5670)
+++ sandbox/tschaub/history/lib/OpenLayers/Control/NavigationHistory.js 2008-01-07 17:47:08 UTC (rev 5671)
@@ -16,11 +16,26 @@
OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
/**
+ * APIProperty: type
+ * OpenLayers.Control.TYPE_BUTTON
+ */
+ type: OpenLayers.Control.TYPE_BUTTON,
+
+ /**
* APIProperty: limit
* {Integer} Optional limit on the number of history items to retain. If
* null, there is no limit. Default is 50.
*/
limit: 50,
+
+ /**
+ * APIProperty: backwards
+ * {Boolean} Navigate backwards through history by default. This is
+ * relevant when the <trigger> method is called. If true, the
+ * <trigger> method will call <previous>. If false, the <trigger>
+ * method will call <next>. Default is true.
+ */
+ backwards: true,
/**
* Property: activateOnDraw
@@ -121,6 +136,26 @@
},
/**
+ * APIMethod: trigger
+ * Trigger the default action on the control. If <backwards> is true, this
+ * will call <previous>. If <backwards> is false, this will call
+ * <next>.
+ *
+ * Parameters:
+ * options - {Object} Optional object to modify trigger behavior. An
+ * opposite property on the options object will cause previous to be
+ * called instead of next.
+ */
+ trigger: function(options) {
+ var backwards = (options.opposite) ? !this.backwards : this.backwards;
+ if(backwards) {
+ this.previous();
+ } else {
+ this.next();
+ }
+ },
+
+ /**
* APIMethod: previous
* Restore the previous state. If no items are in the previous history
* stack, this has no effect.
@@ -193,11 +228,9 @@
setListeners: function() {
this.listeners = {};
for(var type in this.on) {
- this.listeners[type] = function() {
+ this.listeners[type] = OpenLayers.Function.bind(function() {
if(!this.restoring) {
- var state = OpenLayers.Function.bind(
- this.on[type], this
- )(arguments);
+ var state = this.on[type].apply(this, arguments);
this.previousStack.unshift(state);
if(this.previousStack.length > (this.limit + 1)) {
this.previousStack.pop();
@@ -207,7 +240,7 @@
}
}
return true;
- };
+ }, this);
}
},
More information about the Commits
mailing list