Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Fix offset top when clicking vector point #2144

Benjamin Kinge24b9c58e89c
diff --git a/web/js/components/map/ol-coordinates.js b/web/js/components/map/ol-coordinates.js
index 3d028407a..846b432a4 100644
--- a/web/js/components/map/ol-coordinates.js
+++ b/web/js/components/map/ol-coordinates.js
@@ -42,11 +42,12 @@ class OlCoordinates extends React.Component {
const metaArray = clickObj.metaArray || [];
const selected = clickObj.selected || {};
const offsetLeft = clickObj.offsetLeft || 10;
+ const offsetTop = clickObj.offsetTop || 100;
const dialogId = 'vector_dialog' + pixels[0] + pixels[1];
const isVectorModalOpen = modalState.id.includes('vector_dialog') && modalState.isOpen;
if (metaArray.length) {
- openVectorDiaglog(dialogId, metaArray, offsetLeft);
+ openVectorDiaglog(dialogId, metaArray, offsetLeft, offsetTop);
}
if (Object.entries(selected).length || (Object.entries(lastSelected).length && !isVectorModalOpen)) {
selectVectorFeatures(selected);
@@ -132,7 +133,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(changeCursor(bool))
},
- openVectorDiaglog: (dialogId, metaArray, offsetLeft) => {
+ openVectorDiaglog: (dialogId, metaArray, offsetLeft, offsetTop) => {
dispatch(openCustomContent(dialogId,
{
backdrop: false,
@@ -149,6 +150,7 @@ const mapDispatchToProps = dispatch => ({
width: 445,
height: 300,
offsetLeft,
+ offsetTop,
timeout: 150,
onClose: () => {
dispatch(selectVectorFeatures({}));
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index 269bf5d96..943dc3705 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -144,16 +144,26 @@ export function onMapClickGetVectorFeatures(pixels, map, state) {
const metaArray = [];
const selected = {};
const config = state.config;
- const { screenWidth } = state.browser;
+ const { screenWidth, screenHeight } = state.browser;
const x = pixels[0];
+ const y = pixels[1]
const isOnLeft = screenWidth - x >= screenWidth / 2;
+ const isOnTop = screenHeight - y >= screenHeight / 2;
const modalWidth = 445;
+ const modalHeight = 300;
let offsetLeft = isOnLeft ? x + 20 : x - modalWidth - 20;
+ let offsetTop = y - (modalHeight / 2);
+
if (offsetLeft < 0) {
- offsetLeft = 20
+ offsetLeft = 20;
} else if (offsetLeft + modalWidth > screenWidth) {
offsetLeft = screenWidth - modalWidth - 20;
}
+ if (offsetTop < 0) {
+ offsetTop = 20;
+ } else if (offsetTop + modalHeight > screenHeight) {
+ offsetTop = y - modalHeight;
+ }
map.forEachFeatureAtPixel(pixels, function (feature, layer) {
const def = lodashGet(layer, 'wv.def');
@@ -183,7 +193,7 @@ export function onMapClickGetVectorFeatures(pixels, map, state) {
selected[layerId].push(uniqueIdentifier);
}
});
- return { selected, metaArray, offsetLeft };
+ return { selected, metaArray, offsetLeft, offsetTop };
}
export function updateVectorSelection(selectionObj, lastSelection, layers, type, state) {
const vectorStyles = state.config.vectorStyles;