Interactive interface for browsing global, full-resolution satellite imagery
correctly position modal on first open #2144
Benjamin Kinga06165d9a1e3
diff --git a/web/css/modal.css b/web/css/modal.cssindex a5e0790a5..bfba8ebfa 100644--- a/web/css/modal.css+++ b/web/css/modal.css@@ -17,14 +17,8 @@.draggable-modal .modal {position: fixed;}-.react-draggable.modal-dialog.vector-modal {+.react-draggable.modal-dialog {position: absolute;- left: 50%;- width: 500px;- height: 160px;- margin-left: -250px;- margin-top: 10px;- margin-bottom: 0;}.template-modal.modal-dialog {max-width: 625px;diff --git a/web/css/vectorMeta.css b/web/css/vectorMeta.cssindex ae0be35a6..7ced077a2 100644--- a/web/css/vectorMeta.css+++ b/web/css/vectorMeta.css@@ -1,3 +1,8 @@+.vector-modal {+ width: 445px;+ height: 300px;+ position: absolute;+}.vector-modal .close {opacity: 1;}diff --git a/web/js/components/map/ol-coordinates.js b/web/js/components/map/ol-coordinates.jsindex c6e683f85..c0bfcdc23 100644--- a/web/js/components/map/ol-coordinates.js+++ b/web/js/components/map/ol-coordinates.js@@ -37,15 +37,18 @@ class OlCoordinates extends React.Component {mouseClick(e, map) {const pixels = e.pixel;- const { lastSelected, openVectorDiaglog, selectVectorFeatures, modalStateId, getDialogObject } = this.props;+ const { lastSelected, openVectorDiaglog, selectVectorFeatures, modalState, getDialogObject } = this.props;const clickObj = getDialogObject(pixels, map);const metaArray = clickObj.metaArray || [];const selected = clickObj.selected || {};+ const offsetLeft = clickObj.offsetLeft || 10;const dialogId = 'vector_dialog' + pixels[0] + pixels[1];+ const isVectorModalOpen = modalState.id.includes('vector_dialog') && modalState.isOpen;+if (metaArray.length) {- openVectorDiaglog(dialogId, metaArray);+ openVectorDiaglog(dialogId, metaArray, isVectorModalOpen ? undefined : offsetLeft);}- if (Object.entries(selected).length || (Object.entries(lastSelected).length && !(modalStateId.includes('vector_dialog') && modalState.isOpen))) {+ if (Object.entries(selected).length || (Object.entries(lastSelected).length && !isVectorModalOpen)) {selectVectorFeatures(selected);}}@@ -129,7 +132,7 @@ const mapDispatchToProps = dispatch => ({dispatch(changeCursor(bool))},- openVectorDiaglog: (dialogId, metaArray) => {+ openVectorDiaglog: (dialogId, metaArray, offsetLeft) => {dispatch(openCustomContent(dialogId,{backdrop: false,@@ -142,8 +145,9 @@ const mapDispatchToProps = dispatch => ({isDraggable: true,isResizable: true,vectorMetaObject: lodashGroupBy(metaArray, 'id'),- width: 500,+ width: 445,height: 300,+ offsetLeft,onClose: () => {dispatch(selectVectorFeatures({}));}@@ -153,7 +157,7 @@ const mapDispatchToProps = dispatch => ({});function mapStateToProps(state) {return {- modalStateId: state.modal.id,+ modalState: state.modal,isShowingClick: state.map.isClickable,getDialogObject: (pixels, map) => { return onMapClickGetVectorFeatures(pixels, map, state); },lastSelected: state.vectorStyles.selecteddiff --git a/web/js/containers/modal.js b/web/js/containers/modal.jsindex 9c414ae13..f1a06864f 100644--- a/web/js/containers/modal.js+++ b/web/js/containers/modal.js@@ -28,19 +28,21 @@ class ModalContainer extends Component {height: props.customProps.height,isDraggable: props.isDraggable};+ this._style = {}this.onResize = this.onResize.bind(this);}getStyle(state, props) {const isResizable = props.isResizable;- return {- left: props.offsetLeft,+ this._style = {+ left: props.offsetLeft || this._style.left,right: props.offsetRight,top: props.offsetTop,width: isResizable ? state.width : props.width,height: isResizable ? state.height : props.height,maxHeight: isResizable ? state.height : props.height- };+ }+ return this._style;}onResize(e, { size }) {@@ -119,7 +121,7 @@ class ModalContainer extends Component {disabled={!isDraggable}><Resizable className="resize-box" resizeHandles={['se']}- width={this.state.width || 500} height={this.state.height || 300} minConstraints={[250, 250]}+ width={this.state.width || newProps.width} height={this.state.height || newProps.height} minConstraints={[250, 250]}maxConstraints={[495, screenHeight]}handleSize={[8, 8]}onResize={this.onResize}@@ -145,7 +147,7 @@ class ModalContainer extends Component {fade={!isDraggable}>{CompletelyCustomModal- ? (<CompletelyCustomModal key={'custom_' + lowerCaseId} modalHeight={this.state.height} modalWidth={this.state.width} {...customProps}+ ? (<CompletelyCustomModal key={'custom_' + lowerCaseId} modalHeight={this.state.height || newProps.height} modalWidth={this.state.width || newProps.width} {...customProps}toggleWithClose={toggleFunction} />): (<DetectOuterClickdiff --git a/web/js/containers/vector-dialog.js b/web/js/containers/vector-dialog.jsindex 42337276c..d6311fa6e 100644--- a/web/js/containers/vector-dialog.js+++ b/web/js/containers/vector-dialog.js@@ -19,7 +19,7 @@ class VectorDialog extends React.Component {}render() {- const { toggleWithClose, vectorMetaObject, modalHeight } = this.props;+ const { toggleWithClose, vectorMetaObject, modalHeight, modalWidth } = this.props;const { activeIndex } = this.state;const navArray = [];const keyArray = [];@@ -46,7 +46,7 @@ class VectorDialog extends React.Component {const activeMetaArray = vectorMetaObject[keyArray[activeIndex]];return (- <div className='draggable-modal-content'>+ <div className='draggable-modal-content' ><ModalHeader toggle={toggleWithClose}><Nav tabs id="vector-meta-nav" className="vector-meta-nav">{navArray}diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.jsindex 1eaf9aa4a..cf19d6843 100644--- a/web/js/modules/vector-styles/util.js+++ b/web/js/modules/vector-styles/util.js@@ -5,6 +5,20 @@ import {} from 'lodash';import { Stroke, Style, Fill, Circle } from 'ol/style';import { setStyleFunction } from './selectors';+import {+ expression, Color,+ function as fn,+ latest as spec,+ featureFilter as createFilter,+ deref as derefLayers+} from '@mapbox/mapbox-gl-style-spec';+import { color } from 'onecolor';+import util from '../../util/util';+++const isExpression = expression.isExpression;+const createPropertyExpression = expression.createPropertyExpression;+export function getVectorStyleAttributeArray(layer) {var isCustomActive = false;@@ -87,10 +101,73 @@ export function selectedStyleFunction(feature, styleArray) {}});}+export function getColor() { }+export function getConditionalColors(color) {+ const array = Array.from(color);+ array.shift();+ let colors = [];+ let labels = [];+ let temp = [];+ const chunk = 2;+ // https://stackoverflow.com/a/8495740/4589331+ for (let i = 0, j = array.length; i < j; i += chunk) {+ temp = array.slice(i, i + chunk);+ if (temp.length === 2) {+ if (temp[0].length === 3 &&+ typeof temp[0][2] === 'string' &&+ typeof temp[1] === 'string'+ ) {+ labels.push(temp[0][2]);+ colors.push(temp[1])+ } else {+ console.warn('Irregular conditional');+ }+ } else if (temp.length === 1 && typeof temp[0] === 'string') {+ labels.push('Default');+ colors.push(temp[0])+ } else {+ console.warn('Irregular conditional');+ }+ }+ return { colors, labels }+}+export function getPaletteForStyle(layer, layerstyleLayerObject) {+ const styleLayerObject = layerstyleLayerObject.layers[0];+ const color = styleLayerObject.paint['line-color'] || styleLayerObject.paint['circle-color'] || styleLayerObject.paint['fill-color']+ const isConditionalStyling = styleLayerObject.paint ? isExpression(color) : false;+ let colors = [];+ let labels = [];+ if (isConditionalStyling) {+ const expressionObj = getConditionalColors(color);+ colors = expressionObj.colors;+ labels = expressionObj.labels;+ } else {+ colors.push(color);+ labels.push(layer.title);+ }+ return [{+ colors: colors,+ type: "classification",+ tooltips: labels,+ title: layer.title,+ id: layer.id + '0_legend'+ }]+}export function onMapClickGetVectorFeatures(pixels, map, state) {const metaArray = [];const selected = {};const config = state.config;+ const { screenHeight, screenWidth } = state.browser;+ const x = pixels[0];+ const isOnLeft = screenWidth - x >= screenWidth / 2;+ const modalWidth = 445;+ let offsetLeft = isOnLeft ? x + 20 : x - modalWidth - 20;+ if (offsetLeft < 0) {+ offsetLeft = 20+ } else if (offsetLeft + modalWidth > screenWidth) {+ offsetLeft = screenWidth - modalWidth - 20;+ }+map.forEachFeatureAtPixel(pixels, function (feature, layer) {const def = lodashGet(layer, 'wv.def');if (!def) return;@@ -119,7 +196,7 @@ export function onMapClickGetVectorFeatures(pixels, map, state) {selected[layerId].push(uniqueIdentifier);}});- return { selected, metaArray };+ return { selected, metaArray, offsetLeft };}export function updateVectorSelection(selectionObj, lastSelection, layers, type, state) {const vectorStyles = state.config.vectorStyles;