Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Show Cursor change on clickable points #2144

Benjamin King59c613263ee0
diff --git a/web/css/util.css b/web/css/util.css
index efbbc167e..54e57a24a 100644
--- a/web/css/util.css
+++ b/web/css/util.css
@@ -208,3 +208,6 @@ button[data-tooltip] {
display: table;
clear: both;
}
+.cursor-pointer {
+ cursor: pointer;
+}
\ No newline at end of file
diff --git a/web/js/app.js b/web/js/app.js
index 56155c5f0..81c7d6a7a 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -101,7 +101,9 @@ class App extends React.Component {
}
render() {
- const { isAnimationWidgetActive, isTourActive, locationKey } = this.props;
+ const { isAnimationWidgetActive, isTourActive, locationKey, mapIsClickable } = this.props;
+ const mapClasses = mapIsClickable ? 'wv-map' + ' cursor-pointer' : 'wv-map';
+
return (
<div className="wv-content" id="wv-content" data-role="content">
<Toolbar />
@@ -112,7 +114,7 @@ class App extends React.Component {
{isTourActive ? <Tour /> : null}
<div id="layer-modal" className="layer-modal" />
<div id="layer-settings-modal" />
- <div id="wv-map" className="wv-map" />
+ <div id="wv-map" className={mapClasses} />
<div id="eventsHolder" />
<div id="imagedownload" />
<div id="dlMap" />
@@ -182,7 +184,8 @@ function mapStateToProps(state, ownProps) {
parameters: state.parameters,
models: ownProps.models,
mapMouseEvents: ownProps.mapMouseEvents,
- locationKey: state.location.key
+ locationKey: state.location.key,
+ mapIsClickable: state.map.isClickable
};
}
const mapDispatchToProps = dispatch => ({
diff --git a/web/js/combine-ui.js b/web/js/combine-ui.js
index e1b0a9f45..f94c76406 100644
--- a/web/js/combine-ui.js
+++ b/web/js/combine-ui.js
@@ -64,5 +64,8 @@ function registerMapMouseHandlers(maps, events) {
element.addEventListener('mouseout', event => {
events.trigger('mouseout', event, map, crs);
});
+ element.addEventListener('click', event => {
+ events.trigger('click', event, map, crs);
+ });
});
}
diff --git a/web/js/components/map/ol-coordinates.js b/web/js/components/map/ol-coordinates.js
index 1a1b97732..641b12a7b 100644
--- a/web/js/components/map/ol-coordinates.js
+++ b/web/js/components/map/ol-coordinates.js
@@ -3,6 +3,14 @@ import PropTypes from 'prop-types';
import Coordinates from './coordinates';
import util from '../../util/util';
import { transform } from 'ol/proj';
+import vectorDialog from '../../containers/vector-dialog';
+import { onMapClickGetVectorFeatures } from '../../modules/vector-styles/util';
+import { openCustomContent } from '../../modules/modal/actions';
+import { selectVectorFeatures } from '../../modules/vector-styles/actions';
+import { connect } from 'react-redux';
+import { groupBy as lodashGroupBy } from 'lodash';
+import { changeCursor } from '../../modules/map/actions';
+
class OlCoordinates extends React.Component {
constructor(props) {
@@ -17,21 +25,45 @@ class OlCoordinates extends React.Component {
this.mouseMove = this.mouseMove.bind(this);
this.mouseOut = this.mouseOut.bind(this);
this.changeFormat = this.changeFormat.bind(this);
+ this.mouseClick = this.mouseClick.bind(this);
this.registerMouseListeners();
}
registerMouseListeners() {
this.props.mouseEvents.on('mousemove', this.mouseMove);
this.props.mouseEvents.on('mouseout', this.mouseOut);
+ this.props.mouseEvents.on('click', this.mouseClick);
+ }
+
+ mouseClick(e, map) {
+ const pixels = map.getEventPixel(e)
+ const { lastSelection, openVectorDiaglog, selectVectorFeatures, modalStateId, getDialogObject } = this.props;
+ const clickObj = getDialogObject(pixels, map);
+ const metaArray = clickObj.metaArray;
+ const selected = clickObj.selected;
+ const dialogId = 'vector_dialog' + pixels[0] + pixels[1];
+ if (metaArray.length) {
+ openVectorDiaglog(dialogId, metaArray);
+ }
+ if (Object.entries(selected).length || (Object.entries(lastSelection).length && !(modalStateId.includes('vector_dialog') && modalState.isOpen))) {
+ selectVectorFeatures(selected);
+ }
}
mouseMove(event, map, crs) {
const pixels = map.getEventPixel(event);
const coord = map.getCoordinateFromPixel(pixels);
+ const { isShowingClick, changeCursor } = this.props;
if (!coord) {
this.clearCoord();
return;
}
+ const hasFeatures = map.hasFeatureAtPixel(pixels);
+ if (hasFeatures && !isShowingClick) {
+ changeCursor(true);
+ } else if (!hasFeatures && isShowingClick) {
+ changeCursor(false);
+ }
const pcoord = transform(coord, crs, 'EPSG:4326');
const [lon, lat] = pcoord;
@@ -89,9 +121,48 @@ class OlCoordinates extends React.Component {
);
}
}
+const mapDispatchToProps = dispatch => ({
+ selectVectorFeatures: (features) => {
+ dispatch(selectVectorFeatures(features));
+ },
+ changeCursor: (bool) => {
+ dispatch(changeCursor(bool))
+ },
+ openVectorDiaglog: (dialogId, metaArray) => {
+ dispatch(openCustomContent(dialogId,
+ {
+ backdrop: false,
+ clickableBehindModal: true,
+ desktopOnly: true,
+ isDraggable: true,
+ wrapClassName: 'vector-modal-wrap',
+ modalClassName: 'vector-modal light',
+ CompletelyCustomModal: vectorDialog,
+ isDraggable: true,
+ isResizable: true,
+ vectorMetaObject: lodashGroupBy(metaArray, 'id'),
+ width: 500,
+ height: 300,
+ onClose: () => {
+ dispatch(selectVectorFeatures({}));
+ }
+ }
+ ));
+ }
+});
+function mapStateToProps(state) {
+ return {
+ modalStateId: state.modal.id,
+ isShowingClick: state.map.isClickable,
+ getDialogObject: (pixels, map) => { return onMapClickGetVectorFeatures(pixels, map, state); },
+ lastSelected: state.vectorStyles.selected
+ };
+}
OlCoordinates.propTypes = {
mouseEvents: PropTypes.object.isRequired
};
-
-export default OlCoordinates;
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(OlCoordinates);
diff --git a/web/js/components/vector-metadata/table.js b/web/js/components/vector-metadata/table.js
index 1a5c9d7df..25bff5e37 100644
--- a/web/js/components/vector-metadata/table.js
+++ b/web/js/components/vector-metadata/table.js
@@ -8,9 +8,10 @@ export default class VectorMetaTable extends React.Component {
constructor(props) {
super(props);
this.state = {
- tooltipOpen: false,
+ tooltipOpen: false
};
}
+
shouldComponentUpdate(nextProps) {
if (this.props.title && nextProps.title && this.props.title === nextProps.title) {
return false;
@@ -18,6 +19,7 @@ export default class VectorMetaTable extends React.Component {
return true;
}
}
+
render() {
const { metaArray } = this.props;
@@ -26,7 +28,7 @@ export default class VectorMetaTable extends React.Component {
{metaArray.map((obj, metaIndex) => {
const metaFeatures = obj.features;
const metaLegend = obj.legend;
- const title = obj.featureTitle
+ const title = obj.featureTitle;
return (
<div key={util.encodeId(title + '_' + metaIndex)}>
<Table size="sm">
@@ -57,15 +59,15 @@ export default class VectorMetaTable extends React.Component {
</td>
</tr>
- )
+ );
})}
</tbody>
</Table>
</div>
- )
+ );
})
}
- </div>)
+ </div>);
}
}
VectorMetaTable.propTypes = {
diff --git a/web/js/containers/modal.js b/web/js/containers/modal.js
index 728512b06..8d09948b9 100644
--- a/web/js/containers/modal.js
+++ b/web/js/containers/modal.js
@@ -11,12 +11,11 @@ import Draggable from 'react-draggable';
import { ResizableBox, Resizable } from 'react-resizable';
const InteractionWrap = ({ condition, wrapper, children }) => condition ? wrapper(children) : children;
const toggleWithClose = (onToggle, onClose, isOpen) => {
-
if (onClose && isOpen) {
return () => {
onToggle();
onClose();
- }
+ };
} else {
return onToggle;
}
@@ -31,6 +30,7 @@ class ModalContainer extends Component {
};
this.onResize = this.onResize.bind(this);
}
+
getStyle(state, props) {
const isResizable = props.isResizable;
return {
@@ -41,25 +41,28 @@ class ModalContainer extends Component {
height: isResizable ? state.height : props.height
};
}
+
onResize(e, { size }) {
e.stopPropagation();
this.setState({
width: size.width, height: size.height
});
}
+
getTemplateBody() {
const { bodyTemplate } = this.props;
return bodyTemplate.isLoading ? (
<span> Loading </span>
) : (
- <div
- id="template-content"
- dangerouslySetInnerHTML={{ __html: bodyTemplate.response }}
- />
- );
+ <div
+ id="template-content"
+ dangerouslySetInnerHTML={{ __html: bodyTemplate.response }}
+ />
+ );
}
+
setDimensions(updatedState) {
- this.setState(updatedState)
+ this.setState(updatedState);
}
render() {
diff --git a/web/js/containers/vector-dialog.js b/web/js/containers/vector-dialog.js
index f6a220ad0..8c68a4344 100644
--- a/web/js/containers/vector-dialog.js
+++ b/web/js/containers/vector-dialog.js
@@ -12,6 +12,7 @@ class VectorDialog extends React.Component {
this.state = { activeIndex: 0 };
this.updateIndex = this.updateIndex.bind(this);
}
+
updateIndex(activeIndex) {
if (activeIndex === this.state.activeIndex) return;
this.setState({ activeIndex });
@@ -20,10 +21,10 @@ class VectorDialog extends React.Component {
render() {
const { toggleWithClose, vectorMetaObject, height } = this.props;
const { activeIndex } = this.state;
- let navArray = [];
- let keyArray = [];
+ const navArray = [];
+ const keyArray = [];
let i = 0;
- for (let [key, value] of Object.entries(vectorMetaObject)) {
+ for (const [key, value] of Object.entries(vectorMetaObject)) {
const stringLength = 20;
const title = (value[0].title || key);
const titleText = title.length > stringLength ? title.substring(0, stringLength) + '...' : title;
@@ -39,7 +40,7 @@ class VectorDialog extends React.Component {
{titleText + ' [' + (value.length) + ']'}
</NavLink>
</NavItem>
- )
+ );
i++;
}
const activeMetaArray = vectorMetaObject[keyArray[activeIndex]];
@@ -58,19 +59,18 @@ class VectorDialog extends React.Component {
</ Scrollbars>
</ModalBody>
</div>
- )
+ );
}
}
-
function mapStateToProps(state) {
- return {}
+ return {};
};
export default connect(
mapStateToProps,
null
)(VectorDialog);
VectorDialog.propTypes = {
- vectorMetaArray: PropTypes.Array,
- toggleWithClose: PropTypes.func
+ toggleWithClose: PropTypes.func,
+ vectorMetaArray: PropTypes.Array
};
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index e6148b03e..56fd4c63d 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -1,4 +1,10 @@
-import { groupBy, orderBy as lodashOrderBy, throttle as lodashThrottle, forOwn as lodashForOwn, each as lodashEach, findIndex as lodashFindIndex } from 'lodash';
+import {
+ groupBy, orderBy as lodashOrderBy, throttle as lodashThrottle, forOwn as lodashForOwn, each as lodashEach, findIndex as lodashFindIndex,
+ get as lodashGet,
+ debounce as lodashDebounce,
+ cloneDeep as lodashCloneDeep,
+ find as lodashFind
+} from 'lodash';
import util from '../util/util';
import OlMap from 'ol/Map';
import OlView from 'ol/View';
@@ -41,12 +47,7 @@ import {
isRenderable as isRenderableLayer
} from '../modules/layers/selectors';
import { datesinDateRanges } from '../modules/layers/util';
-import {
- get as lodashGet,
- debounce as lodashDebounce,
- cloneDeep as lodashCloneDeep,
- find as lodashFind
-} from 'lodash';
+
import { CLEAR_ROTATE, RENDERED, UPDATE_MAP_UI, FITTED_TO_LEADING_EXTENT } from '../modules/map/constants';
import { getLeadingExtent } from '../modules/map/util';
import vectorDialog from '../containers/vector-dialog';
@@ -94,7 +95,7 @@ export function mapui(models, config, store, ui) {
* Suscribe to redux store and listen for
* specific action types
*/
- const subscribeToStore = function (action) {
+ const subscribeToStore = function(action) {
switch (action.type) {
case layerConstants.ADD_LAYER: {
const def = lodashFind(action.layers, { id: action.id });
@@ -141,10 +142,10 @@ export function mapui(models, config, store, ui) {
return onResize();
case vectorStyleConstants.SET_SELECTED_VECTORS:
const type = 'selection';
- let newSelection = action.payload;
- let state = store.getState();
- let { compare, layers } = state;
- let activeLayerStr = compare.activeString;
+ const newSelection = action.payload;
+ const state = store.getState();
+ const { compare, layers } = state;
+ const activeLayerStr = compare.activeString;
updateVectorSelection(action.payload, self.selectedVectors, layers[activeLayerStr], type, state);
self.selectedVectors = newSelection;
return;
@@ -165,10 +166,10 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var init = function () {
+ var init = function() {
// NOTE: iOS sometimes bombs if this is _.each instead. In that case,
// it is possible that config.projections somehow becomes array-like.
- lodashForOwn(config.projections, function (proj) {
+ lodashForOwn(config.projections, function(proj) {
var map = createMap(proj);
self.proj[proj.id] = map;
});
@@ -186,7 +187,7 @@ export function mapui(models, config, store, ui) {
updateProjection(true);
};
- const flyToNewExtent = function (extent, rotation) {
+ const flyToNewExtent = function(extent, rotation) {
const coordinateX = extent[0] + (extent[2] - extent[0]) / 2;
const coordinateY = extent[1] + (extent[3] - extent[1]) / 2;
const coordinates = [coordinateX, coordinateY];
@@ -207,7 +208,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var updateProjection = function (start) {
+ var updateProjection = function(start) {
const state = store.getState();
const { proj } = state;
if (self.selected) {
@@ -270,7 +271,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var onResize = function () {
+ var onResize = function() {
var map = self.selected;
if (map.small !== util.browser.small) {
if (util.browser.small) {
@@ -294,7 +295,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var hideMap = function (map) {
+ var hideMap = function(map) {
$('#' + map.getTarget()).hide();
};
/*
@@ -307,7 +308,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var showMap = function (map) {
+ var showMap = function(map) {
$('#' + map.getTarget()).show();
};
/*
@@ -320,12 +321,12 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var clearLayers = function (map) {
+ var clearLayers = function(map) {
var activeLayers = map
.getLayers()
.getArray()
.slice(0);
- lodashEach(activeLayers, function (mapLayer) {
+ lodashEach(activeLayers, function(mapLayer) {
map.removeLayer(mapLayer);
});
removeGraticule('active');
@@ -343,7 +344,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var reloadLayers = self.reloadLayers = function (map) {
+ var reloadLayers = self.reloadLayers = function(map) {
map = map || self.selected;
const state = store.getState();
const { layers, proj } = state;
@@ -362,7 +363,7 @@ export function mapui(models, config, store, ui) {
},
state
);
- lodashEach(defs, function (def) {
+ lodashEach(defs, function(def) {
if (isGraticule(def, proj.id)) {
addGraticule(def.opacity, layerGroupStr);
} else {
@@ -390,7 +391,7 @@ export function mapui(models, config, store, ui) {
* Create a Layergroup given the date and layerGroups
* @param {Array} arr | Array of date/layer group strings
*/
- var getCompareLayerGroup = function (arr, layersState, projId, state) {
+ var getCompareLayerGroup = function(arr, layersState, projId, state) {
return new OlLayerGroup({
layers: getLayers(
layersState[arr[0]],
@@ -423,15 +424,15 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var updateLayerVisibilities = function () {
+ var updateLayerVisibilities = function() {
const state = store.getState();
var renderable;
var layers = self.selected.getLayers();
var layersState = state.layers;
var activeGroupStr = state.compare.activeString;
var activeDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';
- var updateGraticules = function (defs, groupName) {
- lodashEach(defs, function (def) {
+ var updateGraticules = function(defs, groupName) {
+ lodashEach(defs, function(def) {
if (isGraticule(def, state.proj.id)) {
renderable = isRenderableLayer(
def.id,
@@ -447,7 +448,7 @@ export function mapui(models, config, store, ui) {
}
});
};
- layers.forEach(function (layer) {
+ layers.forEach(function(layer) {
var group = layer.get('group');
// Not in A|B
if (layer.wv) {
@@ -491,7 +492,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var updateOpacity = function (action) {
+ var updateOpacity = function(action) {
const state = store.getState();
const { layers, compare, proj } = state;
const activeStr = compare.isCompareA ? 'active' : 'activeB';
@@ -520,7 +521,7 @@ export function mapui(models, config, store, ui) {
* @returns {void}
*/
- var addLayer = function (def, date, activeLayers) {
+ var addLayer = function(def, date, activeLayers) {
const state = store.getState();
const { compare, layers, proj } = state;
const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';
@@ -568,7 +569,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var removeLayer = function (action) {
+ var removeLayer = function(action) {
const state = store.getState();
const { compare, proj } = state;
const activeLayerStr = compare.isCompareA ? 'active' : 'activeB';
@@ -597,7 +598,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var updateDate = self.updateDate = function () {
+ var updateDate = self.updateDate = function() {
const state = store.getState();
const { compare } = state;
const layerState = state.layers;
@@ -621,7 +622,7 @@ export function mapui(models, config, store, ui) {
: null;
}
}
- lodashEach(activeLayers, function (def) {
+ lodashEach(activeLayers, function(def) {
const layerName = def.layer || def.id;
if (!['subdaily', 'daily', 'monthly', 'yearly'].includes(def.period)) {
@@ -674,7 +675,7 @@ export function mapui(models, config, store, ui) {
*
* @todo Check if this function can be combined with updateLayerOrder
*/
- var updateLookup = function (layerId) {
+ var updateLookup = function(layerId) {
reloadLayers();
};
@@ -689,7 +690,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {object} Layer object
*/
- var findLayer = function (def, layerGroupStr) {
+ var findLayer = function(def, layerGroupStr) {
var layers = self.selected.getLayers().getArray();
var layer = lodashFind(layers, {
wv: {
@@ -725,7 +726,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {number} Index of layer in OpenLayers layer array
*/
- var findLayerIndex = function (def, layerGroup) {
+ var findLayerIndex = function(def, layerGroup) {
layerGroup = layerGroup || self.selected;
var layers = layerGroup.getLayers().getArray();
@@ -750,7 +751,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {boolean}
*/
- var isGraticule = function (def, proj) {
+ var isGraticule = function(def, proj) {
return (
def.projections[proj].type === 'graticule' || def.type === 'graticule'
);
@@ -767,7 +768,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var addGraticule = function (opacity, groupStr) {
+ var addGraticule = function(opacity, groupStr) {
groupStr = groupStr || 'active';
opacity = opacity || 0.5;
var graticule = self.selected['graticule-' + groupStr];
@@ -799,7 +800,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var removeGraticule = function (groupStr) {
+ var removeGraticule = function(groupStr) {
groupStr = groupStr || 'active';
var graticule = self.selected['graticule-' + groupStr];
if (graticule) {
@@ -809,7 +810,7 @@ export function mapui(models, config, store, ui) {
};
var triggerExtent = lodashThrottle(
- function () {
+ function() {
self.events.trigger('extent');
},
500,
@@ -827,7 +828,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var updateExtent = function () {
+ var updateExtent = function() {
const map = self.selected;
const view = map.getView();
const extent = view.calculateExtent(map.getSize());
@@ -874,7 +875,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {object} OpenLayers Map Object
*/
- var createMap = function (proj, dateSelected) {
+ var createMap = function(proj, dateSelected) {
const state = store.getState();
const { date, compare } = state;
const activeDate = compare.isCompareA ? 'selected' : 'selectedB';
@@ -974,11 +975,11 @@ export function mapui(models, config, store, ui) {
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', function () {
+ map.on('pointerdrag', function() {
self.mapIsbeingDragged = true;
self.events.trigger('drag');
});
- map.getView().on('propertychange', function (e) {
+ map.getView().on('propertychange', function(e) {
switch (e.key) {
case 'resolution':
self.mapIsbeingZoomed = true;
@@ -986,9 +987,9 @@ export function mapui(models, config, store, ui) {
break;
}
});
- map.on('moveend', function (e) {
+ map.on('moveend', function(e) {
self.events.trigger('moveend');
- setTimeout(function () {
+ setTimeout(function() {
self.mapIsbeingDragged = false;
self.mapIsbeingZoomed = false;
}, 200);
@@ -1000,7 +1001,6 @@ export function mapui(models, config, store, ui) {
if (store.getState().data.active) ui.data.onActivate();
};
map.on('rendercomplete', onRenderComplete);
- map.on('click', (e) => onMapClickGetVectorFeatures(e, map, store));
measureTools[proj.crs] = measure(map, self.events, store);
return map;
@@ -1019,7 +1019,7 @@ export function mapui(models, config, store, ui) {
*
* @returns {void}
*/
- var createZoomButtons = function (map, proj) {
+ var createZoomButtons = function(map, proj) {
var $map = $('#' + map.getTarget());
var $zoomOut = $('<div></div>')
@@ -1066,7 +1066,7 @@ export function mapui(models, config, store, ui) {
* @returns {void}
*
*/
- var onZoomChange = function () {
+ var onZoomChange = function() {
var maxZoom = proj.resolutions.length;
var zoom = map.getView().getZoom();
if (zoom === 0) {
@@ -1081,13 +1081,13 @@ export function mapui(models, config, store, ui) {
}
};
- map.getView().on('change:resolution', function () {
+ map.getView().on('change:resolution', function() {
onZoomChange();
self.events.trigger('movestart');
});
onZoomChange();
};
- var onRotate = function (val) {
+ var onRotate = function(val) {
rotation.updateRotation(val);
updateExtent();
};
@@ -1107,7 +1107,7 @@ export function mapui(models, config, store, ui) {
*
* @todo move this component to another Location
*/
- var createMousePosSel = function (map, proj) {
+ var createMousePosSel = function(map, proj) {
var hoverThrottle;
function onMouseMove(e) {
@@ -1153,7 +1153,7 @@ export function mapui(models, config, store, ui) {
if (!self.mapIsbeingDragged && !self.mapIsbeingZoomed) dataRunner.newPoint(pixels, map);
}
$(map.getViewport())
- .mouseout(function (e) {
+ .mouseout(function(e) {
if (
$(e.relatedTarget).hasClass('map-coord') ||
$(e.relatedTarget).hasClass('coord-btn')
@@ -1168,4 +1168,4 @@ export function mapui(models, config, store, ui) {
init();
return self;
-}
\ No newline at end of file
+}
diff --git a/web/js/modules/map/actions.js b/web/js/modules/map/actions.js
index 453d7ba65..731e5090d 100644
--- a/web/js/modules/map/actions.js
+++ b/web/js/modules/map/actions.js
@@ -1,4 +1,4 @@
-import { RUNNING_DATA, CLEAR_RUNNING_DATA, CLEAR_ROTATE } from './constants';
+import { RUNNING_DATA, CLEAR_RUNNING_DATA, CLEAR_ROTATE, CHANGE_CURSOR } from './constants';
export function runningData(payload) {
return {
@@ -18,3 +18,10 @@ export function clearRotate() {
type: CLEAR_ROTATE
};
}
+
+export function changeCursor(bool) {
+ return {
+ type: CHANGE_CURSOR,
+ bool
+ };
+}
diff --git a/web/js/modules/map/constants.js b/web/js/modules/map/constants.js
index 3dd15f419..ea507ea9d 100644
--- a/web/js/modules/map/constants.js
+++ b/web/js/modules/map/constants.js
@@ -6,3 +6,4 @@ 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';
+export const CHANGE_CURSOR = 'MAP/CHANGE_CURSOR';
diff --git a/web/js/modules/map/reducers.js b/web/js/modules/map/reducers.js
index 440f552d4..1c5403d5c 100644
--- a/web/js/modules/map/reducers.js
+++ b/web/js/modules/map/reducers.js
@@ -6,7 +6,8 @@ import {
UPDATE_MAP_UI,
UPDATE_MAP_ROTATION,
RENDERED,
- FITTED_TO_LEADING_EXTENT
+ FITTED_TO_LEADING_EXTENT,
+ CHANGE_CURSOR
} from './constants';
import update from 'immutability-helper';
const INITIAL_STATE = {
@@ -15,7 +16,9 @@ const INITIAL_STATE = {
rotation: 0,
extent: [],
rendered: false,
- leadingExtent: []
+ leadingExtent: [],
+ isClickable: false
+
};
export default function mapReducer(state = INITIAL_STATE, action) {
@@ -45,6 +48,10 @@ export default function mapReducer(state = INITIAL_STATE, action) {
return lodashAssign({}, state, {
leadingExtent: action.extent
});
+ case CHANGE_CURSOR:
+ return lodashAssign({}, state, {
+ isClickable: action.bool
+ });
default:
return state;
}
diff --git a/web/js/modules/modal/reducers.js b/web/js/modules/modal/reducers.js
index 840da245e..54596182b 100644
--- a/web/js/modules/modal/reducers.js
+++ b/web/js/modules/modal/reducers.js
@@ -4,7 +4,8 @@ import {
OPEN_BASIC,
RENDER_TEMPLATE,
ABOUT_PAGE_REQUEST,
- CLOSE
+ CLOSE,
+ CHANGE_CURSOR
} from './constants';
import { requestReducer } from '../core/reducers';
import { assign as lodashAssign } from 'lodash';
diff --git a/web/js/modules/vector-styles/actions.js b/web/js/modules/vector-styles/actions.js
index 047dbeca5..e95439a47 100644
--- a/web/js/modules/vector-styles/actions.js
+++ b/web/js/modules/vector-styles/actions.js
@@ -2,8 +2,7 @@ import {
SET_FILTER_RANGE,
CLEAR_VECTORSTYLE,
SET_VECTORSTYLE,
- SET_SELECTED_VECTORS,
- SET_HOVERED_VECTORS
+ SET_SELECTED_VECTORS
} from './constants';
import {
setRange as setRangeSelector,
@@ -101,5 +100,5 @@ export function selectVectorFeatures(payload) {
return {
type: SET_SELECTED_VECTORS,
payload
- }
-}
\ No newline at end of file
+ };
+}
diff --git a/web/js/modules/vector-styles/constants.js b/web/js/modules/vector-styles/constants.js
index d5eed196d..c27bc9e00 100644
--- a/web/js/modules/vector-styles/constants.js
+++ b/web/js/modules/vector-styles/constants.js
@@ -3,4 +3,4 @@ export const SET_FILTER_RANGE = 'VECTORSTYLES/SET_FILTER_RANGE';
export const CLEAR_VECTORSTYLE = 'VECTORSTYLES/CLEAR_VECTORSTYLE';
export const SET_VECTORSTYLE = 'VECTORSTYLES/SET_VECTORSTYLE';
export const SET_SELECTED_VECTORS = 'VECTORSTYLES/SET_SELECTED';
-export const SET_HOVERED_VECTORS = 'VECTORSTYLES/SET_HOVERED_VECTORS';
\ No newline at end of file
+export const SET_HOVERED_VECTORS = 'VECTORSTYLES/SET_HOVERED_VECTORS';
diff --git a/web/js/modules/vector-styles/reducers.js b/web/js/modules/vector-styles/reducers.js
index 1d2fcbf57..d263d9a15 100644
--- a/web/js/modules/vector-styles/reducers.js
+++ b/web/js/modules/vector-styles/reducers.js
@@ -3,8 +3,7 @@ import {
CLEAR_VECTORSTYLE,
SET_VECTORSTYLE,
SET_FILTER_RANGE,
- SET_SELECTED_VECTORS,
- SET_HOVERED_VECTORS
+ SET_SELECTED_VECTORS
} from './constants';
export const defaultVectorStyleState = {
custom: {},
diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.js
index cafb96f0a..45101337c 100644
--- a/web/js/modules/vector-styles/selectors.js
+++ b/web/js/modules/vector-styles/selectors.js
@@ -54,7 +54,7 @@ export function findIndex(layerId, type, value, index, groupStr, state) {
index = index || 0;
var values = getVectorStyle(layerId, index, groupStr, state).entries.values;
var result;
- lodashEach(values, function (check, index) {
+ lodashEach(values, function(check, index) {
var min = getMinValue(check);
var max = getMaxValue(check);
if (type === 'min' && value === min) {
@@ -101,7 +101,7 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
: null;
}
}
- lodashEach(activeLayers, function (def) {
+ lodashEach(activeLayers, function(def) {
if (!['subdaily', 'daily', 'monthly', 'yearly'].includes(def.period)) {
return;
}
@@ -129,7 +129,7 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
// Filter Orbit Tracks
if (glStyle.name === 'Orbit Tracks') {
// Filter time by 5 mins
- layer.setStyle(function (feature, resolution) {
+ layer.setStyle(function(feature, resolution) {
var minute;
var minutes = feature.get('label');
if (minutes) {
@@ -143,18 +143,17 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)
((selected[layerId] && selected[layerId].length))) {
const selectedFeatures = selected[layerId];
- layer.setStyle(function (feature, resolution) {
+ layer.setStyle(function(feature, resolution) {
const data = state.config.vectorData[def.vectorData.id];
const properties = data.mvt_properties;
const features = feature.getProperties();
- const idKey = lodashFind(properties, { Function: 'Identify' })['Identifier'];
+ const idKey = lodashFind(properties, { Function: 'Identify' }).Identifier;
const uniqueIdentifier = features[idKey];
if (uniqueIdentifier && selectedFeatures && selectedFeatures.includes(uniqueIdentifier)) {
return selectedStyleFunction(feature, styleFunction(feature, resolution));
} else {
return styleFunction(feature, resolution);
}
-
});
}
return vectorStyleId;
@@ -201,7 +200,7 @@ export function clearStyleFunction(def, vectorStyleId, vectorStyles, layer, stat
styleFunction = stylefunction(layer, glStyle, vectorStyleId);
if (glStyle.name === 'Orbit Tracks') {
// Filter time by 5 mins
- layer.setStyle(function (feature, resolution) {
+ layer.setStyle(function(feature, resolution) {
var minute;
var minutes = feature.get('label');
if (minutes) {
@@ -214,4 +213,3 @@ export function clearStyleFunction(def, vectorStyleId, vectorStyles, layer, stat
}
return update(vectorStyles, { layerId: { maps: { $unset: ['custom'] } } });
}
-
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index 0068e39ca..8f5c74a07 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -2,14 +2,9 @@ import {
assign as lodashAssign,
find as lodashFind,
get as lodashGet,
- groupBy as lodashGroupBy,
- isEqual as lodashIsEqual
} from 'lodash';
import { Stroke, Style, Fill, Circle } from 'ol/style';
-import vectorDialog from '../../containers/vector-dialog';
import { setStyleFunction } from './selectors';
-import { openCustomContent } from '../modal/actions';
-import { selectVectorFeatures, hoverVectorFeatures } from './actions';
export function getVectorStyleAttributeArray(layer) {
var isCustomActive = false;
@@ -71,7 +66,7 @@ export function selectedCircleStyle(style) {
}
export function selectedPolygonStyle(style) {
const fill = style.getFill();
- const color = fill.getColor().replace(/[^,]+(?=\))/, '0.5')
+ const color = fill.getColor().replace(/[^,]+(?=\))/, '0.5');
const stroke = style.getStroke();
stroke.setColor('white');
stroke.setWidth(0.5);
@@ -92,30 +87,27 @@ export function selectedStyleFunction(feature, styleArray) {
}
});
}
-export function onMapClickGetVectorFeatures(e, map, store) {
- let metaArray = [];
- let selected = {};
- const state = store.getState();
- const lastSelection = state.vectorStyles.selected;
+export function onMapClickGetVectorFeatures(pixels, map, state) {
+ const metaArray = [];
+ const selected = {};
const config = state.config;
- const dialogId = 'vector_dialog' + e.pixel[0] + e.pixel[1];
- const modalState = state.modal;
- map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
+ map.forEachFeatureAtPixel(pixels, function (feature, layer) {
const def = lodashGet(layer, 'wv.def');
if (!def) return;
if (def.vectorData && def.vectorData.id && def.title) {
const layerId = def.id;
if (!selected[layerId]) selected[layerId] = [];
- let features = feature.getProperties();
+ const features = feature.getProperties();
const vectorDataId = def.vectorData.id;
const data = config.vectorData[vectorDataId];
const properties = data.mvt_properties;
- const uniqueIdentifierKey = lodashFind(properties, { Function: 'Identify' })['Identifier'];
- const titleKey = lodashFind(properties, { IsTitle: "True" })['Identifier'];
+ const uniqueIdentifierKey = lodashFind(properties, { Function: 'Identify' }).Identifier;
+ const titleObj = lodashFind(properties, { IsLabel: 'True' });
+ const titleKey = titleObj.Identifier
const uniqueIdentifier = features[uniqueIdentifierKey];
- const title = features[titleKey];
- if (selected[layerId].includes(uniqueIdentifier)) return
+ const title = titleKey ? features[titleKey] : 'Unknown title';
+ if (selected[layerId].includes(uniqueIdentifier)) return;
const obj = {
legend: properties,
features: features,
@@ -127,41 +119,16 @@ export function onMapClickGetVectorFeatures(e, map, store) {
selected[layerId].push(uniqueIdentifier);
}
});
-
-
- if (metaArray.length) {
- store.dispatch(openCustomContent(dialogId,
- {
- backdrop: false,
- clickableBehindModal: true,
- desktopOnly: true,
- isDraggable: true,
- wrapClassName: 'vector-modal-wrap',
- modalClassName: 'vector-modal light',
- CompletelyCustomModal: vectorDialog,
- isDraggable: true,
- isResizable: true,
- vectorMetaObject: lodashGroupBy(metaArray, 'id'),
- width: 500,
- height: 300,
- onClose: () => {
- store.dispatch(selectVectorFeatures({}));
- }
- }
- ));
- if (Object.entries(selected).length || (Object.entries(lastSelection).length && !(modalState.id.includes('vector_dialog') && modalState.isOpen))) {
- store.dispatch(selectVectorFeatures(selected));
- }
- };
+ return { selected, metaArray };
}
export function updateVectorSelection(selectionObj, lastSelection, layers, type, state) {
- const vectorStyles = state.config.vectorStyles
- for (let [key, featureIdArray] of Object.entries(selectionObj)) {
+ const vectorStyles = state.config.vectorStyles;
+ for (const [key, featureIdArray] of Object.entries(selectionObj)) {
const def = lodashFind(layers, { id: key });
setStyleFunction(def, def.vectorStyle.id, vectorStyles, null, state);
if (lastSelection[key]) delete lastSelection[key];
}
- for (let [key] of Object.entries(lastSelection)) {
+ for (const [key] of Object.entries(lastSelection)) {
const def = lodashFind(layers, { id: key });
setStyleFunction(
def,
@@ -171,5 +138,4 @@ export function updateVectorSelection(selectionObj, lastSelection, layers, type,
state
);
}
-
-}
\ No newline at end of file
+}
diff --git a/web/js/util/util.js b/web/js/util/util.js
index 1febcbfe5..a43c12351 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -16,7 +16,7 @@ import { events } from './events';
import load from './load';
import Cache from 'cachai';
-export default (function (self) {
+export default (function(self) {
var canvas = null;
// Export other util methods
@@ -52,7 +52,7 @@ export default (function (self) {
}
};
- self.repeat = function (value, length) {
+ self.repeat = function(value, length) {
var result = '';
for (var i = 0; i < length; i++) {
result += value;
@@ -60,7 +60,7 @@ export default (function (self) {
return result;
};
- self.pad = function (value, width, padding) {
+ self.pad = function(value, width, padding) {
value = '' + value;
if (value.length < width) {
var add = width - value.length;
@@ -68,7 +68,7 @@ export default (function (self) {
}
return value;
};
- self.preventPinch = function (e) {
+ self.preventPinch = function(e) {
if (e.deltaY && !Number.isInteger(e.deltaY)) {
e.stopPropagation();
e.preventDefault();
@@ -94,7 +94,7 @@ export default (function (self) {
* object.
* @return {object} object representation of the query string.
*/
- self.fromQueryString = function (queryString) {
+ self.fromQueryString = function(queryString) {
if (!queryString) {
return {};
}
@@ -111,7 +111,7 @@ export default (function (self) {
}
return result;
};
- self.elapsed = function (message, startTime, parameters) {
+ self.elapsed = function(message, startTime, parameters) {
if (parameters && !parameters.elapsed) return;
var t = new Date().getTime() - startTime;
console.log(t, message);
@@ -138,12 +138,12 @@ export default (function (self) {
* "format=image/png"
* @return {String} converted query string
*/
- self.toQueryString = function (kvps, exceptions) {
+ self.toQueryString = function(kvps, exceptions) {
exceptions = exceptions || {};
var parts = [];
- lodashEach(kvps, function (value, key) {
+ lodashEach(kvps, function(value, key) {
var part = key + '=' + encodeURIComponent(value);
- lodashEach(exceptions, function (exception) {
+ lodashEach(exceptions, function(exception) {
var regexp = new RegExp(exception, 'ig');
var decoded = decodeURIComponent(exception);
part = part.replace(regexp, decoded);
@@ -167,7 +167,7 @@ export default (function (self) {
* @return {Date} converted string as a datetime object, throws an
* exception if the string is invalid.
*/
- self.parseTimestampUTC = function (str) {
+ self.parseTimestampUTC = function(str) {
return self.parseDateUTC(str);
};
@@ -181,7 +181,7 @@ export default (function (self) {
* @return y {Number} Y value on canvas
* @return {Object} Canvas image data.
*/
- self.getCanvasPixelData = function (canvas, x, y) {
+ self.getCanvasPixelData = function(canvas, x, y) {
var context = canvas.getContext('2d');
return context.getImageData(x, y, 1, 1)
.data;
@@ -197,7 +197,7 @@ export default (function (self) {
* the string is invalid
*/
// NOTE: Older Safari doesn't like Date.parse
- self.parseDateUTC = function (dateAsString) {
+ self.parseDateUTC = function(dateAsString) {
var dateTimeArr = dateAsString.split(/T/);
var yyyymmdd = dateTimeArr[0].split(/[\s-]+/);
@@ -227,12 +227,12 @@ export default (function (self) {
}
return date;
};
- self.appendAttributesForURL = function (item) {
+ self.appendAttributesForURL = function(item) {
if (lodashIsObject(item)) {
let part = item.id || '';
const attributes = [];
if (item.attributes && item.attributes.length > 0) {
- lodashEach(item.attributes, function (attribute) {
+ lodashEach(item.attributes, function(attribute) {
if (attribute.value) {
attributes.push(attribute.id + '=' + attribute.value);
} else {
@@ -250,7 +250,7 @@ export default (function (self) {
* Test if is valid Date
* @param {Object} d | Date object
*/
- self.isValidDate = function (d) {
+ self.isValidDate = function(d) {
return d instanceof Date && !isNaN(d);
};
/**
@@ -262,7 +262,7 @@ export default (function (self) {
* @return {Date} converted string as a non UTC date object, throws an exception if
* the string is invalid
*/
- self.parseDate = function (dateAsString) {
+ self.parseDate = function(dateAsString) {
var dateTimeArr = dateAsString.split(/T/);
var yyyymmdd = dateTimeArr[0].split(/[\s-]+/);
@@ -301,7 +301,7 @@ export default (function (self) {
*
* @see http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
*/
- self.getTextWidth = function (text, font) {
+ self.getTextWidth = function(text, font) {
// re-use canvas object for better performance
canvas = canvas || document.createElement('canvas');
var context = canvas.getContext('2d');
@@ -317,7 +317,7 @@ export default (function (self) {
* @param {Date} date {Date} the date to convert
* @return {string} Julian date string in the form of `YYYYDDD`
*/
- self.toJulianDate = function (date) {
+ self.toJulianDate = function(date) {
var jStart, jDate;
jStart = self.parseDateUTC(date.getUTCFullYear() + '-01-01');
jDate = '00' + (1 + Math.ceil((date.getTime() - jStart) / 86400000));
@@ -332,7 +332,7 @@ export default (function (self) {
* @param date {Date} the date to convert
* @return {string} ISO string in the form of ``YYYY-MM-DD``.
*/
- self.toISOStringDate = function (date) {
+ self.toISOStringDate = function(date) {
return date.toISOString()
.split('T')[0];
};
@@ -345,7 +345,7 @@ export default (function (self) {
* @param {Date} date the date to convert
* @return {string} ISO string in the form of `YYYY-MM-DDThh:mm:ssZ`.
*/
- self.toISOStringSeconds = function (date) {
+ self.toISOStringSeconds = function(date) {
return date.toISOString().split('.')[0] + 'Z';
};
@@ -357,7 +357,7 @@ export default (function (self) {
* @param {Date} date the date to convert
* @return {string} ISO string in the form of `YYYY-MM-DDThh:mmZ`.
*/
- self.toISOStringMinutes = function (date) {
+ self.toISOStringMinutes = function(date) {
const parts = date.toISOString().split(':');
return parts[0] + ':' + parts[1] + 'Z';
};
@@ -370,7 +370,7 @@ export default (function (self) {
* @param date {Date} the date to convert
* @return {string} ISO string in the form of HH:MM`.
*/
- self.toHourMinutes = function (date) {
+ self.toHourMinutes = function(date) {
var time = date.toISOString()
.split('T')[1];
var parts = time.split('.')[0].split(':');
@@ -385,7 +385,7 @@ export default (function (self) {
* @param time {Date} date
* @return {number} rounded date
*/
- self.roundTimeOneMinute = function (time) {
+ self.roundTimeOneMinute = function(time) {
var timeToReturn = new Date(time);
timeToReturn.setMilliseconds(Math.round(timeToReturn.getMilliseconds() / 1000) * 1000);
@@ -401,9 +401,9 @@ export default (function (self) {
* @param str {String} String
* @return {string} cleaned str
*/
- self.cleanId = function (str) {
+ self.cleanId = function(str) {
return str.replace(/\W/g, '_');
- }
+ };
/**
* Sets a date to UTC midnight.
*
@@ -413,7 +413,7 @@ export default (function (self) {
* to zero.
* @return {Date} the date object
*/
- self.clearTimeUTC = function (date) {
+ self.clearTimeUTC = function(date) {
date.setUTCHours(0);
date.setUTCMinutes(0);
date.setUTCSeconds(0);
@@ -422,7 +422,7 @@ export default (function (self) {
return date;
};
- self.dateAdd = function (date, interval, amount) {
+ self.dateAdd = function(date, interval, amount) {
var month, maxDay, year;
var newDate = new Date(date);
switch (interval) {
@@ -454,11 +454,8 @@ export default (function (self) {
return newDate;
};
-<<<<<<< HEAD
+
self.getNumberOfDays = function(start, end, interval, increment, maxToCheck) {
-=======
- self.getNumberOfDays = function (start, end, interval, increment) {
->>>>>>> Fix dialog displays #2144
increment = increment || 1;
var i = 1;
var currentDate = start;
@@ -473,7 +470,7 @@ export default (function (self) {
return i;
};
- self.daysInMonth = function (d) {
+ self.daysInMonth = function(d) {
var year;
var month;
if (d.getUTCFullYear) {
@@ -487,14 +484,14 @@ export default (function (self) {
return lastDay.getUTCDate();
};
- self.daysInYear = function (date) {
+ self.daysInYear = function(date) {
var jStart, jDate;
jStart = self.parseDateUTC(date.getUTCFullYear() + '-01-01');
jDate = '00' + (Math.ceil((date.getTime() - jStart) / 86400000) + 1);
return (jDate).substr((jDate.length) - 3);
};
- self.objectLength = function (obj) {
+ self.objectLength = function(obj) {
return Object.keys(obj)
.length;
};
@@ -507,7 +504,7 @@ export default (function (self) {
* @param date {Date} date object of which to determine week day
* @return {String} the full name of the day of the week
*/
- self.giveWeekDay = function (d) {
+ self.giveWeekDay = function(d) {
var day = [
'Sunday',
'Monday',
@@ -529,7 +526,7 @@ export default (function (self) {
* @param date {Date} date object of which to determine the Month name
* @return {String} the full name of the month
*/
- self.giveMonth = function (d) {
+ self.giveMonth = function(d) {
var month = [
'January',
'February',
@@ -548,7 +545,7 @@ export default (function (self) {
return month[d.getUTCMonth()];
};
- self.clamp = function (val, min, max) {
+ self.clamp = function(val, min, max) {
if (val < min) {
return min;
}
@@ -558,7 +555,7 @@ export default (function (self) {
return val;
};
- self.roll = function (val, min, max) {
+ self.roll = function(val, min, max) {
if (val < min) {
return max - (min - val) + 1;
}
@@ -568,15 +565,15 @@ export default (function (self) {
return val;
};
- self.minDate = function () {
+ self.minDate = function() {
return new Date(Date.UTC(1000, 0, 1, 0, 0));
};
- self.maxDate = function () {
+ self.maxDate = function() {
return new Date(Date.UTC(3000, 11, 30, 23, 59));
};
- self.rollRange = function (date, interval, minDate, maxDate) {
+ self.rollRange = function(date, interval, minDate, maxDate) {
var year = date.getUTCFullYear();
var month = date.getUTCMonth();
var first, last;
@@ -628,7 +625,7 @@ export default (function (self) {
};
};
- self.rollDate = function (date, interval, amount, minDate, maxDate) {
+ self.rollDate = function(date, interval, amount, minDate, maxDate) {
minDate = minDate || self.minDate();
maxDate = maxDate || self.maxDate();
var range = self.rollRange(date, interval, minDate, maxDate);
@@ -681,7 +678,7 @@ export default (function (self) {
* @return {String} string representation in the form of
* ``YYYYMMDDHHMMSSsss``
*/
- self.toCompactTimestamp = function (date) {
+ self.toCompactTimestamp = function(date) {
return date.toISOString()
.replace(/[-:TZ.]/g, '');
};
@@ -695,7 +692,7 @@ export default (function (self) {
* ``YYYYMMDDHHMMSSsss``.
* @return {Date} the converted date object.
*/
- self.fromCompactTimestamp = function (str) {
+ self.fromCompactTimestamp = function(str) {
var v = str.match(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{3})/);
if (lodashIsNull(v)) {
throw new Error('Invalid timestamp:' + str);
@@ -718,13 +715,13 @@ export default (function (self) {
* @static
* @return {Date} The current time or an overriden value.
*/
- var now = function () {
+ var now = function() {
return new Date();
};
self.now = now;
- self.resetNow = function () {
+ self.resetNow = function() {
self.now = now;
};
@@ -737,7 +734,7 @@ export default (function (self) {
* @return {Date} The current time with the UTC hours, minutes, and seconds
* fields set to zero or an overriden value.
*/
- self.today = function () {
+ self.today = function() {
return self.now();
};
@@ -753,7 +750,7 @@ export default (function (self) {
* @param {string} message Message to display to the end user.
* @param {Exception} cause The exception object that caused the error
*/
- self.error = function (message, cause) {
+ self.error = function(message, cause) {
wvui.error(message, cause);
};
@@ -767,16 +764,16 @@ export default (function (self) {
* @param {object*} messages Messages to display to the end user.
*/
self.warn = (console && console.warn && console.warn.bind)
- ? console.warn.bind(console) : function () { };
+ ? console.warn.bind(console) : function() { };
- self.hexToRGB = function (str) {
+ self.hexToRGB = function(str) {
return 'rgb(' +
parseInt(str.substring(0, 2), 16) + ',' +
parseInt(str.substring(2, 4), 16) + ',' +
parseInt(str.substring(4, 6), 16) + ')';
};
- self.hexToRGBA = function (str) {
+ self.hexToRGBA = function(str) {
return 'rgba(' +
parseInt(str.substring(0, 2), 16) + ',' +
parseInt(str.substring(2, 4), 16) + ',' +
@@ -784,7 +781,7 @@ export default (function (self) {
parseInt(str.substring(6, 8), 16) + ')';
};
- self.rgbaToHex = function (r, g, b) {
+ self.rgbaToHex = function(r, g, b) {
function hex(c) {
var strHex = c.toString(16);
return strHex.length === 1 ? '0' + strHex : strHex;
@@ -792,7 +789,7 @@ export default (function (self) {
return hex(r) + hex(g) + hex(b) + 'ff';
};
- self.hexColorDelta = function (hex1, hex2) {
+ self.hexColorDelta = function(hex1, hex2) {
var r1 = parseInt(hex1.substring(0, 2), 16);
var g1 = parseInt(hex1.substring(2, 4), 16);
var b1 = parseInt(hex1.substring(4, 6), 16);
@@ -802,18 +799,18 @@ export default (function (self) {
// calculate differences in 3D Space
return Math.sqrt(Math.pow((r1 - r2), 2) + Math.pow((g1 - g2), 2) + Math.pow((b1 - b2), 2));
};
- self.fetch = function (url, mimeType) {
+ self.fetch = function(url, mimeType) {
return new Promise((resolve, reject) => {
return fetch(url)
- .then(function (response) {
+ .then(function(response) {
return mimeType === 'application/json'
? response.json()
: response.text();
})
- .then(function (data) {
+ .then(function(data) {
resolve(data);
})
- .catch(function (error) {
+ .catch(function(error) {
reject(error);
});
});
@@ -829,7 +826,7 @@ export default (function (self) {
* @param {Object} [spec.options] options to pass to jscache on setItem.
*
*/
- self.ajaxCache = function (spec) {
+ self.ajaxCache = function(spec) {
spec = spec || {};
var size = spec.size || null;
var options = spec.options || {};
@@ -847,7 +844,7 @@ export default (function (self) {
* when the query returns, or resolves immedately if the results
* are cached.
*/
- submit: function (parameters) {
+ submit: function(parameters) {
var key = 'url=' + parameters.url;
if (parameters.data) {
key += '&query=' + $.param(parameters.data, true);
@@ -860,7 +857,7 @@ export default (function (self) {
.promise();
} else {
var promise = $.ajax(parameters);
- promise.done(function (results) {
+ promise.done(function(results) {
cache.setItem(key, results, options);
});
return promise;
@@ -868,9 +865,9 @@ export default (function (self) {
}
};
};
- self.errorReport = function (errors) {
+ self.errorReport = function(errors) {
var layersRemoved = 0;
- lodashEach(errors, function (error) {
+ lodashEach(errors, function(error) {
var cause = error.cause ? ': ' + error.cause : '';
self.warn(error.message + cause);
if (error.layerRemoved) {
@@ -885,8 +882,8 @@ export default (function (self) {
* @param {function} func the function to wrap
* @return the function wrapped in a try/catch block.
*/
- self.wrap = function (func) {
- return function () {
+ self.wrap = function(func) {
+ return function() {
try {
return func.apply(func, arguments);
} catch (error) {
@@ -903,14 +900,14 @@ export default (function (self) {
* @param {url} func the function to wrap
* @return {object} Promise
*/
- self.get = function (url) {
+ self.get = function(url) {
// Return a new promise.
- return new Promise(function (resolve, reject) {
+ return new Promise(function(resolve, reject) {
// Do the usual XHR stuff
var req = new XMLHttpRequest();
req.open('GET', url);
- req.onload = function () {
+ req.onload = function() {
// This is called even on 404 etc
// so check the status
if (req.status === 200) {
@@ -923,7 +920,7 @@ export default (function (self) {
}
};
// Handle network errors
- req.onerror = function () {
+ req.onerror = function() {
reject(Error('Network Error'));
};
// Make the request
@@ -932,20 +929,20 @@ export default (function (self) {
};
// FIXME: Should be replaced with $.when
- self.ajaxJoin = function (calls) {
+ self.ajaxJoin = function(calls) {
var completed = 0;
var result = {};
var deferred = $.Deferred();
- $.each(calls, function (index, call) {
- call.promise.done(function (data) {
+ $.each(calls, function(index, call) {
+ call.promise.done(function(data) {
result[call.item] = data;
completed += 1;
if (completed === calls.length) {
deferred.resolve(result);
}
})
- .fail(function (jqXHR, textStatus, errorThrown) {
+ .fail(function(jqXHR, textStatus, errorThrown) {
deferred.reject(jqXHR, textStatus, errorThrown);
});
});
@@ -968,21 +965,21 @@ export default (function (self) {
// The original plan was to escape the special characters but that
// became confusing as element attributes would need one escape character
// but the selector would need two (\. vs \\.)
- self.encodeId = function (str) {
+ self.encodeId = function(str) {
return str.replace(/[.:]/g, (match) => {
return '__' + match.charCodeAt(0).toString(16).toUpperCase() + '__';
});
};
// Converts an encoded identifier back to its original value.
- self.decodeId = function (str) {
+ self.decodeId = function(str) {
return str.replace(/__[0-9A-Fa-f]{2}__/g, (match) => {
const charCode = Number.parseInt(match.substring(2, 4), 16);
return String.fromCharCode(charCode);
});
};
- self.metrics = function () {
+ self.metrics = function() {
if (window.ntptEventTag) {
ntptEventTag.apply(null, arguments);
} else {
@@ -1032,7 +1029,7 @@ export default (function (self) {
self.formatDMS = (value, type) => formatDegrees(value, type, true);
self.formatDM = (value, type) => formatDegrees(value, type, false);
- self.setCoordinateFormat = function (type) {
+ self.setCoordinateFormat = function(type) {
if (!browser.localStorage) return;
if (type !== 'latlon-dd' && type !== 'latlon-dms' && type !== 'latlon-dm') {
throw new Error('Invalid coordinate format: ' + type);
@@ -1040,12 +1037,12 @@ export default (function (self) {
localStorage.setItem('coordinateFormat', type);
};
- self.getCoordinateFormat = function () {
+ self.getCoordinateFormat = function() {
if (!browser.localStorage) return 'latlon-dd';
return localStorage.getItem('coordinateFormat') || 'latlon-dd';
};
- self.formatCoordinate = function (coord, format) {
+ self.formatCoordinate = function(coord, format) {
var type = format || self.getCoordinateFormat();
if (type === 'latlon-dms') {
return self.formatDMS(coord[1], 'latitude') + ', ' +
@@ -1063,7 +1060,7 @@ export default (function (self) {
// arguments array contains all args passed. String must be formatted
// so that first replacement starts with "{1}"
// usage example: wv.util.format("{1}{2}",'World','view')
- self.format = function () {
+ self.format = function() {
var formatted = arguments[0];
for (var i = 1; i < arguments.length; i++) {
var regexp = new RegExp('\\{' + i + '\\}', 'gi');
@@ -1072,7 +1069,7 @@ export default (function (self) {
return formatted;
};
- self.toArray = function (value) {
+ self.toArray = function(value) {
if (!value) {
return [];
}
@@ -1083,14 +1080,14 @@ export default (function (self) {
};
// Returns the number of months between two dates
- self.yearDiff = function (startDate, endDate) {
+ self.yearDiff = function(startDate, endDate) {
var year1 = startDate.getFullYear();
var year2 = endDate.getFullYear();
return year2 - year1;
};
// Returns the number of months between two dates
- self.monthDiff = function (startDate, endDate) {
+ self.monthDiff = function(startDate, endDate) {
var year1 = startDate.getFullYear();
var year2 = endDate.getFullYear();
var month1 = startDate.getMonth();
@@ -1103,7 +1100,7 @@ export default (function (self) {
return numberOfMonths;
};
- self.dayDiff = function (startDate, endDate) {
+ self.dayDiff = function(startDate, endDate) {
var date1 = new Date(startDate);
var date2 = new Date(endDate);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
@@ -1111,7 +1108,7 @@ export default (function (self) {
return dayDiff;
};
- self.minuteDiff = function (startDate, endDate) {
+ self.minuteDiff = function(startDate, endDate) {
var date1 = new Date(startDate);
var date2 = new Date(endDate);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
@@ -1125,7 +1122,7 @@ export default (function (self) {
* @param {String} value | String to return index of
* @return {Number}
*/
- self.stringInArray = function (arra, value) {
+ self.stringInArray = function(arra, value) {
for (var i = 0, len = arra.length; i < len; i++) {
if (arra[i] === value) {
return i;
@@ -1140,7 +1137,7 @@ export default (function (self) {
* @param {array} comment seperated list of objects
* @return {bool}
*/
- self.objectsHaveSameKeys = function (...objects) {
+ self.objectsHaveSameKeys = function(...objects) {
const allKeys = objects.reduce((keys, object) => keys.concat(Object.keys(object)), []);
const union = new Set(allKeys);
return objects.every(object => union.size === Object.keys(object).length);