Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Rotation removed from view object. Calculating view rotated extent implemented. Need to restore rotation upon reload.

Stephan Wlodarczyk761bced96654
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index aac5aa33d..fb0dc321f 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -266,35 +266,15 @@ export function mapui(models, config, store, ui) {
}
if (extent) {
const view = map.getView();
+ const rotation = view.getRotation(); // This should be pulled from the permalink now since we removed rotation from the view object.
- const mapRotation = (Math.abs(view.getRotation()) * (180 / Math.PI)).toFixed(4);
-
- // This is where the funny business happens
view.fit(extent, {
constrainResolution: false,
callback,
});
- // view.getZoom() doing this after fit yields a floating zoom level (i.e. -0.2223, 1.8845, etc.)
-
- // console.log(view.getZoom())
-
- /** Originally, I was trying to a find a way to either round up or down the value,
- or truncate it completely based on the rotation value. When you rotate the map, the zoom level will
- either go up or down; it will not be a whole number. */
-
- // let zoom = Math.trunc(view.getZoom());
- // let zoom = Math.floor(view.getZoom());
- // let zoom = Math.ceil(view.getZoom());
-
- if (mapRotation) {
- const zoom = Math.ceil(view.getZoom());
- /** Run the app, and rotate the map using the rotational buttons, reload the page, view should be restored.
- Now rotate the map using the alt + mouse and get a decimal rotation value, (i.e. 137.448), infinte zoom
- should take place. Not all decimal values will cause it to happen. */
- // if (mapRotation >= 29 && mapRotation <= 60) zoom += 1;
- // else if (mapRotation >= 114 && mapRotation < 160) zoom += 1;
- view.setZoom(zoom);
+ if (rotation) {
+ view.setRotation(rotation);
}
}
}
@@ -945,10 +925,6 @@ export function mapui(models, config, store, ui) {
maxResolution: proj.resolutions[0],
projection: olProj.get(proj.crs),
center: proj.startCenter,
- rotation:
- proj.id === 'geographic' || proj.id === 'webmerc'
- ? 0.0
- : models.map.rotation,
zoom: proj.startZoom,
maxZoom: proj.numZoomLevels,
enableRotation: true,
diff --git a/web/js/modules/map/util.js b/web/js/modules/map/util.js
index 5e957a0cc..5c0d9d087 100644
--- a/web/js/modules/map/util.js
+++ b/web/js/modules/map/util.js
@@ -1,4 +1,5 @@
import * as olExtent from 'ol/extent';
+import * as Polygon from 'ol/geom/Polygon';
import {
each as lodashEach,
isUndefined as lodashIsUndefined,
@@ -40,6 +41,13 @@ export function getMapParameterSetup(
},
serialize: (currentItemState, currentState) => {
const rendered = lodashGet(currentState, 'map.rendered');
+ const rotation = lodashGet(currentState, 'map.rotation');
+
+ if (rotation) {
+ const map = currentState.map.ui.selected;
+ currentItemState = getRotatedExtent(map, rotation);
+ }
+
if (!rendered) return undefined;
const actualLeadingExtent = lodashGet(
currentState,
@@ -131,6 +139,18 @@ export function getLeadingExtent(loadtime) {
return [minLon, minLat, maxLon, maxLat];
}
+export function getRotatedExtent(map, rotation) {
+ const view = map.getView();
+ const extent = view.calculateExtent(map.getSize());
+ const geom = Polygon.fromExtent(extent);
+ const mapCenter = view.getCenter();
+ const radians = rotation * (Math.PI / 180);
+
+ geom.rotate(radians, mapCenter);
+
+ return geom.getExtent();
+}
+
/**
* Once a layer's group of layers (prev, current, next day) are fulfilled,
* a promise with an array of their fulfilled values is returned.