Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Keep permalink clean until change #1817

Benjamin Kingf16b9a51b683
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 4187f83c9..35323cbde 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -48,7 +48,7 @@ import {
cloneDeep as lodashCloneDeep,
find as lodashFind
} from 'lodash';
-import { CLEAR_ROTATE } from '../modules/map/constants';
+import { CLEAR_ROTATE, RENDERED, UPDATE_MAP_UI, FITTED_TO_LEADING_EXTENT } from '../modules/map/constants';
import { getLeadingExtent } from '../modules/map/util';
export function mapui(models, config, store, ui) {
@@ -187,7 +187,7 @@ export function mapui(models, config, store, ui) {
self.selected = self.proj[proj.id];
var map = self.selected;
let currentRotation = proj.id !== 'geographic' && proj.id !== 'webmerc' ? map.getView().getRotation() : 0;
- store.dispatch({ type: 'MAP/UPDATE_MAP_UI', ui: self, rotation: currentRotation });
+ store.dispatch({ type: UPDATE_MAP_UI, ui: self, rotation: currentRotation });
reloadLayers();
// Update the rotation buttons if polar projection to display correct value
@@ -209,14 +209,22 @@ export function mapui(models, config, store, ui) {
if (start) {
var projId = proj.selected.id;
var extent = null;
+ var callback = null;
if (models.map.extent) {
extent = models.map.extent;
} else if (!models.map.extent && projId === 'geographic') {
extent = getLeadingExtent(config.pageLoadTime);
+ callback = () => {
+ const map = self.selected;
+ const view = map.getView();
+ const extent = view.calculateExtent(map.getSize());
+ store.dispatch({ type: FITTED_TO_LEADING_EXTENT, extent });
+ };
}
if (extent) {
map.getView().fit(extent, {
- constrainResolution: false
+ constrainResolution: false,
+ callback
});
}
}
@@ -914,7 +922,8 @@ export function mapui(models, config, store, ui) {
}, 200);
});
const onRenderComplete = () => {
- store.dispatch({ type: 'MAP/UPDATE_MAP_UI', ui: self, rotation: self.selected.getView().getRotation() });
+ store.dispatch({ type: RENDERED });
+ store.dispatch({ type: UPDATE_MAP_UI, ui: self, rotation: self.selected.getView().getRotation() });
map.un('rendercomplete', onRenderComplete);
if (store.getState().data.active) ui.data.onActivate();
};
diff --git a/web/js/modules/map/constants.js b/web/js/modules/map/constants.js
index d60ef32e8..3dd15f419 100644
--- a/web/js/modules/map/constants.js
+++ b/web/js/modules/map/constants.js
@@ -4,3 +4,5 @@ export const CLEAR_ROTATE = 'MAP/CLEAR_ROTATE';
export const UPDATE_MAP_EXTENT = 'MAP/UPDATE_MAP_EXTENT';
export const UPDATE_MAP_UI = 'MAP/UPDATE_MAP_UI';
export const UPDATE_MAP_ROTATION = 'MAP/UPDATE_ROTATION';
+export const RENDERED = 'MAP/RENDERED';
+export const FITTED_TO_LEADING_EXTENT = 'MAP/FITTED_TO_LEADING_EXTENT';
diff --git a/web/js/modules/map/reducers.js b/web/js/modules/map/reducers.js
index 9b05d989f..440f552d4 100644
--- a/web/js/modules/map/reducers.js
+++ b/web/js/modules/map/reducers.js
@@ -4,14 +4,18 @@ import {
CLEAR_RUNNING_DATA,
UPDATE_MAP_EXTENT,
UPDATE_MAP_UI,
- UPDATE_MAP_ROTATION
+ UPDATE_MAP_ROTATION,
+ RENDERED,
+ FITTED_TO_LEADING_EXTENT
} from './constants';
import update from 'immutability-helper';
const INITIAL_STATE = {
runningDataObj: {},
ui: { selected: null },
rotation: 0,
- extent: []
+ extent: [],
+ rendered: false,
+ leadingExtent: []
};
export default function mapReducer(state = INITIAL_STATE, action) {
@@ -33,6 +37,14 @@ export default function mapReducer(state = INITIAL_STATE, action) {
});
case UPDATE_MAP_ROTATION:
return update(state, { rotation: { $set: action.rotation } });
+ case RENDERED:
+ return lodashAssign({}, state, {
+ rendered: true
+ });
+ case FITTED_TO_LEADING_EXTENT:
+ return lodashAssign({}, state, {
+ leadingExtent: action.extent
+ });
default:
return state;
}
diff --git a/web/js/modules/map/util.js b/web/js/modules/map/util.js
index d4548cc40..0038d62f4 100644
--- a/web/js/modules/map/util.js
+++ b/web/js/modules/map/util.js
@@ -3,7 +3,9 @@ import * as olExtent from 'ol/extent';
import {
each as lodashEach,
isUndefined as lodashIsUndefined,
- map as lodashMap
+ map as lodashMap,
+ get as lodashGet,
+ isEqual as lodashIsEqual
} from 'lodash';
import OlRendererCanvasTileLayer from 'ol/renderer/canvas/TileLayer';
import Promise from 'bluebird';
@@ -23,6 +25,7 @@ export function getMapParameterSetup(
type: 'array',
options: {
delimiter: ',',
+ serializeNeedsGlobalState: true,
parse: state => {
var extent = lodashMap(state.split(','), function(str) {
return parseFloat(str);
@@ -38,9 +41,16 @@ export function getMapParameterSetup(
}
},
serialize: (currentItemState, currentState) => {
+ const rendered = lodashGet(currentState, 'map.rendered');
+ if (!rendered) return undefined;
+ const actualLeadingExtent = lodashGet(
+ currentState,
+ 'map.leadingExtent'
+ );
const extent = mapIsExtentValid(currentItemState)
? currentItemState
: leadingExtent;
+ if (lodashIsEqual(actualLeadingExtent, extent)) return undefined;
return encode(extent);
}
}