From 5539f6e9588bf980031da550ce36af85b5ff725d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 7 Feb 2012 17:18:45 +0100 Subject: [PATCH 01/16] [Control.Panel] place code creating the control markup in a separate function --- lib/OpenLayers/Control/Panel.js | 54 +++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/lib/OpenLayers/Control/Panel.js b/lib/OpenLayers/Control/Panel.js index b04f6c3863..c1760f03c0 100644 --- a/lib/OpenLayers/Control/Panel.js +++ b/lib/OpenLayers/Control/Panel.js @@ -245,26 +245,56 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { controls = [controls]; } this.controls = this.controls.concat(controls); - - // Give each control a panel_div which will be used later. - // Access to this div is via the panel_div attribute of the - // control added to the panel. - // Also, stop mousedowns and clicks, but don't stop mouseup, - // since they need to pass through. + for (var i=0, len=controls.length; i} The control to create the HTML + * markup for. + * + * Returns: + * {DOMElement} The markup. + */ + createControlMarkup: function(control) { + return document.createElement("div"); + }, /** * Method: addControlsToMap From e551fc672ce15f06a99c91b140148b29671d36e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 7 Feb 2012 17:19:29 +0100 Subject: [PATCH 02/16] [Event.buttonclick] make buttonclick work on RETURN/SPACE keydown --- lib/OpenLayers/Events.js | 9 ++++++++- lib/OpenLayers/Events/buttonclick.js | 14 +++++++++++++- tests/Events/buttonclick.html | 21 ++++++++++++++++++--- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index 907ced8109..ea46bf3cba 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -20,6 +20,12 @@ OpenLayers.Event = { * element._eventCacheID */ observers: false, + + /** + * Constant: KEY_SPACE + * {int} + */ + KEY_SPACE: 32, /** * Constant: KEY_BACKSPACE @@ -388,7 +394,8 @@ OpenLayers.Events = OpenLayers.Class({ "mousedown", "mouseup", "mousemove", "click", "dblclick", "rightclick", "dblrightclick", "resize", "focus", "blur", - "touchstart", "touchmove", "touchend" + "touchstart", "touchmove", "touchend", + "keydown" ], /** diff --git a/lib/OpenLayers/Events/buttonclick.js b/lib/OpenLayers/Events/buttonclick.js index 351248bf0c..f4de405997 100644 --- a/lib/OpenLayers/Events/buttonclick.js +++ b/lib/OpenLayers/Events/buttonclick.js @@ -39,7 +39,7 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({ */ events: [ 'mousedown', 'mouseup', 'click', 'dblclick', - 'touchstart', 'touchmove', 'touchend' + 'touchstart', 'touchmove', 'touchend', 'keydown' ], /** @@ -112,6 +112,18 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({ element = element.parentNode; } if (OpenLayers.Element.hasClass(element, "olButton")) { + if (evt.type === "keydown") { + switch (evt.keyCode) { + case OpenLayers.Event.KEY_RETURN: + case OpenLayers.Event.KEY_SPACE: + this.target.triggerEvent("buttonclick", { + buttonElement: element + }); + OpenLayers.Event.stop(evt); + propagate = false; + break; + } + } if (this.startEvt) { if (this.completeRegEx.test(evt.type)) { var pos = OpenLayers.Util.pagePosition(element); diff --git a/tests/Events/buttonclick.html b/tests/Events/buttonclick.html index 9aff9b89b8..7d12710cf6 100644 --- a/tests/Events/buttonclick.html +++ b/tests/Events/buttonclick.html @@ -29,7 +29,7 @@ } function test_ButtonClick_buttonClick(t) { - t.plan(23); + t.plan(27); events = new OpenLayers.Events({}, element); events.on({ "buttonclick": logEvent, @@ -38,7 +38,8 @@ "click": logEvent, "dblclick": logEvent, "touchstart": logEvent, - "touchend": logEvent + "touchend": logEvent, + "keydown": logEvent }); buttonClick = events.extensions["buttonclick"]; @@ -111,12 +112,26 @@ t.eq(log[1].type, "buttonclick", "buttonclick for 2nd click IE"); // rightclick - log = [] + log = []; trigger({type: "mousedown", button: 2}); trigger({type: "mouseup", button: 2}); t.eq(log.length, 2, "two events fired for rightclick"); t.eq(log[0].type, "mousedown", "mousedown from rightclick goes through"); t.eq(log[1].type, "mouseup", "mouseup from rightclick goes through"); + + // keydown RETURN + log = []; + trigger({type: "keydown", keyCode: OpenLayers.Event.KEY_RETURN}); + trigger({type: "click"}); + t.eq(log.length, 1, "one event fired for RETURN keydown"); + t.eq(log[0].type, "buttonclick", "buttonclick for RETURN keydown"); + + // keydown SPACE + log = []; + trigger({type: "keydown", keyCode: OpenLayers.Event.KEY_SPACE}); + trigger({type: "click"}); + t.eq(log.length, 1, "one event fired for SPACE keydown"); + t.eq(log[0].type, "buttonclick", "buttonclick for SPACE keydown"); } From aedc96f030a67c0a221fb84730315bb056167531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 7 Feb 2012 17:19:49 +0100 Subject: [PATCH 03/16] [examples] add an accessible-panel example --- examples/accessible-panel.html | 124 +++++++++++++++++++++++++++++++++ examples/accessible-panel.js | 64 +++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 examples/accessible-panel.html create mode 100644 examples/accessible-panel.js diff --git a/examples/accessible-panel.html b/examples/accessible-panel.html new file mode 100644 index 0000000000..39754ceccc --- /dev/null +++ b/examples/accessible-panel.html @@ -0,0 +1,124 @@ + + + + + + + Custom and accessible panel + + + + + + + +

Custom and accessible panel

+
+ panels, CSS, style, accessibility, button +
+

+ Create a custom and accessible panel, styled entirely with + CSS. +

+
+
+ +
+ +

Accessibility: + +

    +
  • The buttons are actual HTML buttons. You can therefore + use the TAB key to give the focus to the panel's buttons, and the "ENTER" + key to activate or trigger the corresponding control.
  • +
  • The buttons include text and titles (displayed when a button + is hovered).
  • +
  • If you remove colors from the page (for example using FireFox's No + Color extension) the buttons are still visible, and + accessible using the keyboard.
  • +
+

+ +

By default a panel creates buttons as divs. In this example the + createControlMarkup panel function is overridden to create + a more accessible markup for the buttons. See the accessible-panel.js + source to see how this is done.

+ +
+ + + diff --git a/examples/accessible-panel.js b/examples/accessible-panel.js new file mode 100644 index 0000000000..f982fc624b --- /dev/null +++ b/examples/accessible-panel.js @@ -0,0 +1,64 @@ +var lon = 5; +var lat = 40; +var zoom = 5; +var map, layer; + +function init() { + map = new OpenLayers.Map( 'map', { controls: [] } ); + layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", + "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} ); + map.addLayer(layer); + + vlayer = new OpenLayers.Layer.Vector( "Editable" ); + map.addLayer(vlayer); + + zb = new OpenLayers.Control.ZoomBox({ + title: "Zoom box: zoom clicking and dragging", + text: "Zoom" + }); + + var panel = new OpenLayers.Control.Panel({ + defaultControl: zb, + createControlMarkup: function(control) { + var button = document.createElement('button'), + iconSpan = document.createElement('span'), + textSpan = document.createElement('span'); + iconSpan.innerHTML = ' '; + button.appendChild(iconSpan); + if (control.text) { + textSpan.innerHTML = control.text; + } + button.appendChild(textSpan); + return button; + } + }); + + panel.addControls([ + zb, + new OpenLayers.Control.DrawFeature(vlayer, OpenLayers.Handler.Path, + {title:'Draw a feature', text: 'Draw'}), + new OpenLayers.Control.ZoomToMaxExtent({ + title:"Zoom to the max extent", + text: "World" + }) + ]); + + nav = new OpenLayers.Control.NavigationHistory({ + previousOptions: { + title: "Go to previous map position", + text: "Prev" + }, + nextOptions: { + title: "Go to next map position", + text: "Next" + }, + displayClass: "navHistory" + }); + // parent control must be added to the map + map.addControl(nav); + panel.addControls([nav.next, nav.previous]); + + map.addControl(panel); + + map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); +} From 0f0e60c3361caa6b300315481574a25ad384a588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 8 Feb 2012 10:05:21 +0100 Subject: [PATCH 04/16] [examples] more docs in the accessible-panel example --- examples/accessible-panel.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/accessible-panel.html b/examples/accessible-panel.html index 39754ceccc..d46d4fbfee 100644 --- a/examples/accessible-panel.html +++ b/examples/accessible-panel.html @@ -97,7 +97,7 @@
-

Accessibility: +

An accessible panel:

  • The buttons are actual HTML buttons. You can therefore @@ -118,6 +118,12 @@ href="accessible-panel.js" target="_blank"> accessible-panel.js source to see how this is done.

    +

    Note: in IE 8, when a button is pressed its content shifts by 1 pixel. + This is a known + IE8 bug, with known workarounds. No workaround is applied in this + example though.

    +
From 3b7585be24bec60f5ef9cbc6122ce3c560e4b007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 15 Feb 2012 16:06:06 +0100 Subject: [PATCH 05/16] avoid useless deref --- lib/OpenLayers/Control/Panel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Control/Panel.js b/lib/OpenLayers/Control/Panel.js index c1760f03c0..7a936b6ff1 100644 --- a/lib/OpenLayers/Control/Panel.js +++ b/lib/OpenLayers/Control/Panel.js @@ -253,7 +253,7 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { if (control.title != "") { element.title = control.title; } - controls[i].panel_div = element; + control.panel_div = element; } if (this.map) { // map.addControl() has already been called on the panel From 9e488252055799dfa28f3d0898f6d8190a12586f Mon Sep 17 00:00:00 2001 From: Xavier Mamano Date: Sat, 18 Feb 2012 17:51:36 +0100 Subject: [PATCH 06/16] Preserve the title and the className if they are set in `createControlMarkup`. --- lib/OpenLayers/Control/Panel.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Control/Panel.js b/lib/OpenLayers/Control/Panel.js index 7a936b6ff1..f141671445 100644 --- a/lib/OpenLayers/Control/Panel.js +++ b/lib/OpenLayers/Control/Panel.js @@ -249,8 +249,10 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { for (var i=0, len=controls.length; i Date: Wed, 29 Feb 2012 00:56:52 +0100 Subject: [PATCH 07/16] [Event.buttonclick] make buttonclick work if target element is a child of the clicked button --- lib/OpenLayers/Events/buttonclick.js | 41 ++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/OpenLayers/Events/buttonclick.js b/lib/OpenLayers/Events/buttonclick.js index f4de405997..f772c761f4 100644 --- a/lib/OpenLayers/Events/buttonclick.js +++ b/lib/OpenLayers/Events/buttonclick.js @@ -97,6 +97,31 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({ delete this.target; }, + /** + * Method: getPressedButton + * Get the pressed button, if any. Returns undefined if no button + * was pressed. + * + * Arguments: + * element - {DOMElement} The event target. + * + * Returns: + * {DOMElement} The button element, or undefined. + */ + getPressedButton: function(element) { + var depth = 5, // limit the search depth + button; + do { + if(OpenLayers.Element.hasClass(element, "olButton")) { + // hit! + button = element; + break; + } + element = element.parentNode; + } while(--depth > 0 && element); + return button; + }, + /** * Method: buttonClick * Check if a button was clicked, and fire the buttonclick event @@ -108,27 +133,25 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({ var propagate = true, element = OpenLayers.Event.element(evt); if (element && (OpenLayers.Event.isLeftClick(evt) || !~evt.type.indexOf("mouse"))) { - if (element.nodeType === 3 || OpenLayers.Element.hasClass(element, "olAlphaImg")) { - element = element.parentNode; - } - if (OpenLayers.Element.hasClass(element, "olButton")) { + // was a button pressed? + var button = this.getPressedButton(element); + if (button) { if (evt.type === "keydown") { switch (evt.keyCode) { case OpenLayers.Event.KEY_RETURN: case OpenLayers.Event.KEY_SPACE: this.target.triggerEvent("buttonclick", { - buttonElement: element + buttonElement: button }); OpenLayers.Event.stop(evt); propagate = false; break; } - } - if (this.startEvt) { + } else if (this.startEvt) { if (this.completeRegEx.test(evt.type)) { - var pos = OpenLayers.Util.pagePosition(element); + var pos = OpenLayers.Util.pagePosition(button); this.target.triggerEvent("buttonclick", { - buttonElement: element, + buttonElement: button, buttonXY: { x: this.startEvt.clientX - pos[0], y: this.startEvt.clientY - pos[1] From b7eba35077a1f6d9404d203ad2893c88127cee42 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 29 Feb 2012 08:11:14 +0100 Subject: [PATCH 08/16] Notes on incorrect maxResolution of 156543.0339 and defaults coupled with projection --- notes/2.12.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/notes/2.12.md b/notes/2.12.md index b77d87739d..a027464c07 100644 --- a/notes/2.12.md +++ b/notes/2.12.md @@ -84,8 +84,39 @@ The `OpenLayers.Tile.Image` class now has a method to get a canvas context for p tileOptions: {crossOriginKeyword: null} +Both `OpenLayers.Layer.OSM` and `OpenLayers.Layer.Bing` do not have defaults for `maxExtent`, `maxResolutions` and `units` any more. This may break maps that are configured with a `maxResolution` of `156543.0339`, which was used in examples before 2.11, but is incorrect. The correct value is `156543.03390625`, but it is no longer necessary to specify a maxResolution, maxExtent and units if the correct resolution is set. See "Projection and Spherical Mercator" below. + ## Projection & SphericalMercator +When working with Web Mercator layers (e.g. Google, Bing, OSM), it was previously necessary to configure the map or the base layer with the correct `projection`, `maxExtent`, `maxResolutions` and `units`. Now OpenLayers has defaults for WGS84 and Web Mercator in `OpenLayers.Projection.defaults`, so it is enough to provide the `projection`. + +Old: + + new OpenLayers.Map({ + div: "map", + projection: "EPSG:900913", + maxResolution: 156543.03390625, + maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34), + units: "m", + layers: [ + new OpenLayers.Layer.Google("Google Streets"), + new OpenLayers.Layer.OSM(null, null, {isBaseLayer: false, opcity: 0.7}) + ], + zoom: 1 + }); + +New: + + new OpenLayers.Map({ + div: "map", + projection: "EPSG:900913", + layers: [ + new OpenLayers.Layer.Google("Google Streets"), + new OpenLayers.Layer.OSM(null, null, {isBaseLayer: false, opcity: 0.7}) + ], + zoom: 1 + }); + In previous releases, coordinate transforms between EPSG:4326 and EPSG:900913 were defined in the SphericalMercator.js script. In 2.12, these default transforms are included in the Projection.js script. The Projection.js script is included as a dependency in builds with any layer types, so no special build configuration is necessary to get the web mercator transforms. If you were previously using the `OpenLayers.Layer.SphericalMercator.forwardMercator` or `inverseMercator` methods, you may have to explicitly include the SphericalMercator.js script in your build. The Google layer is the only layer that depends on the SphericalMercator mixin. If you are not using the Google layer but want to use the SphericalMercator methods listed above, you have to explicitly include the SphericalMercator.js script in your build. From d0c782ca745104aa19e31f758e8327b1cce0a320 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 29 Feb 2012 10:40:45 +0100 Subject: [PATCH 09/16] Making LayerSwitcher work again outside viewport. --- lib/OpenLayers/Control/LayerSwitcher.js | 10 ++++++++-- tests/Control/LayerSwitcher.html | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Control/LayerSwitcher.js b/lib/OpenLayers/Control/LayerSwitcher.js index a0e480e385..b1f2cc49cb 100644 --- a/lib/OpenLayers/Control/LayerSwitcher.js +++ b/lib/OpenLayers/Control/LayerSwitcher.js @@ -120,7 +120,7 @@ OpenLayers.Control.LayerSwitcher = initialize: function(options) { OpenLayers.Control.prototype.initialize.apply(this, arguments); this.layerStates = []; - + if(this.roundedCorner) { OpenLayers.Console.warn('roundedCorner option is deprecated'); } @@ -143,6 +143,7 @@ OpenLayers.Control.LayerSwitcher = changebaselayer: this.redraw, scope: this }); + this.events.unregister("buttonclick", this, this.onButtonClick); OpenLayers.Control.prototype.destroy.apply(this, arguments); }, @@ -157,13 +158,18 @@ OpenLayers.Control.LayerSwitcher = OpenLayers.Control.prototype.setMap.apply(this, arguments); this.map.events.on({ - buttonclick: this.onButtonClick, addlayer: this.redraw, changelayer: this.redraw, removelayer: this.redraw, changebaselayer: this.redraw, scope: this }); + if (this.outsideViewport) { + this.events.attachToElement(this.div); + this.events.register("buttonclick", this, this.onButtonClick); + } else { + this.map.events.register("buttonclick", this, this.onButtonClick); + } }, /** diff --git a/tests/Control/LayerSwitcher.html b/tests/Control/LayerSwitcher.html index 47895857d2..0094e77108 100644 --- a/tests/Control/LayerSwitcher.html +++ b/tests/Control/LayerSwitcher.html @@ -25,15 +25,17 @@ t.ok( div != null, "draw returns its div" ); } function test_Control_LayerSwitcher_outsideViewport (t) { - t.plan( 2 ); + t.plan( 4 ); map = new OpenLayers.Map('map'); control = new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')}); map.addControl(control); - t.eq(control.div.style.width, "250px", "Div is not minimized when added."); + t.eq(control.div.style.width, "250px", "Div is not minimized when added."); + t.ok(control.events.element && control.events.listeners.buttonclick, "[outside] Events instance attached to div and has buttonclick event"); control = new OpenLayers.Control.LayerSwitcher(); map.addControl(control); t.eq(control.div.style.width, "0px", "Div is minimized when added."); + t.ok(!control.events.element && map.events.listeners.buttonclick, "[inside] Events instance not attached to div and buttonclick event registered on map"); } function test_Control_LayerSwitcher_loadContents(t) { From 557d7ab0d77a910c26d65867467aae99d81663c3 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 29 Feb 2012 10:49:40 +0100 Subject: [PATCH 10/16] Fixing typo. --- notes/2.12.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notes/2.12.md b/notes/2.12.md index a027464c07..e4e9b09ca3 100644 --- a/notes/2.12.md +++ b/notes/2.12.md @@ -100,7 +100,7 @@ Old: units: "m", layers: [ new OpenLayers.Layer.Google("Google Streets"), - new OpenLayers.Layer.OSM(null, null, {isBaseLayer: false, opcity: 0.7}) + new OpenLayers.Layer.OSM(null, null, {isBaseLayer: false, opacity: 0.7}) ], zoom: 1 }); @@ -112,7 +112,7 @@ New: projection: "EPSG:900913", layers: [ new OpenLayers.Layer.Google("Google Streets"), - new OpenLayers.Layer.OSM(null, null, {isBaseLayer: false, opcity: 0.7}) + new OpenLayers.Layer.OSM(null, null, {isBaseLayer: false, opacity: 0.7}) ], zoom: 1 }); From b699afa57f7b9a6e03815558ac89f64922719186 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Wed, 29 Feb 2012 10:57:08 +0100 Subject: [PATCH 11/16] make vendorOptions an object instead of an array, which makes it more convenient to prevent duplicate vendorOptions --- lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js b/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js index 49596be1c4..bee661311b 100644 --- a/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js +++ b/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js @@ -58,12 +58,9 @@ OpenLayers.Format.SLD.v1_0_0_GeoServer = OpenLayers.Class( }, "VendorOption": function(node, obj) { if (!obj.vendorOptions) { - obj.vendorOptions = []; + obj.vendorOptions = {}; } - obj.vendorOptions.push({ - name: node.getAttribute("name"), - value: this.getChildValue(node) - }); + obj.vendorOptions[node.getAttribute("name")] = this.getChildValue(node); } }, OpenLayers.Format.SLD.v1_0_0.prototype.readers["sld"]) }, OpenLayers.Format.SLD.v1_0_0.prototype.readers), @@ -130,8 +127,11 @@ OpenLayers.Format.SLD.v1_0_0_GeoServer = OpenLayers.Class( addVendorOptions: function(node, symbolizer) { var options = symbolizer.vendorOptions; if (options) { - for (var i=0, ii=options.length; i Date: Wed, 29 Feb 2012 10:40:20 +0000 Subject: [PATCH 12/16] Make layer opacity api property --- lib/OpenLayers/Layer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 1a2a1999e4..788b6e7633 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -34,7 +34,7 @@ OpenLayers.Layer = OpenLayers.Class({ div: null, /** - * Property: opacity + * APIProperty: opacity * {Float} The layer's opacity. Float number between 0.0 and 1.0. Default * is 1. */ From 6a43fcaefcf7f5ffee2f2d6a4ee1a4bd864e5add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 29 Feb 2012 13:34:47 +0100 Subject: [PATCH 13/16] change buttonclick.getPressedButton depth value from 5 to 3, this allows buttons with grand children (2 levels) --- lib/OpenLayers/Events/buttonclick.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Events/buttonclick.js b/lib/OpenLayers/Events/buttonclick.js index f772c761f4..6520b83a0d 100644 --- a/lib/OpenLayers/Events/buttonclick.js +++ b/lib/OpenLayers/Events/buttonclick.js @@ -109,7 +109,7 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({ * {DOMElement} The button element, or undefined. */ getPressedButton: function(element) { - var depth = 5, // limit the search depth + var depth = 3, // limit the search depth button; do { if(OpenLayers.Element.hasClass(element, "olButton")) { From 98ff5473a6658e9f052947f5036579c464d29a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 29 Feb 2012 13:36:07 +0100 Subject: [PATCH 14/16] add tests for buttonclick.getPressedButton --- tests/Events/buttonclick.html | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/Events/buttonclick.html b/tests/Events/buttonclick.html index 7d12710cf6..35ebb81f8a 100644 --- a/tests/Events/buttonclick.html +++ b/tests/Events/buttonclick.html @@ -27,6 +27,41 @@ buttonClick.destroy(); events.destroy(); } + + function test_getPressedButton(t) { + t.plan(4); + + // set up + + events = new OpenLayers.Events({}, element); + buttonClick = new OpenLayers.Events.buttonclick(events); + + var button = document.createElement('button'), + span1 = document.createElement('span'), + span2 = document.createElement('span'), + span3 = document.createElement('span'); + button.className = 'olButton'; + button.appendChild(span1); + span1.appendChild(span2); + span2.appendChild(span3); + + t.ok(buttonClick.getPressedButton(button) === button, + 'getPressedButton returns button when element is button'); + t.ok(buttonClick.getPressedButton(span1) === button, + 'getPressedButton returns button when element is button descendant level 1'); + t.ok(buttonClick.getPressedButton(span2) === button, + 'getPressedButton returns button when element is button descendant level 2'); + t.eq(buttonClick.getPressedButton(span3), undefined, + 'getPressedButton returns undefined when element is button descendant level 3'); + + // test + + + // tear down + + buttonClick.destroy(); + events.destroy(); + } function test_ButtonClick_buttonClick(t) { t.plan(27); From 0e1a30b3cdcd26efbe092dba144833552e045fe6 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Wed, 29 Feb 2012 14:42:11 +0100 Subject: [PATCH 15/16] PointPlacement and LinePlacement are choices, so don't output both --- lib/OpenLayers/Format/SLD/v1.js | 6 ++++-- tests/Format/SLD/v1_0_0.html | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Format/SLD/v1.js b/lib/OpenLayers/Format/SLD/v1.js index f934f80d65..cd32810be9 100644 --- a/lib/OpenLayers/Format/SLD/v1.js +++ b/lib/OpenLayers/Format/SLD/v1.js @@ -990,12 +990,14 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, { }, "LabelPlacement": function(symbolizer) { var node = this.createElementNSPlus("sld:LabelPlacement"); - if (symbolizer.labelAnchorPointX != null || + // PointPlacement and LinePlacement are choices, so don't output both + if ((symbolizer.labelAnchorPointX != null || symbolizer.labelAnchorPointY != null || symbolizer.labelAlign != null || symbolizer.labelXOffset != null || symbolizer.labelYOffset != null || - symbolizer.labelRotation != null) { + symbolizer.labelRotation != null) && + symbolizer.labelPerpendicularOffset == null) { this.writeNode("PointPlacement", symbolizer, node); } if (symbolizer.labelPerpendicularOffset != null) { diff --git a/tests/Format/SLD/v1_0_0.html b/tests/Format/SLD/v1_0_0.html index af58c30c7d..46794902f0 100644 --- a/tests/Format/SLD/v1_0_0.html +++ b/tests/Format/SLD/v1_0_0.html @@ -538,7 +538,8 @@ }), new OpenLayers.Symbolizer.Text({ label: "${FOO}", - labelPerpendicularOffset: 10 + labelPerpendicularOffset: 10, + labelAlign: "rb" }) ] }) From 2421ed6da3d5b7985172dec93aca85e5c77a38a5 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Wed, 29 Feb 2012 14:53:20 +0100 Subject: [PATCH 16/16] add comments to the test (suggestion by @ahocevar) --- tests/Format/SLD/v1_0_0.html | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Format/SLD/v1_0_0.html b/tests/Format/SLD/v1_0_0.html index 46794902f0..a295a746b8 100644 --- a/tests/Format/SLD/v1_0_0.html +++ b/tests/Format/SLD/v1_0_0.html @@ -528,6 +528,7 @@ var format = new OpenLayers.Format.SLD.v1_0_0({ multipleSymbolizers: true }); + // labelPerpendicularOffset takes precedence over labelAlign var style = new OpenLayers.Style2({ rules: [ new OpenLayers.Rule({