Fixes for issues #198, #201, #202, #203

This commit is contained in:
Mark Salsbery 2013-08-26 16:48:59 -07:00
parent f8ab315795
commit 57ae0656c1
4 changed files with 53 additions and 40 deletions

View File

@ -36,7 +36,7 @@
/**
* For use by classes which want to support custom, non-browser events.
* TODO: This is an aweful name! This thing represents an "event source",
* TODO: This is an awful name! This thing represents an "event source",
* not an "event handler". PLEASE change the to EventSource. Also please
* change 'addHandler', 'removeHandler' and 'raiseEvent' to 'bind',
* 'unbind', and 'trigger' respectively. Finally add a method 'one' which
@ -55,14 +55,15 @@ $.EventHandler.prototype = {
* @function
* @param {String} eventName - Name of event to register.
* @param {Function} handler - Function to call when event is triggered.
* @param {Object} optional userData - Arbitrary object to be passed to the handler.
*/
addHandler: function( eventName, handler ) {
addHandler: function ( eventName, handler, userData ) {
var events = this.events[ eventName ];
if ( !events ) {
this.events[ eventName ] = events = [];
}
if ( handler && $.isFunction( handler ) ) {
events[ events.length ] = handler;
events[ events.length ] = { handler: handler, userData: userData || null };
}
},
@ -81,7 +82,7 @@ $.EventHandler.prototype = {
}
if ( $.isArray( events ) ) {
for ( i = 0; i < events.length; i++ ) {
if( events[ i ] !== handler ){
if ( events[i].handler !== handler ) {
handlers.push( events[ i ] );
}
}
@ -124,7 +125,8 @@ $.EventHandler.prototype = {
length = events.length;
for ( i = 0; i < length; i++ ) {
if (events[ i ]) {
events[ i ]( source, args );
args.userData = events[ i ].userData;
events[ i ].handler( source, args );
}
}
};

View File

@ -71,8 +71,16 @@ $.LegacyTileSource = function( levels ) {
//clean up the levels to make sure we support all formats
options.levels = filterFiles( options.levels );
if ( options.levels.length > 0 ) {
width = options.levels[ options.levels.length - 1 ].width;
height = options.levels[ options.levels.length - 1 ].height;
}
else {
width = 0;
height = 0;
$.console.error( "No supported image formats found" );
}
$.extend( true, options, {
width: width,
@ -80,7 +88,7 @@ $.LegacyTileSource = function( levels ) {
tileSize: Math.max( height, width ),
tileOverlap: 0,
minLevel: 0,
maxLevel: options.levels.length - 1
maxLevel: options.levels.length > 0 ? options.levels.length - 1 : 0
} );
$.TileSource.apply( this, [ options ] );
@ -141,7 +149,7 @@ $.extend( $.LegacyTileSource.prototype, $.TileSource.prototype, {
*/
getLevelScale: function ( level ) {
var levelScale = NaN;
if ( level >= this.minLevel && level <= this.maxLevel ){
if ( this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel ) {
levelScale =
this.levels[ level ].width /
this.levels[ this.maxLevel ].width;
@ -188,7 +196,7 @@ $.extend( $.LegacyTileSource.prototype, $.TileSource.prototype, {
*/
getTileUrl: function ( level, x, y ) {
var url = null;
if( level >= this.minLevel && level <= this.maxLevel ){
if ( this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel ) {
url = this.levels[ level ].url;
}
return url;
@ -223,6 +231,9 @@ function filterFiles( files ){
height: Number( file.height )
});
}
else {
$.console.error( 'Unsupported image format: %s', file.url ? file.url : '<no URL>' );
}
}
return filtered.sort(function(a,b){

View File

@ -117,8 +117,8 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve
for ( i = 0; i < arguments.length; i++ ) {
if ( $.isFunction( arguments[ i ] ) ) {
callback = arguments[ i ];
this.addHandler( 'ready', function( placeHolderSource, readySource ){
callback( readySource );
this.addHandler( 'ready', function ( placeHolderSource, placeHolderArgs ) {
callback( placeHolderArgs.tileSource );
} );
//only one callback per constructor
break;
@ -301,7 +301,7 @@ $.TileSource.prototype = {
options = $TileSource.prototype.configure.apply( _this, [ data, url ]);
readySource = new $TileSource( options );
_this.ready = true;
_this.raiseEvent( 'ready', readySource );
_this.raiseEvent( 'ready', { tileSource: readySource } );
};
if( url.match(/\.js$/) ){

View File

@ -1463,7 +1463,7 @@ function onCanvasDrag( tracker, position, delta, shift ) {
this.viewport.applyConstraints();
}
}
this.raiseEvent( 'canvas-click', {
this.raiseEvent( 'canvas-drag', {
tracker: tracker,
position: position,
delta: delta,