Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

move rotation and zoom to components

Jason Kent0509b759c60b
diff --git a/web/js/components/map/rotation.js b/web/js/components/map/rotation.js
new file mode 100644
index 000000000..bffbdcb8e
--- /dev/null
+++ b/web/js/components/map/rotation.js
@@ -0,0 +1,142 @@
+import React from 'react';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { connect } from 'react-redux';
+import { debounce } from 'lodash';
+import PropTypes from 'prop-types';
+import { saveRotation } from '../../map/util';
+
+const duration = 500;
+
+class Rotation extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ intervalId: null,
+ };
+ this.rotateOnClick = this.rotateOnClick.bind(this);
+ this.clearInterval = this.clearInterval.bind(this);
+ this.resetRotation = this.resetRotation.bind(this);
+ }
+
+ componentDidUpdate() {
+ // const { rotatation } = this.props;
+
+ // Clear interval if being reset?
+ }
+
+ clearInterval() {
+ const { intervalId } = this.state;
+ clearInterval(intervalId);
+ }
+
+ /**
+ *
+ * @param {*} radians
+ */
+ rotate(radians) {
+ const { map, updateRotationState } = this.props;
+ const mapView = map.ui.selected.getView();
+ const currentDeg = mapView.getRotation() * (180.0 / Math.PI);
+ saveRotation(currentDeg, mapView);
+ mapView.animate({
+ rotation: mapView.getRotation() - Math.PI / radians,
+ duration,
+ });
+ updateRotationState(radians);
+ }
+
+ /**
+ * @param {*} radians
+ */
+ rotateOnClick = (radians) => {
+ const newIntervalId = setInterval(() => {
+ this.rotate(radians);
+ }, duration);
+ this.rotate(radians);
+ this.setState({ intervalId: newIntervalId });
+ };
+
+ resetRotation() {
+ const { map } = this.props;
+ this.clearInterval();
+ map.ui.selected.getView().animate({
+ duration: 500,
+ rotation: 0,
+ });
+ }
+
+ render() {
+ const { rotation, proj } = this.props;
+ const currentRotation = Number(rotation * (180 / Math.PI)).toFixed();
+
+ return proj.id !== 'geographic' && proj.id !== 'webmerc' && (
+ <>
+ <button
+ type="button"
+ className="wv-map-rotate-left wv-map-zoom ui-button ui-corner-all ui-widget"
+ title="You may also rotate by holding Alt and dragging the mouse"
+ onMouseDown={() => { this.rotateOnClick(10); }}
+ onMouseUp={this.clearInterval}
+ onMouseOut={this.clearInterval}
+ onMouseMove={(e) => { e.stopPropagation(); }}
+ >
+ <FontAwesomeIcon icon="undo" className="cursor-pointer" />
+ </button>
+
+ <button
+ type="button"
+ className="wv-map-reset-rotation wv-map-zoom ui-button ui-corner-all ui-widget"
+ title="Reset rotation"
+ onMouseDown={this.resetRotation}
+ onMouseUp={this.clearInterval}
+ onMouseOut={this.clearInterval}
+ onMouseMove={(e) => { e.stopPropagation(); }}
+ >
+ {currentRotation}
+ </button>
+
+ <button
+ type="button"
+ className="wv-map-rotate-right wv-map-zoom ui-button ui-corner-all ui-widget"
+ title="You may also rotate by holding Alt and dragging the mouse"
+ onMouseDown={() => { this.rotateOnClick(-10); }}
+ onMouseUp={this.clearInterval}
+ onMouseOut={this.clearInterval}
+ onMouseMove={(e) => { e.stopPropagation(); }}
+ >
+ <FontAwesomeIcon icon="redo" className="cursor-pointer" />
+ </button>
+ </>
+ );
+ }
+}
+
+const mapStateToProps = (state) => {
+ const { map, proj } = state;
+ return {
+ map,
+ proj,
+ rotation: map.rotation,
+ };
+};
+
+const mapDispatchToProps = (dispatch) => ({
+ updateRotationState: debounce((radians) => {
+ dispatch({
+ type: 'MAP/UPDATE_ROTATION',
+ rotation: radians,
+ });
+ }, 100),
+});
+
+Rotation.propTypes = {
+ map: PropTypes.object,
+ rotation: PropTypes.number,
+ proj: PropTypes.object,
+ updateRotationState: PropTypes.func,
+};
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps,
+)(Rotation);
diff --git a/web/js/components/map/zoom.js b/web/js/components/map/zoom.js
new file mode 100644
index 000000000..9ee6b456e
--- /dev/null
+++ b/web/js/components/map/zoom.js
@@ -0,0 +1,53 @@
+import React from 'react';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { connect } from 'react-redux';
+import PropTypes from 'prop-types';
+import { mapUtilZoomAction } from '../../map/util';
+
+function Zoom({ map, proj }) {
+ if (!map) return null;
+ const zoomLevel = map.getView().getZoom();
+ const { numZoomLevels } = proj;
+
+ return (
+ <>
+ <button
+ type="button"
+ disabled={zoomLevel === numZoomLevels}
+ className="wv-map-zoom wv-map-zoom-in ui-button ui-corner-all ui-widget"
+ title="Zoom in view."
+ onClick={() => { mapUtilZoomAction(map, 1); }}
+ onMouseMove={(e) => e.stopPropagation()}
+ >
+ <FontAwesomeIcon icon="plus" />
+ </button>
+ <div
+ type="button"
+ disabled={zoomLevel === 0}
+ className="wv-map-zoom wv-map-zoom-out ui-button ui-corner-all ui-widget"
+ title="Zoom out view."
+ onClick={() => { mapUtilZoomAction(map, -1); }}
+ onMouseMove={(e) => e.stopPropagation()}
+ >
+ <FontAwesomeIcon icon="minus" />
+ </div>
+ </>
+ );
+}
+
+const mapStateToProps = (state) => {
+ const { map, proj } = state;
+ return {
+ map: map.ui.selected,
+ proj,
+ };
+};
+
+Zoom.propTypes = {
+ map: PropTypes.object,
+ proj: PropTypes.object,
+};
+
+export default connect(
+ mapStateToProps,
+)(Zoom);
diff --git a/web/js/containers/map-interactions/map-interactions.js b/web/js/containers/map-interactions/map-interactions.js
index 85f25496f..a1aeeb8e7 100644
--- a/web/js/containers/map-interactions/map-interactions.js
+++ b/web/js/containers/map-interactions/map-interactions.js
@@ -5,6 +5,8 @@ import OlCoordinates from '../../components/map/ol-coordinates';
import OlVectorInteractions from './ol-vector-interactions';
import OlMeasureTool from '../../components/map/ol-measure-tool';
import OlCoordinatesMarker from '../../components/geosearch/ol-coordinates-marker';
+import OlRotationButtons from '../../components/map/rotation';
+import OlZoomButtons from '../../components/map/zoom';
class MapInteractions extends PureComponent {
getMapClasses = () => {
@@ -23,6 +25,8 @@ class MapInteractions extends PureComponent {
const mapClasses = this.getMapClasses();
return (
<>
+ <OlZoomButtons />
+ <OlRotationButtons />
<div id="wv-map" className={mapClasses} />
{!isDistractionFreeModeActive && (
<OlCoordinates />
diff --git a/web/js/main.js b/web/js/main.js
index 64965d720..7ed68b88b 100644
--- a/web/js/main.js
+++ b/web/js/main.js
@@ -51,8 +51,14 @@ const compose = DEBUG === false || DEBUG === 'logger'
stateSanitizer: (state) => {
const sanitizedState = {
...state,
+ map: {
+ ...state.map,
+ ui: {
+ ...state.map.ui,
+ },
+ },
};
- delete sanitizedState.map;
+ delete sanitizedState.map.ui;
return sanitizedState;
},
});
diff --git a/web/js/map/rotation.js b/web/js/map/rotation.js
deleted file mode 100644
index 2db5a40fa..000000000
--- a/web/js/map/rotation.js
+++ /dev/null
@@ -1,256 +0,0 @@
-import 'jquery-ui-bundle/jquery-ui';
-import { debounce } from 'lodash';
-import { faIconUndoSVGDomEl, faIconRedoSVGDomEl } from './fa-map-icons';
-
-export default function MapRotate(ui, models, store) {
- this.intervalId = null;
- const self = this;
-
- /*
- * 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}
- */
- this.buildRotationWidget = function(map) {
- const $map = $(`#${map.getTarget()}`);
- const $rotateLeftButton = $('<button></button>')
- .addClass('wv-map-rotate-left wv-map-zoom')
- .attr(
- 'title',
- 'You may also rotate by holding Alt and dragging the mouse',
- );
- const $lefticon = $(faIconUndoSVGDomEl);
-
- const $rotateRightButton = $('<button></button>')
- .addClass('wv-map-rotate-right wv-map-zoom')
- .attr(
- 'title',
- 'You may also rotate by holding Alt and dragging the mouse',
- );
- const $righticon = $(faIconRedoSVGDomEl);
-
- const $resetButton = $('<button></button>')
- .addClass('wv-map-reset-rotation wv-map-zoom')
- .attr('title', 'Click to reset');
-
- $rotateLeftButton.append($lefticon);
- $rotateRightButton.append($righticon);
- $map
- .append($rotateLeftButton)
- .append($resetButton)
- .append($rotateRightButton);
- };
- self.reset = function(map) {
- if (self.intervalId) clearInterval(self.intervalId); // stop repeating rotation on mobile
- map.getView().animate({
- duration: 500,
- rotation: 0,
- });
- self.setResetButton(0);
- };
- /*
- * 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) {
- const mapState = store.getState().map;
- const dur = 500;
- const $leftButton = $(`#wv-map-${id} .wv-map-rotate-left`);
- const $rightButton = $(`#wv-map-${id} .wv-map-rotate-right`);
- const $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(() => {
- self.intervalId = setInterval(() => {
- self.rotate(10, dur, map);
- }, dur);
- self.rotate(10, dur, map);
- })
- .mouseup(() => {
- clearInterval(self.intervalId);
- })
- .mouseout(() => {
- clearInterval(self.intervalId);
- })
- // This component is inside the map viewport container. Allowing
- // mouse move events to bubble up displays map coordinates--let those
- // be blank when over a component.
- .mousemove((e) => e.stopPropagation());
-
- $rightButton
- .button({
- text: false,
- })
- .mousedown(() => {
- self.intervalId = setInterval(() => {
- self.rotate(-10, dur, map);
- }, dur);
- self.rotate(-10, dur, map);
- })
- .mouseup(() => {
- clearInterval(self.intervalId);
- })
- .mouseout(() => {
- clearInterval(self.intervalId);
- })
- // See note above
- .mousemove((e) => e.stopPropagation());
-
- $resetButton
- .button({
- label: Number(mapState.rotation * (180 / Math.PI)).toFixed(),
- })
- .mousedown(() => {
- // reset rotation
- clearInterval(self.intervalId); // stop repeating rotation on mobile
- map.getView().animate({
- duration: 500,
- rotation: 0,
- });
-
- $resetButton.button('option', 'label', '0');
- })
- // See note above
- .mousemove((e) => e.stopPropagation());
- };
-
- /**
- * Saves the rotation degrees as a number within -360 & 360 degrees
- *
- * @param {type} currentDeg The current rotation degrees
- * @param {type} currentView The current rotation view
- * @return {type} Compare the current degrees to 360 degrees minus the new view's degree value.
- * This ensures the maximum degrees never exceeds +/- 360.
- * The current view is then set to this new value.
- */
- this.saveRotation = function(currentDeg, currentView) {
- if (Math.abs(currentDeg) === 360) {
- currentView.setRotation(0);
- } else if (Math.abs(currentDeg) >= 360) {
- const newNadVal = (360 - Math.abs(currentDeg)) * (Math.PI / 180);
- if (currentDeg < 0) {
- currentView.setRotation(newNadVal);
- } else {
- currentView.setRotation(-newNadVal);
- }
- }
- };
- this.dispatchRotation = function(radians) {
- store.dispatch({ type: 'MAP/UPDATE_ROTATION', rotation: radians });
- };
- const debounceRotationDispatcher = debounce(this.dispatchRotation, 100);
- /*
- * Called as event listener when map is rotated. Update url to reflect rotation reset
- *
- * @method updateRotation
- * @static
- *
- * @returns {void}
- */
- this.updateRotation = function() {
- const currentView = ui.selected.getView();
- const radians = currentView.getRotation();
- debounceRotationDispatcher(radians);
- self.setResetButton(radians);
-
- const currentDeg = currentView.getRotation() * (180.0 / Math.PI);
- this.saveRotation(currentDeg, currentView);
- };
-
- /*
- * 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) {
- const button = $('.wv-map-reset-rotation');
- const deg = radians * (180.0 / Math.PI);
- // Set reset button content
- button.button('option', 'label', Number(deg % 360).toFixed());
- switch (true) {
- 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');
- break;
- case deg <= -10.0:
- button.find('span').attr('style', 'padding-left: 10px');
- break;
- default:
- 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}
- */
- this.rotate = function(amount, duration, map) {
- const currentDeg = map.getView().getRotation() * (180.0 / Math.PI);
-
- const currentView = ui.selected.getView();
- this.saveRotation(currentDeg, currentView);
-
- map.getView().animate({
- rotation: map.getView().getRotation() - Math.PI / amount,
- duration,
- });
- };
- this.setRotation = function(val, duration, map) {
- map.getView().animate({
- rotation: val,
- duration,
- });
- };
-}
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index fe41aa451..8c185c541 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -1,4 +1,5 @@
/* eslint-disable no-multi-assign */
+import ReactDOM from 'react-dom';
import {
throttle as lodashThrottle,
forOwn as lodashForOwn,
@@ -9,7 +10,6 @@ import {
cloneDeep as lodashCloneDeep,
find as lodashFind,
} from 'lodash';
-import ReactDOM from 'react-dom';
import OlMap from 'ol/Map';
import OlView from 'ol/View';
import OlKinetic from 'ol/Kinetic';
@@ -26,12 +26,11 @@ import OlLayerGroup from 'ol/layer/Group';
import * as olProj from 'ol/proj';
import { CALCULATE_RESPONSIVE_STATE } from 'redux-responsive';
import Cache from 'cachai';
-import MapRotate from './rotation';
import mapDateLineBuilder from './datelinebuilder';
import mapLayerBuilder from './layerbuilder';
import MapRunningData from './runningdata';
import mapPrecacheTile from './precachetile';
-import { mapUtilZoomAction, getActiveLayerGroup } from './util';
+import { getActiveLayerGroup, saveRotation } from './util';
import mapCompare from './compare/compare';
import { LOCATION_POP_ACTION } from '../redux-location-state-customs';
import { CHANGE_PROJECTION } from '../modules/projection/constants';
@@ -58,26 +57,22 @@ import {
import getSelectedDate from '../modules/date/selectors';
import { EXIT_ANIMATION, STOP_ANIMATION } from '../modules/animation/constants';
import {
- CLEAR_ROTATE, RENDERED, UPDATE_MAP_UI, FITTED_TO_LEADING_EXTENT, REFRESH_ROTATE,
+ RENDERED, UPDATE_MAP_UI, UPDATE_MAP_EXTENT, UPDATE_MAP_ROTATION, FITTED_TO_LEADING_EXTENT, REFRESH_ROTATE, CLEAR_ROTATE,
} from '../modules/map/constants';
import { getLeadingExtent } from '../modules/map/util';
import { updateVectorSelection } from '../modules/vector-styles/util';
-import { faIconPlusSVGDomEl, faIconMinusSVGDomEl } from './fa-map-icons';
import { hasVectorLayers } from '../modules/layers/util';
import { animateCoordinates, getCoordinatesMarker } from '../modules/geosearch/util';
import { reverseGeocode } from '../modules/geosearch/util-api';
import { getCoordinatesMetadata, renderCoordinatesDialog } from '../components/geosearch/ol-coordinates-marker-util';
-const { events } = util;
+const { events } = util;
export default function mapui(models, config, store, ui) {
- const id = 'wv-map';
- const selector = `#${id}`;
const animationDuration = 250;
const self = {};
let cache;
- const rotation = new MapRotate(self, models, store);
const dateline = mapDateLineBuilder(models, config, store, ui);
const precache = mapPrecacheTile(models, config, cache, self);
const compareMapUi = mapCompare(config, store);
@@ -129,10 +124,20 @@ export default function mapui(models, config, store, ui) {
}
return;
}
- case CLEAR_ROTATE:
- return rotation.reset(self.selected);
- case REFRESH_ROTATE:
- return rotation.setRotation(action.rotation, 500, self.selected);
+ case CLEAR_ROTATE: {
+ self.selected.getView().animate({
+ duration: 500,
+ rotation: 0,
+ });
+ return;
+ }
+ case REFRESH_ROTATE: {
+ self.selected.getView().animate({
+ rotation: action.rotation,
+ duration: 500,
+ });
+ return;
+ }
case LOCATION_POP_ACTION: {
const newState = util.fromQueryString(action.payload.search);
const extent = lodashGet(action, 'payload.query.map.extent');
@@ -202,6 +207,7 @@ export default function mapui(models, config, store, ui) {
reloadLayers();
}
};
+
/*
* Sets up map listeners
*
@@ -430,22 +436,18 @@ export default function mapui(models, config, store, ui) {
const currentRotation = isProjectionRotatable ? map.getView().getRotation() : 0;
const rotationStart = isProjectionRotatable ? models.map.rotation : 0;
- store.dispatch({ type: UPDATE_MAP_UI, ui: self, rotation: start ? rotationStart : currentRotation });
+ store.dispatch({
+ type: UPDATE_MAP_UI,
+ ui: self,
+ rotation: start ? rotationStart : currentRotation,
+ });
reloadLayers();
- // Update the rotation buttons if polar projection to display correct value
- if (isProjectionRotatable) {
- rotation.setResetButton(currentRotation);
- }
-
// If the browser was resized, the inactive map was not notified of
// the event. Force the update no matter what and reposition the center
// using the previous value.
showMap(map);
map.updateSize();
- if (isProjectionRotatable) {
- rotation.setResetButton(currentRotation);
- }
if (self.selected.previousCenter) {
self.selected.setCenter(self.selected.previousCenter);
@@ -470,7 +472,6 @@ export default function mapui(models, config, store, ui) {
callback = () => {
const map = self.selected;
const view = map.getView();
- rotation.setResetButton(rotationStart);
view.setRotation(rotationStart);
};
}
@@ -487,6 +488,7 @@ export default function mapui(models, config, store, ui) {
onResize();
handleActiveMapMarker(start);
}
+
/*
* When page is resised set for mobile or desktop
*
@@ -504,11 +506,9 @@ export default function mapui(models, config, store, ui) {
if (isMobile) {
map.removeControl(map.wv.scaleImperial);
map.removeControl(map.wv.scaleMetric);
- $(`#${map.getTarget()} .select-wrapper`).hide();
} else {
map.addControl(map.wv.scaleImperial);
map.addControl(map.wv.scaleMetric);
- $(`#${map.getTarget()} .select-wrapper`).show();
}
}
/*
@@ -522,7 +522,7 @@ export default function mapui(models, config, store, ui) {
* @returns {void}
*/
function hideMap(map) {
- $(`#${map.getTarget()}`).hide();
+ document.getElementById(`${map.getTarget()}`).style.display = 'none';
}
/*
* Show Map
@@ -535,7 +535,7 @@ export default function mapui(models, config, store, ui) {
* @returns {void}
*/
function showMap(map) {
- $(`#${map.getTarget()}`).show();
+ document.getElementById(`${map.getTarget()}`).style.display = 'block';
}
/*
* Remove Layers from map
@@ -895,51 +895,35 @@ export default function mapui(models, config, store, ui) {
return index;
}
- const triggerExtent = lodashThrottle(
- () => events.trigger('map:extent'),
- 500,
- { trailing: true },
- );
-
- /*
- * Updates the extents of OpenLayers map
- *
- *
- * @method updateExtent
- * @static
- *
- * @returns {void}
- */
- function updateExtent() {
- const map = self.selected;
- const view = map.getView();
- const extent = view.calculateExtent(map.getSize());
- store.dispatch({ type: 'MAP/UPDATE_MAP_EXTENT', extent });
- triggerExtent();
- }
+ const updateExtent = () => {
+ const view = self.selected.getView();
+ const extent = view.calculateExtent(self.selected.getSize());
+ store.dispatch({ type: UPDATE_MAP_EXTENT, extent });
+ lodashThrottle(
+ () => events.trigger('map:extent'),
+ 500,
+ { trailing: true },
+ )();
+ };
/*
- * Updates the extents of OpenLayers map
- *
- *
- * @method updateExtent
- * @static
+ * Create a map for a given projection
*
* @param {object} proj - Projection properties
*
- *
* @returns {object} OpenLayers Map Object
*/
function createMap(proj, dateSelected) {
const state = store.getState();
dateSelected = dateSelected || getSelectedDate(state);
const id = `wv-map-${proj.id}`;
- const $map = $('<div></div>')
- .attr('id', id)
- .attr('data-proj', proj.id)
- .addClass('wv-map')
- .hide();
- $(selector).append($map);
+ const mapEl = document.createElement('div');
+ mapEl.setAttribute('id', id);
+ mapEl.setAttribute('data-proj', proj.id);
+ mapEl.classList.add('wv-map');
+ mapEl.style.display = 'none';
+
+ document.getElementById('wv-map').insertAdjacentElement('afterbegin', mapEl);
// Create two specific controls
const scaleMetric = new OlControlScaleLine({
@@ -994,28 +978,41 @@ export default function mapui(models, config, store, ui) {
scaleImperial,
};
map.proj = proj.id;
- createZoomButtons(map, proj);
createMousePosSel(map, proj);
+ map.getView().on('change:resolution', () => {
+ events.trigger('map:movestart');
+ });
// This component is inside the map viewport container. Allowing
// mouse move events to bubble up displays map coordinates--let those
// be blank when over a component.
- $('.wv-map-scale-metric').mousemove((e) => e.stopPropagation());
- $('.wv-map-scale-imperial').mousemove((e) => e.stopPropagation());
+ document.querySelector('.wv-map-scale-metric').addEventListener('mousemove', (e) => e.stopPropagation());
+ document.querySelector('.wv-map-scale-imperial').addEventListener('mousemove', (e) => e.stopPropagation());
- // allow rotation by dragging for polar projections
+ // Allow rotation by dragging for polar projections
if (proj.id !== 'geographic' && proj.id !== 'webmerc') {
- rotation.init(map, proj.id);
map.addInteraction(rotateInteraction);
map.addInteraction(mobileRotation);
} else if (proj.id === 'geographic') {
dateline.init(self, map, dateSelected);
}
+ const onRotate = () => {
+ const radians = map.getView().getRotation();
+ store.dispatch({
+ type: UPDATE_MAP_ROTATION,
+ rotation: radians,
+ });
+ const currentDeg = radians * (180.0 / Math.PI);
+ saveRotation(currentDeg, map.getView());
+ updateExtent();
+ };
+
// Set event listeners for changes on the map view (when rotated, zoomed, panned)
map.getView().on('change:center', lodashDebounce(updateExtent, 300));
map.getView().on('change:resolution', lodashDebounce(updateExtent, 300));
map.getView().on('change:rotation', lodashThrottle(onRotate, 300));
+
map.on('pointerdrag', () => {
self.mapIsbeingDragged = true;
events.trigger('map:drag');
@@ -1039,7 +1036,11 @@ export default function mapui(models, config, store, ui) {
});
const onRenderComplete = () => {
store.dispatch({ type: RENDERED });
- store.dispatch({ type: UPDATE_MAP_UI, ui: self, rotation: self.selected.getView().getRotation() });
+ store.dispatch({
+ type: UPDATE_MAP_UI,
+ ui: self,
+ rotation: self.selected.getView().getRotation(),
+ });
map.un('rendercomplete', onRenderComplete);
};
map.on('rendercomplete', onRenderComplete);
@@ -1049,101 +1050,7 @@ export default function mapui(models, config, store, ui) {
return map;
}
- /*
- * Creates map zoom buttons
- *
- *
- * @method createZoomButtons
- * @static
- *
- * @param {object} map - OpenLayers Map Object
- *
- * @param {object} proj - Projection properties
- *
- *
- * @returns {void}
- */
- function createZoomButtons(map, proj) {
- const $map = $(`#${map.getTarget()}`);
-
- const $zoomOut = $('<div></div>')
- .addClass('wv-map-zoom-out')
- .addClass('wv-map-zoom')
- .attr(
- 'title',
- 'Zoom out map view',
- );
- const $outIcon = $(faIconMinusSVGDomEl);
- $zoomOut.append($outIcon);
- $map.append($zoomOut);
- $zoomOut.button({
- text: false,
- });
- $zoomOut.click(() => {
- mapUtilZoomAction(map, -1);
- });
- $zoomOut.mousemove((e) => e.stopPropagation());
- const $zoomIn = $('<div></div>')
- .addClass('wv-map-zoom-in')
- .addClass('wv-map-zoom')
- .attr(
- 'title',
- 'Zoom in map view',
- );
- const $inIcon = $(faIconPlusSVGDomEl);
- $zoomIn.append($inIcon);
- $map.append($zoomIn);
- $zoomIn.button({
- text: false,
- });
- $zoomIn.click(() => {
- mapUtilZoomAction(map, 1);
- });
- $zoomIn.mousemove((e) => e.stopPropagation());
-
- /*
- * Sets zoom buttons as active or inactive based
- * on the zoom level
- *
- * @funct onZoomChange
- * @static
- *
- * @returns {void}
- *
- */
- const onZoomChange = function() {
- const { numZoomLevels } = proj;
- const zoom = map.getView().getZoom();
- if (zoom === 0) {
- $zoomIn.button('enable');
- $zoomOut.button('disable');
- } else if (zoom === numZoomLevels) {
- $zoomIn.button('disable');
- $zoomOut.button('enable');
- } else {
- $zoomIn.button('enable');
- $zoomOut.button('enable');
- }
- };
- map.getView().on('change:resolution', () => {
- onZoomChange();
- events.trigger('map:movestart');
- });
- onZoomChange();
- }
- /*
- * @method onRotate
- * @static
- *
- * @param {Object} val "change:rotation" Object
- *
- * @returns {void}
- */
- function onRotate(val) {
- rotation.updateRotation(val);
- updateExtent();
- }
/*
* Creates map events based on mouse position
*
diff --git a/web/js/map/util.js b/web/js/map/util.js
index 5028241fe..3bf10188c 100644
--- a/web/js/map/util.js
+++ b/web/js/map/util.js
@@ -113,3 +113,21 @@ export function mergeBreakpointLayerAttributes(def, projId) {
return { ...def, breakPointLayer: updatedBreakPointLayer };
} return def;
}
+
+/**
+ *
+ * @param {*} currentDeg
+ * @param {*} currentView
+ */
+export function saveRotation(currentDeg, currentView) {
+ if (Math.abs(currentDeg) === 360) {
+ currentView.setRotation(0);
+ } else if (Math.abs(currentDeg) >= 360) {
+ const newNadVal = (360 - Math.abs(currentDeg)) * (Math.PI / 180);
+ if (currentDeg < 0) {
+ currentView.setRotation(newNadVal);
+ } else {
+ currentView.setRotation(-newNadVal);
+ }
+ }
+}