1. openscales-team
  2. Untitled project
  3. openscales
  4. Issues
Issue #433 new

How to Add a KeyboardEvent to the map?

Anonymous created an issue

hi,I add a keyboradEvent to the map object(org.openscales.core.map),but it doesn't work . whether the map object could add the keyboradEvent? how to do? thanks.

Comments (1)

  1. payamp

    I just started using openscales (today), so I am no expert, but I added the event listener to the stage instead of the map. stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownEventHandler);

    			private static const LEFT_ARROW:uint = 37;
    			private static const UP_ARROW:uint = 38;
    			private static const RIGHT_ARROW:uint = 39;
    			private static const DOWN_ARROW:uint = 40;
    
    protected function keyDownEventHandler(event:KeyboardEvent ) : void 
    			{
    				var key:uint = event.keyCode;
    				var dist:Number;
    				
    				if( key == UP_ARROW || key == DOWN_ARROW ) {
    					dist = map.extent.height / 8;
    				} else {
    					dist = map.extent.width / 8;
    				}
    				var center:Location;
    				switch( key ) {
    					case UP_ARROW:
    						center = new Location( map.center.x , map.center.y + dist );
    						map.moveTo( center, map.zoom, true);
    						break;
    					case DOWN_ARROW:
    						center = new Location( map.center.x , map.center.y - dist );
    						map.moveTo( center, map.zoom, true);
    						break;
    					case RIGHT_ARROW:
    						center = new Location( map.center.x + dist , map.center.y );
    						map.moveTo( center, map.zoom, true);
    						break;
    					case LEFT_ARROW:
    						center = new Location( map.center.x - dist , map.center.y );
    						map.moveTo( center, map.zoom, true);
    						break;
    					default:
    						
    				}
    			}
    
  2. Log in to comment