Interactive interface for browsing global, full-resolution satellite imagery
Changed degrees to always be less than 360 (or more than -360) Ref issue #427 - URL and button label will now always display a value between 360 and negative 360 degrees when using the alt-drag or finger drag commands. - setRotation on updateRotation so that degrees is always between +/- 360 Without setting the rotation on update & subtracting 360 degrees on set, you would need to drag the window x-times full rotations before getting back to 0. Meaning if you dragged left 4 times, meant you would get a negative degree value (0 to -360) but it wouldn't show positive again until dragging right 4 times (0 to 360). This fixes that issue. So , even when dragging left 4 times, dragging 1 time right passed 0 degrees will get you back to positive degrees.
ZachTRice1a331dd8ac49
diff --git a/web/js/map/wv.map.model.js b/web/js/map/wv.map.model.jsindex 0b976602e..4d978d064 100644--- a/web/js/map/wv.map.model.js+++ b/web/js/map/wv.map.model.js@@ -25,32 +25,32 @@ wv.map.model = wv.map.model || function(models, config) {self.events = wv.util.events();self.rotation = 0;/*- * Emits update event- *- * @method update- * @static- *- * @param extent {object} Map Extent Array- *- * @returns {void}- */+ * Emits update event+ *+ * @method update+ * @static+ *+ * @param extent {object} Map Extent Array+ *+ * @returns {void}+ */self.update = function(extent) {self.extent = extent;self.events.trigger("update", extent);};/*- * Sets map view from parsed URL- *- * @method load- * @static- *- * @param state {object} map state object from permalink- *- * @param errors {string} errors- *- * @returns {void}- */+ * Sets map view from parsed URL+ *+ * @method load+ * @static+ *+ * @param state {object} map state object from permalink+ *+ * @param errors {string} errors+ *+ * @returns {void}+ */self.load = function(state, errors) {if (state.v) {var proj = models.proj.selected;@@ -64,9 +64,7 @@ wv.map.model = wv.map.model || function(models, config) {self.extent = state.v;} else {self.extent = _.clone(proj.maxExtent);- errors.push({- message: "Extent outside of range"- });+ errors.push({message: "Extent outside of range"});}}//get rotation if it exists@@ -76,42 +74,40 @@ wv.map.model = wv.map.model || function(models, config) {};/*- * Saves extent and rotation When- * models.link.toQueryString() is called- *- * @method save- * @static- *- * @param state {object} map state object from permalink- *- *- * @returns {void}- */+ * Saves extent and rotation When+ * models.link.toQueryString() is called+ *+ * @method save+ * @static+ *+ * @param state {object} map state object from permalink+ *+ *+ * @returns {void}+ */self.save = function(state) {state.v = _.clone(self.extent);if (self.rotation !== 0.0 && self.rotation !== 0 && models.proj.selected.id !== 'geographic')- state.r = (self.rotation * (180.0 / Math.PI))- .toPrecision(6); //convert from radians to degrees+ state.r = (self.rotation * (180.0 / Math.PI)).toPrecision(6); //convert from radians to degrees};/*- * Set default extent according to time of day:- *- * at 00:00 UTC, start at far eastern edge of- * map: "20.6015625,-46.546875,179.9296875,53.015625"- *- * at 23:00 UTC, start at far western edge of map:- * "-179.9296875,-46.546875,-20.6015625,53.015625"- *- * @method getLeadingExtent- * @static- *- *- * @returns {object} Extent Array- */+ * Set default extent according to time of day:+ *+ * at 00:00 UTC, start at far eastern edge of+ * map: "20.6015625,-46.546875,179.9296875,53.015625"+ *+ * at 23:00 UTC, start at far western edge of map:+ * "-179.9296875,-46.546875,-20.6015625,53.015625"+ *+ * @method getLeadingExtent+ * @static+ *+ *+ * @returns {object} Extent Array+ */self.getLeadingExtent = function() {- var curHour = wv.util.now()- .getUTCHours();+ var curHour = wv.util.now().getUTCHours();// For earlier hours when data is still being filled in, force a far eastern perspectiveif (curHour < 3) {diff --git a/web/js/map/wv.map.rotate.js b/web/js/map/wv.map.rotate.jsindex c4e101ab7..e409fb65c 100644--- a/web/js/map/wv.map.rotate.js+++ b/web/js/map/wv.map.rotate.js@@ -21,70 +21,58 @@ wv.map.rotate = wv.map.rotate || function(ui, models, map) {this.intervalId = null;var self = this;-/*- * Initializes by triggering build methods- *- * @method init- * @static- *- * @param {object} map - openLayers map object- *- * @param {string} d - projection id string- *- * @returns {void}- */+ * Initializes by triggering build methods+ *+ * @method init+ * @static+ *+ * @param {object} map - openLayers map object+ *+ * @param {string} d - projection id string+ *+ * @returns {void}+ */this.init = function(map, id) {this.buildRotationWidget(map);this.setRotationEvents(map, id);};/*- * Draws Rotation Widget- *- * @method createRotationWidget- * @static- *- * @param {object} map - openLayers map object- *- * @returns {void}- */+ * Draws Rotation Widget+ *+ * @method createRotationWidget+ * @static+ *+ * @param {object} map - openLayers map object+ *+ * @returns {void}+ */this.buildRotationWidget = function(map) {var $map = $("#" + map.getTarget());- var $rotateLeftButton = $("<button></button>")- .addClass("wv-map-rotate-left wv-map-zoom")- .attr("title", "You may also rotate by holding Alt and dragging the mouse");- var $lefticon = $("<i></i>")- .addClass("fa fa-undo");-- var $rotateRightButton = $("<button></button>")- .addClass("wv-map-rotate-right wv-map-zoom")- .attr("title", "You may also rotate by holding Alt and dragging the mouse");- var $righticon = $("<i></i>")- .addClass("fa fa-repeat");-- var $resetButton = $("<button></button>")- .addClass("wv-map-reset-rotation wv-map-zoom")- .attr("title", "Click to reset")- .attr("style", "width: 43px");+ var $rotateLeftButton = $("<button></button>").addClass("wv-map-rotate-left wv-map-zoom").attr("title", "You may also rotate by holding Alt and dragging the mouse");+ var $lefticon = $("<i></i>").addClass("fa fa-undo");++ var $rotateRightButton = $("<button></button>").addClass("wv-map-rotate-right wv-map-zoom").attr("title", "You may also rotate by holding Alt and dragging the mouse");+ var $righticon = $("<i></i>").addClass("fa fa-repeat");++ var $resetButton = $("<button></button>").addClass("wv-map-reset-rotation wv-map-zoom").attr("title", "Click to reset").attr("style", "width: 43px");$rotateLeftButton.append($lefticon);$rotateRightButton.append($righticon);- $map.append($rotateLeftButton)- .append($resetButton)- .append($rotateRightButton);+ $map.append($rotateLeftButton).append($resetButton).append($rotateRightButton);};/*- * Applies Jquery click events to rotation-widget- *- * @method setRotationEvents- * @static- *- * @param {object} map - openLayers map object- *- * @param {string} d - projection id string- *- * @returns {void}- */+ * Applies Jquery click events to rotation-widget+ *+ * @method setRotationEvents+ * @static+ *+ * @param {object} map - openLayers map object+ *+ * @param {string} d - projection id string+ *+ * @returns {void}+ */this.setRotationEvents = function(map, id) {var dur = 500;var $leftButton = $('#wv-map-' + id + ' .wv-map-rotate-left');@@ -92,143 +80,130 @@ wv.map.rotate = wv.map.rotate || function(ui, models, map) {var $resetButton = $('#wv-map-' + id + ' .wv-map-reset-rotation');//Set buttons to animate rotation by 18 degrees. use setInterval to repeat the rotation when mouse button is held- $leftButton.button({- text: false- })- .mousedown(function() {- self.intervalId = setInterval(function() {- self.rotate(10, dur, map);- }, dur);+ $leftButton.button({text: false}).mousedown(function() {+ self.intervalId = setInterval(function() {self.rotate(10, dur, map);+ }, dur);+ self.rotate(10, dur, map);++ }).mouseup(function() {+ clearInterval(self.intervalId);+ });- })- .mouseup(function() {- clearInterval(self.intervalId);- });-- $rightButton.button({- text: false- })- .mousedown(function() {- self.intervalId = setInterval(function() {- self.rotate(-10, dur, map);- }, dur);+ $rightButton.button({text: false}).mousedown(function() {+ self.intervalId = setInterval(function() {self.rotate(-10, dur, map);+ }, dur);+ self.rotate(-10, dur, map);- })- .mouseup(function() {- clearInterval(self.intervalId);- });+ }).mouseup(function() {+ clearInterval(self.intervalId);+ });$resetButton.button({- label: Number(models.map.rotation * (180 / Math.PI))- .toFixed()- })- .mousedown(function() { //reset rotation- clearInterval(self.intervalId); //stop repeating rotation on mobile- map.getView()- .animate({- duration: 500,- rotation: 0- });-- $resetButton.button("option", "label", "0");- });- };+ label: Number(models.map.rotation * (180 / Math.PI)).toFixed()+ }).mousedown(function() { //reset rotation+ clearInterval(self.intervalId); //stop repeating rotation on mobile+ map.getView().animate({duration: 500, rotation: 0});+ $resetButton.button("option", "label", "0");+ });+ };/*- * Called as event listener when map is rotated. Update url to reflect rotation reset- *- * @method updateRotation- * @static- *- * @returns {void}- */+ * Called as event listener when map is rotated. Update url to reflect rotation reset+ *+ * @method updateRotation+ * @static+ *+ * @returns {void}+ */this.updateRotation = function() {- var deg, radians, view;+ var deg,+ radians,+ view,+ currentDeg;view = ui.selected.getView();radians = view.getRotation();models.map.rotation = radians;self.setResetButton(radians);- };-+ currentDeg = (view.getRotation() * (180.0 / Math.PI));+ if (Math.abs(currentDeg) === 360) {+ view.setRotation(0);+ } else if (Math.abs(currentDeg) >= 360) {+ var newNadVal = ((360 - Math.abs(currentDeg)) * (Math.PI / 180));+ if (currentDeg < 0) {+ view.setRotation(newNadVal);+ } else {+ view.setRotation(-newNadVal);+ }+ }+ };/*- * examines the number of characters present in the- * reset button and reassigns padding accordingly- *- * @method setResetButtonWidth- * @static- *- * @param {number} deg - map rotation degree value- *- * @returns {void}- */+ * examines the number of characters present in the+ * reset button and reassigns padding accordingly+ *+ * @method setResetButtonWidth+ * @static+ *+ * @param {number} deg - map rotation degree value+ *+ * @returns {void}+ */this.setResetButton = function(radians) {var button = $(".wv-map-reset-rotation");var deg = radians * (180.0 / Math.PI);//Set reset button content- button.button("option", "label", Number(deg)- .toFixed());+ button.button("option", "label", Number(deg % 360).toFixed());switch (true) {- case (deg >= 100.0):- button.find("span")- .attr("style", "padding-left: 9px");+ case(deg >= 100.0):+ button.find("span").attr("style", "padding-left: 9px");break;- case (deg <= -100.0):- button.find("span")- .attr("style", "padding-left: 6px");+ case(deg <= -100.0):+ button.find("span").attr("style", "padding-left: 6px");break;- case (deg <= -10.0):- button.find("span")- .attr("style", "padding-left: 10px");+ case(deg <= -10.0):+ button.find("span").attr("style", "padding-left: 10px");break;default:- button.find("span")- .attr("style", "padding-left: 14px");+ button.find("span").attr("style", "padding-left: 14px");break;}};/*- * Called as event listener when map is rotated. Update url to reflect rotation reset- *- * @method rotate- * @static- *- * @param {number} amount - value of degrees to rotate- *- * @param {number} duration - how long the animation should last- *- * @param {object} map - openLayers map object- *- * @returns {void}- */+ * Called as event listener when map is rotated. Update url to reflect rotation reset+ *+ * @method rotate+ * @static+ *+ * @param {number} amount - value of degrees to rotate+ *+ * @param {number} duration - how long the animation should last+ *+ * @param {object} map - openLayers map object+ *+ * @returns {void}+ */this.rotate = function(amount, duration, map) {- var currentDeg = (map.getView()- .getRotation() * (180.0 / Math.PI));+ var currentDeg = (map.getView().getRotation() * (180.0 / Math.PI));if (Math.abs(currentDeg) === 360) {- map.getView()- .setRotation(0);+ map.getView().setRotation(0);} else if (Math.abs(currentDeg) >= 360) {var newNadVal = ((360 - Math.abs(currentDeg)) * (Math.PI / 180));if (currentDeg < 0) {- map.getView()- .setRotation(newNadVal);+ map.getView().setRotation(newNadVal);} else {- map.getView()- .setRotation(-newNadVal);+ map.getView().setRotation(-newNadVal);}}- map.getView()- .animate({- rotation: map.getView()- .getRotation() - (Math.PI / amount),- duration: duration,- });+ map.getView().animate({+ rotation: map.getView().getRotation() - (Math.PI / amount),+ duration: duration+ });};};