Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Additional fixes

ZachTRice574d1c2d3f5d
diff --git a/web/js/containers/map-interactions/ol-vector-interactions.js b/web/js/containers/map-interactions/ol-vector-interactions.js
index 6e4bf9462..95e310f34 100644
--- a/web/js/containers/map-interactions/ol-vector-interactions.js
+++ b/web/js/containers/map-interactions/ol-vector-interactions.js
@@ -379,7 +379,6 @@ const mapDispatchToProps = (dispatch) => ({
mobileFullScreen: true,
dragHandle: '.modal-header',
dialogKey,
- key: dialogKey,
vectorMetaObject: lodashGroupBy(metaArray, 'id'),
width: modalWidth,
height: modalHeight,
diff --git a/web/js/containers/modal.js b/web/js/containers/modal.js
index 00795816d..f2f1357d2 100644
--- a/web/js/containers/modal.js
+++ b/web/js/containers/modal.js
@@ -6,7 +6,6 @@ import { toLower as lodashToLower } from 'lodash';
import {
Modal, ModalBody, ModalHeader, ModalFooter,
} from 'reactstrap';
-import Draggable from 'react-draggable';
import { Resizable } from 'react-resizable';
import { onToggle as onToggleAction } from '../modules/modal/actions';
import ErrorBoundary from './error-boundary';
@@ -57,7 +56,16 @@ function ModalContainer(props) {
const [offsetTop, setOffsetTop] = useState(propsOffsetTop);
const [offsetRight, setOffsetRight] = useState(propsOffsetRight);
const [measuredElement, setMeasuredElement] = useState();
- const draggableNodeRef = useRef(null);
+ const [isDragging, setIsDragging] = useState(false);
+ const dragStartRef = useRef({
+ x: 0,
+ y: 0,
+ left: 0,
+ top: 0,
+ width: 0,
+ height: 0,
+ stayOnscreen: false,
+ });
const prevScreenHeight = usePrevious(screenHeight);
const prevScreenWidth = usePrevious(screenWidth);
const prevWidth = usePrevious(width);
@@ -72,6 +80,66 @@ function ModalContainer(props) {
}
}, []);
+ const beginDrag = useCallback((e, { dragHandle, stayOnscreen }) => {
+ if (!e || e.button !== 0) return;
+ if (!dragHandle) return;
+ if (!e.target?.closest?.(dragHandle)) return;
+ if (e.target?.closest?.('button, a, input, select, textarea')) return;
+
+ const rect = measuredElement?.getBoundingClientRect?.();
+ const startLeft = typeof offsetLeft === 'number' ? offsetLeft : (rect?.left || 0);
+ const startTop = typeof offsetTop === 'number' ? offsetTop : (rect?.top || 0);
+ const elWidth = width || rect?.width || 0;
+ const elHeight = height || rect?.height || 0;
+
+ dragStartRef.current = {
+ x: e.clientX,
+ y: e.clientY,
+ left: startLeft,
+ top: startTop,
+ width: elWidth,
+ height: elHeight,
+ stayOnscreen: !!stayOnscreen,
+ };
+
+ setIsDragging(true);
+ }, [measuredElement, offsetLeft, offsetTop, width, height]);
+
+ useEffect(() => {
+ if (!isDragging) return undefined;
+
+ const onMove = (e) => {
+ const start = dragStartRef.current;
+ const dx = e.clientX - start.x;
+ const dy = e.clientY - start.y;
+
+ let nextLeft = start.left + dx;
+ let nextTop = start.top + dy;
+
+ if (start.stayOnscreen && start.width && start.height) {
+ const maxLeft = Math.max(0, screenWidth - start.width);
+ const maxTop = Math.max(0, screenHeight - start.height);
+ nextLeft = Math.min(Math.max(0, nextLeft), maxLeft);
+ nextTop = Math.min(Math.max(0, nextTop), maxTop);
+ }
+
+ setOffsetLeft(nextLeft);
+ setOffsetTop(nextTop);
+ };
+
+ const onUp = () => {
+ setIsDragging(false);
+ };
+
+ window.addEventListener('mousemove', onMove);
+ window.addEventListener('mouseup', onUp);
+
+ return () => {
+ window.removeEventListener('mousemove', onMove);
+ window.removeEventListener('mouseup', onUp);
+ };
+ }, [isDragging, screenWidth, screenHeight]);
+
const onParamChange = (e, { size }) => {
if (e) {
e.stopPropagation();
@@ -168,48 +236,30 @@ function ModalContainer(props) {
}
const handleCreateChildren = (children) => {
- const style = getStyle();
const newProps = isCustom && id ? update(props, { $merge: customProps }) : props;
const {
- dragHandle,
- isDraggable,
isResizable,
- stayOnscreen,
} = newProps;
- const bounds = stayOnscreen
- ? {
- left: -(screenWidth / 2 - width / 2),
- right: screenWidth / 2 - width / 2,
- top: -style.top,
- bottom: screenHeight - height - style.top - 5,
- }
- : '';
- return (
- <Draggable
- nodeRef={draggableNodeRef}
- handle={dragHandle}
- disabled={!isDraggable}
- bounds={bounds}
- >
- {isResizable
- ? (
- <Resizable
- className="resize-box"
- resizeHandles={['se']}
- width={width || newProps.width}
- height={height || newProps.height}
- minConstraints={[250, 250]}
- maxConstraints={[495, screenHeight]}
- handleSize={[8, 8]}
- onResize={onResize}
- draggableOpts={{ disabled: !isResizable }}
- >
- {children}
- </Resizable>
- )
- : children}
- </Draggable>
- );
+ const maybeResizableChildren = isResizable
+ ? (
+ <Resizable
+ className="resize-box"
+ resizeHandles={['se']}
+ width={width || newProps.width}
+ height={height || newProps.height}
+ minConstraints={[250, 250]}
+ maxConstraints={[495, screenHeight]}
+ handleSize={[8, 8]}
+ onResize={onResize}
+ draggableOpts={{ disabled: !isResizable }}
+ >
+ {children}
+ </Resizable>
+ )
+ : children;
+
+ // Manual dragging is handled via mouse events on the modal content wrapper.
+ return maybeResizableChildren;
};
const newProps = isCustom && id ? update(props, { $merge: customProps }) : props;
@@ -220,6 +270,8 @@ function ModalContainer(props) {
bodyComponentProps,
bodyHeader,
bodyText,
+ dragHandle,
+ stayOnscreen,
footer,
clickableBehindModal,
CompletelyCustomModal,
@@ -238,6 +290,14 @@ function ModalContainer(props) {
wrapClassName,
} = newProps;
+ const customPropsWithoutKey = { ...(customProps || {}) };
+ delete customPropsWithoutKey.key;
+
+ const handleModalMouseDown = useCallback((e) => {
+ if (!isDraggable) return;
+ beginDrag(e, { dragHandle, stayOnscreen });
+ }, [beginDrag, dragHandle, isDraggable, stayOnscreen]);
+
const isRestrictedDisplay = (isMobile && desktopOnly) ||
(!isMobile && mobileOnly) ||
(isEmbedModeActive && size === 'lg' && !id.includes('LAYER_INFO_MODAL'));
@@ -266,7 +326,6 @@ function ModalContainer(props) {
isOpen={isOpen}
toggle={toggleFunction}
backdrop={backdrop}
- innerRef={draggableNodeRef}
id={lowerCaseId}
size={size}
className={isTemplateModal ? 'template-modal' : modalClassName || 'default-modal'}
@@ -276,15 +335,15 @@ function ModalContainer(props) {
modalTransition={{ timeout: isDraggable ? 0 : timeout || 100 }}
fade={!isDraggable}
>
- <div ref={handleElement}>
+ <div ref={handleElement} onMouseDown={handleModalMouseDown} style={{ height: '100%' }}>
{CompletelyCustomModal
? (
<CompletelyCustomModal
- key={`custom_${lowerCaseId}`}
+ key={customProps?.dialogKey ? `custom_${lowerCaseId}_${customProps.dialogKey}` : `custom_${lowerCaseId}`}
modalHeight={height || newProps.height}
modalWidth={width || newProps.width}
// eslint-disable-next-line react/jsx-props-no-spreading
- {...customProps}
+ {...customPropsWithoutKey}
toggleWithClose={toggleFunction}
/>
)
diff --git a/web/js/mapUI/components/update-opacity/updateOpacity.js b/web/js/mapUI/components/update-opacity/updateOpacity.js
index d1269c86f..40c563412 100644
--- a/web/js/mapUI/components/update-opacity/updateOpacity.js
+++ b/web/js/mapUI/components/update-opacity/updateOpacity.js
@@ -60,14 +60,24 @@ function UpdateOpacity(props) {
const updateOpacity = (actionObj) => {
const { id, opacity } = actionObj;
const def = lodashFind(activeLayers, { id });
+ if (!def) {
+ updateLayerVisibilities();
+ return;
+ }
if (def.type === 'granule') {
updateGranuleLayerOpacity(def, activeString, opacity, compare);
} else {
const layerGroup = findLayer(def, activeString);
+ if (!layerGroup || typeof layerGroup.setOpacity !== 'function') {
+ updateLayerVisibilities();
+ return;
+ }
layerGroup.setOpacity(opacity);
- layerGroup.getLayersArray().forEach((l) => {
- l.setOpacity(opacity);
- });
+ if (typeof layerGroup.getLayersArray === 'function') {
+ layerGroup.getLayersArray().forEach((l) => {
+ l.setOpacity(opacity);
+ });
+ }
}
updateLayerVisibilities();
};
diff --git a/web/scss/components/dateselector.scss b/web/scss/components/dateselector.scss
index 05addd40f..208d6efea 100644
--- a/web/scss/components/dateselector.scss
+++ b/web/scss/components/dateselector.scss
@@ -51,6 +51,7 @@
background: transparent;
border: 0;
font-family: variables.$wv-monospace-font;
+ font-size: 15px;
vertical-align: middle;
box-sizing: border-box;
padding: 0;
@@ -59,6 +60,10 @@
width: 100%;
}
+ button {
+ font-size: 15px;
+ }
+
.input-wrapper:hover {
border-color: #666;