From 5a5e4cef4f979f32dfe80a8cbeace4b71a1f3d28 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Thu, 18 Apr 2013 14:38:14 -0400 Subject: [PATCH] Integrate keypress service for sphere dragging --- js/services.js | 23 ++++++++++++----------- panels/map2/module.js | 9 ++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/js/services.js b/js/services.js index 76971f32d2c..84ec92dba3c 100644 --- a/js/services.js +++ b/js/services.js @@ -108,15 +108,16 @@ angular.module('kibana.services', []) }) .service('keylistener', function($rootScope) { - var keys = []; - $(document).keydown(function (e) { - console.log("keydown", e.which); - keys[e.which] = true; - }); - - $(document).keyup(function (e) { - console.log("keyup", e.which); - delete keys[e.which]; - }); - + var keys = []; + $(document).keydown(function (e) { + keys[e.which] = true; }); + + $(document).keyup(function (e) { + delete keys[e.which]; + }); + + this.keyActive = function(key) { + return keys[key] == true; + } +}); diff --git a/panels/map2/module.js b/panels/map2/module.js index 02c03bfa55a..65e5d09aea2 100644 --- a/panels/map2/module.js +++ b/panels/map2/module.js @@ -60,7 +60,7 @@ angular.module('kibana.map2', []) // Now that we're all setup, request the time from our group eventBus.broadcast($scope.$id, $scope.panel.group, 'get_time'); - + $scope.keylistener = keylistener; }; @@ -276,7 +276,7 @@ angular.module('kibana.map2', []) scope.zoom = d3.behavior.zoom() - .scaleExtent([1, 8]) + .scaleExtent([1, 20]) .on("zoom", translate_map); //used by choropleth @@ -410,7 +410,6 @@ angular.module('kibana.map2', []) //If this is a sphere, set up drag and keypress listeners - //@todo implement a global "keypress service", since this fails if there are >1 spheres if (scope.panel.display.data.type === 'orthographic') { //scope.svg.focus(); @@ -429,7 +428,7 @@ angular.module('kibana.map2', []) .call(d3.behavior.drag() .origin(function() { var rotate = scope.projection.rotate(); return {x: 2 * rotate[0], y: -2 * rotate[1]}; }) .on("drag", function() { - if ( scope.ctrlKey) { + if (scope.keylistener.keyActive(17)) { scope.projection.rotate([d3.event.x / 2, -d3.event.y / 2, scope.projection.rotate()[2]]); scope.svg.selectAll("path").attr("d", path); } @@ -472,7 +471,7 @@ angular.module('kibana.map2', []) var width = $(elem[0]).width(), height = $(elem[0]).height(); - if (! scope.ctrlKey) { + if (! scope.keylistener.keyActive(17)) { var t = d3.event.translate, s = d3.event.scale; t[0] = Math.min(width / 2 * (s - 1), Math.max(width / 2 * (1 - s), t[0]));