diff --git a/lib/OpenLayers/Control/UTFGrid.js b/lib/OpenLayers/Control/UTFGrid.js index c05521b1c6..409975bb3c 100644 --- a/lib/OpenLayers/Control/UTFGrid.js +++ b/lib/OpenLayers/Control/UTFGrid.js @@ -5,6 +5,8 @@ /** * @requires OpenLayers/Control.js + * @requires OpenLayers/Handler/Hover.js + * @requires OpenLayers/Handler/Click.js */ /** @@ -31,122 +33,70 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, { element: null, debugElement: null, - /** - * APIProperty: prefix - * {String} - */ - prefix: '', - - /** - * APIProperty: separator - * {String} - */ - separator: ', ', - - /** - * APIProperty: suffix - * {String} - */ - suffix: '', - - /** - * APIProperty: numDigits - * {Integer} - */ - numDigits: 5, - - /** - * APIProperty: granularity - * {Integer} - */ - granularity: 10, - - /** - * APIProperty: emptyString - * {String} Set this to some value to set when the mouse is outside the - * map. - */ - emptyString: null, - /** * Property: lastXy * {} */ lastXy: null, - /** - * APIProperty: displayProjection - * {} The projection in which the - * mouse position is displayed - */ - displayProjection: null, - /** * Constructor: OpenLayers.Control.UTFGrid - * * Parameters: * options - {Object} Options for control. */ - - /** - * Method: destroy - */ - destroy: function() { - this.deactivate(); - OpenLayers.Control.prototype.destroy.apply(this, arguments); - }, - - /** - * APIMethod: activate - */ - activate: function() { - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { - this.map.events.register('mousemove', this, this.redraw); - this.map.events.register('mouseout', this, this.reset); - //this.map.events.register('click', this, this.redraw); - this.redraw(); - return true; - } else { - return false; - } + defaultHandlerOptions: { + 'delay': 500, + 'pixelTolerance': null, + 'stopMove': false, + 'single': true, + 'double': false, + 'pixelTolerance': 0, + 'stopSingle': false, + 'stopDouble': false }, - - /** - * APIMethod: deactivate - */ - deactivate: function() { - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { - //this.map.events.unregister('click', this, this.redraw); - this.map.events.unregister('mousemove', this, this.redraw); - this.map.events.unregister('mouseout', this, this.reset); - this.element.innerHTML = ""; - return true; - } else { - return false; + + handlerMode: 'move', + + setHandler: function() { + this.handler = null; + if (this.handlerMode == 'hover') { + // Handle this event on hover + this.handler = new OpenLayers.Handler.Hover( + this, + {'pause': this.handleEvent, 'move': this.reset}, + this.handlerOptions + ); + } else if (this.handlerMode == 'click') { + // Handle this event on click + this.handler = new OpenLayers.Handler.Click( + this, { + 'click': this.handleEvent + }, this.handlerOptions + ); + } else if (this.handlerMode == 'move') { + this.handler = new OpenLayers.Handler.Hover( + this, + // Handle this event while hovering OR moving + {'pause': this.handleEvent, 'move': this.handleEvent}, + this.handlerOptions + ); } }, - /** - * Method: draw - * {DOMElement} - */ - draw: function() { - OpenLayers.Control.prototype.draw.apply(this, arguments); + initialize: function(options) { + this.handlerOptions = OpenLayers.Util.extend( + {}, this.defaultHandlerOptions + ); + OpenLayers.Control.prototype.initialize.apply( + this, arguments + ); + this.setHandler(); + }, - if (!this.element) { - this.div.left = ""; - this.div.top = ""; - this.element = this.div; - } - - return this.div; - }, - /** - * Method: redraw + * Method: handleEvent */ - redraw: function(evt) { - + handleEvent: function(evt) { var lonLat; if (evt == null) { @@ -163,7 +113,7 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, { lonLat = this.map.getLonLatFromPixel(evt.xy); if (!lonLat) { - // map has not yet been properly initialized + // map may not have been properly initialized return; } this.lastXy = evt.xy; @@ -174,33 +124,15 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, { var layer; for (var i=0, len=layers.length; i"; - debug += "
  • j :" + info.j + "
  • "; - debug += "
  • globalrow :" + info.globalRow + "
  • "; - debug += "
  • globalcol :" + info.globalCol + "
  • "; - debug += "
  • gridrow :" + info.gridRow + "
  • "; - debug += "
  • gridcol :" + info.gridCol + "
  • "; - debug += "
  • gridrow offset :" + info.gridRowOffset + "
  • "; - debug += "
  • gridcol offset :" + info.gridColOffset + "
  • "; - debug += ""; - this.debugElement.innerHTML = debug; - } + this.writeDebugInfo(info); var tile = info.tile; - /* - MP TODO Sanity checks - if ((Math.floor(info.i) >= tileSize) || - (Math.floor(info.j) >= tileSize)) alert("TOO BIG"); - */ var attrs = null; - var resolution = 4; + var resolution = 4; //TODO autodetect? if (tile !== null && typeof(tile) !== 'undefined') { var data = tile.json if (data !== null) { - //val = data; var code = this.resolveCode(data.grid[ Math.floor((info.j) / resolution) ].charCodeAt( @@ -214,6 +146,25 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, { } }, + /** Method: + * + */ + writeDebugInfo: function(info) { + var debug = "
      "; + debug += "
    • i :" + info.i + "
    • "; + debug += "
    • j :" + info.j + "
    • "; + debug += "
    • globalrow :" + info.globalRow + "
    • "; + debug += "
    • globalcol :" + info.globalCol + "
    • "; + debug += "
    • gridrow :" + info.gridRow + "
    • "; + debug += "
    • gridcol :" + info.gridCol + "
    • "; + debug += "
    • gridrow offset :" + info.gridRowOffset + "
    • "; + debug += "
    • gridcol offset :" + info.gridColOffset + "
    • "; + debug += "
    "; + if (this.debugElement) { + this.debugElement.innerHTML = debug; + } + }, + /** * Method: callback * MP TODO @@ -254,9 +205,9 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, { * Method: reset */ reset: function(evt) { - if (this.emptyString != null) { + this.callback(null); + if (this.element) this.element.innerHTML = this.emptyString; - } }, /**