Interactive interface for browsing global, full-resolution satellite imagery
rotation module code reform
Benjamin2b0622eb88d5
diff --git a/web/index.html b/web/index.htmlindex d7e033c2f..9505ad8cc 100644--- a/web/index.html+++ b/web/index.html@@ -197,8 +197,9 @@<!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.js"></script><!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.model.js"></script>+ <!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.rotate.js"></script><!-- link.dev --> <script type="text/javascript" src="js/map/wv.map.ui.js"></script>-+<!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.model.js"></script><!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.ui.js"></script>diff --git a/web/js/map/wv.map.rotate.js b/web/js/map/wv.map.rotate.jsnew file mode 100644index 000000000..ec96b1a7f--- /dev/null+++ b/web/js/map/wv.map.rotate.js@@ -0,0 +1,120 @@+var wv = wv || {};+wv.map = wv.map || {};++wv.map.rotate = wv.map.rotate || function(ui, models, map) {+ console.log('whatt')+ this.evt = wv.util.events();+ /*+ * Draws Rotation Widget+ *+ * @method createRotationWidget+ * @static+ *+ * @param map+ *+ */+ this.createRotationWidget = function(map) {+ var self = this;+ var $map = $("#" + map.getTarget());++ var $left = $("<button></button>")+ .addClass("wv-map-rotate-left wv-map-zoom")+ .attr("title","You may also rotate by holding Alt and dragging the mouse"),+ $lefticon = $("<i></i>")+ .addClass("fa fa-undo");++ var $right = $("<button></button>")+ .addClass("wv-map-rotate-right wv-map-zoom")+ .attr("title","You may also rotate by holding Alt and dragging the mouse"),+ $righticon = $("<i></i>")+ .addClass("fa fa-repeat");++ var $mid = $("<button></button>")+ .addClass("wv-map-reset-rotation wv-map-zoom")+ .attr("title", "Click to reset")+ .attr("style", "width: 43px");++ $left.append($lefticon); $right.append($righticon);+ $map.append($left).append($mid).append($right);++ var intervalId, dur = 500;++ //Set buttons to animate rotation by 18 degrees. use setInterval to repeat the rotation when mouse button is held+ $left.button({+ text: false+ }).mousedown(function() {+ self.rotate(10, dur, map);+ intervalId = setInterval(function() {+ self.rotate(10, dur, map);+ }, dur);+ }).mouseup(function() {+ clearInterval(intervalId);+ });++ $right.button({+ text: false+ }).mousedown(function() {+ self.rotate(-10, dur, map);+ intervalId = setInterval(function() {+ self.rotate(-10, dur, map);+ }, dur);+ }).mouseup(function() {+ clearInterval(intervalId);+ });++ $mid.button({+ label: Number(models.map.rotation * (180/Math.PI)).toFixed()+ }).mousedown(function() { //reset rotation+ clearInterval(intervalId); //stop repeating rotation on mobile+ map.beforeRender(ol.animation.rotate({+ duration: 500,+ rotation: map.getView().getRotation()+ }));+ map.getView().rotate(0);++ $mid.button("option", "label", "0");+ });+ };+++ //Called as event listener when map is rotated. Update url to reflect rotation reset+ this.updateRotation = function() {+ var deg, radians;+ radians = ui.selected.getView().getRotation();++ window.history.replaceState("", "@OFFICIAL_NAME@","?" + models.link.toQueryString());+ deg = ((radians) * (180.0 / Math.PI));++ if(Math.abs(deg) >= 360) {++ if(radians > 0) {+ this.evt.trigger('rotate-left-max')+ } else {+ this.evt.trigger('rotate-right-max')+ }+ models.map.rotation = radians;+ }++ //Set reset button content and proper CSS styling to position it correctly+ $(".wv-map-reset-rotation").button("option", "label", Number(deg).toFixed() );++ if(deg >= 100.0)+ $(".wv-map-reset-rotation").find("span").attr("style","padding-left: 9px");+ else if(deg <= -100.0)+ $(".wv-map-reset-rotation").find("span").attr("style","padding-left: 6px");+ else if(deg <= -10.0)+ $(".wv-map-reset-rotation").find("span").attr("style","padding-left: 10px");+ else+ $(".wv-map-reset-rotation").find("span").attr("style","padding-left: 14px");+ };++ this.rotate = function(amount, duration, map) {+ map.beforeRender(ol.animation.rotate({+ duration: duration,+ rotation: map.getView().getRotation()+ }));++ map.getView().rotate(map.getView().getRotation() - (Math.PI / amount));+ }+}+diff --git a/web/js/map/wv.map.ui.js b/web/js/map/wv.map.ui.jsindex fa08c236b..a589a48e9 100644--- a/web/js/map/wv.map.ui.js+++ b/web/js/map/wv.map.ui.js@@ -12,14 +12,14 @@var wv = wv || {};wv.map = wv.map || {};-wv.map.ui = wv.map.ui || function(models, config) {-+wv.map.ui = wv.map.ui || function(models, config, Rotation) {var id = "wv-map";var selector = "#" + id;var cache = new Cache(100); // Save layers from days visitedvar animationDuration = 250;-var self = {};+ var rotation = new Rotation(self, models);+self.proj = {}; // One map for each projectionself.selected = null; // The map for the selected projectionself.events = wv.util.events();@@ -71,7 +71,7 @@ wv.map.ui = wv.map.ui || function(models, config) {//Update the rotation buttons if polar projection to display correct valueif(models.proj.selected.id !== "geographic")- self.updateRotation();+ rotation.updateRotation();// If the browser was resized, the inactive map was not notified of// the event. Force the update no matter what and reposition the center@@ -404,22 +404,6 @@ wv.map.ui = wv.map.ui || function(models, config) {};//Called as event listener when map is rotated. Update url to reflect rotation reset- self.updateRotation = function() {- models.map.rotation = self.selected.getView().getRotation();- window.history.replaceState("", "@OFFICIAL_NAME@","?" + models.link.toQueryString());-- //Set reset button content and proper CSS styling to position it correctly- $(".wv-map-reset-rotation").button("option", "label", Number((models.map.rotation) * (180.0 / Math.PI)).toFixed() );- if((models.map.rotation) * (180.0 / Math.PI) >= 100.0)- $(".wv-map-reset-rotation").find("span").attr("style","padding-left: 9px");- else if((models.map.rotation) * (180.0 / Math.PI) <= -100.0)- $(".wv-map-reset-rotation").find("span").attr("style","padding-left: 6px");- else if((models.map.rotation) * (180.0 / Math.PI) <= -10.0)- $(".wv-map-reset-rotation").find("span").attr("style","padding-left: 10px");- else- $(".wv-map-reset-rotation").find("span").attr("style","padding-left: 14px");- };-var createMap = function(proj) {var id = "wv-map-" + proj.id;var $map = $("<div></div>")@@ -493,7 +477,7 @@ wv.map.ui = wv.map.ui || function(models, config) {//allow rotation by dragging for polar projectionsif(proj.id !== 'geographic') {- createRotationWidget(map);+ rotation.createRotationWidget(map);map.addInteraction(rotateInteraction);map.addInteraction(mobileRotation);}@@ -501,7 +485,7 @@ wv.map.ui = wv.map.ui || function(models, config) {//Set event listeners for changes on the map view (when rotated, zoomed, panned)map.getView().on("change:center", updateExtent);map.getView().on("change:resolution", updateExtent);- map.getView().on("change:rotation", self.updateRotation);+ map.getView().on("change:rotation", rotation.updateRotation);return map;};@@ -639,82 +623,6 @@ wv.map.ui = wv.map.ui || function(models, config) {});};- //Create rotation buttons for polar views- var createRotationWidget = function(map) {- var $map = $("#" + map.getTarget());-- var $left = $("<button></button>")- .addClass("wv-map-rotate-left wv-map-zoom")- .attr("title","You may also rotate by holding Alt and dragging the mouse"),- $lefticon = $("<i></i>")- .addClass("fa fa-undo");-- var $right = $("<button></button>")- .addClass("wv-map-rotate-right wv-map-zoom")- .attr("title","You may also rotate by holding Alt and dragging the mouse"),- $righticon = $("<i></i>")- .addClass("fa fa-repeat");-- var $mid = $("<button></button>")- .addClass("wv-map-reset-rotation wv-map-zoom")- .attr("title", "Click to reset")- .attr("style", "width: 43px");-- $left.append($lefticon); $right.append($righticon);- $map.append($left).append($mid).append($right);-- var intervalId, dur = 500;-- //Set buttons to animate rotation by 18 degrees. use setInterval to repeat the rotation when mouse button is held- $left.button({- text: false- }).mousedown(function() {- rotate(10, dur);- intervalId = setInterval(function() {- rotate(10, dur);- }, dur);- }).mouseup(function() {- clearInterval(intervalId);- });-- $right.button({- text: false- }).mousedown(function() {- rotate(-10, dur);- intervalId = setInterval(function() {- rotate(-10, dur);- }, dur);- }).mouseup(function() {- clearInterval(intervalId);- });-- $mid.button({- label: Number(models.map.rotation * (180/Math.PI)).toFixed()- }).mousedown(function() { //reset rotation- clearInterval(intervalId); //stop repeating rotation on mobile- map.beforeRender(ol.animation.rotate({- duration: 500,- rotation: map.getView().getRotation()- }));- map.getView().rotate(0);- self.updateRotation();-- $mid.button("option", "label", "0");- });-- //Function to rotate polar map tile when button is pressed. Amount divides a 180 degree rotation- var rotate = function(amount, duration) {- map.beforeRender(ol.animation.rotate({- duration: duration,- rotation: map.getView().getRotation()- }));-- map.getView().rotate(map.getView().getRotation() - (Math.PI / amount));- self.updateRotation();- };-- };-var zoomAction = function(map, amount) {return function() {var zoom = map.getView().getZoom();diff --git a/web/js/wv.main.js b/web/js/wv.main.jsindex 56573adaf..0a753c164 100644--- a/web/js/wv.main.js+++ b/web/js/wv.main.js@@ -128,7 +128,7 @@ $(function() {models.link.load(state);// HACK: Map needs to be created before the data download model- ui.map = wv.map.ui(models, config);+ ui.map = wv.map.ui(models, config, wv.map.rotate);if ( config.features.dataDownload ) {models.data = wv.data.model(models, config);}