From 7a6949aa2e3c95df0d0bb3a0ceef42d5f5fd84b0 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Fri, 10 May 2019 11:33:59 -0400 Subject: [PATCH] Account for the width of open panes when centering the map on issues --- modules/core/validator.js | 2 +- modules/renderer/map.js | 15 +++++++++++++++ modules/ui/entity_issues.js | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/core/validator.js b/modules/core/validator.js index 80c3ed10b..13c820f8c 100644 --- a/modules/core/validator.js +++ b/modules/core/validator.js @@ -114,7 +114,7 @@ export function coreValidator(context) { if (extent) { var setZoom = Math.max(context.map().zoom(), 19); - context.map().centerZoomEase(extent.center(), setZoom); + context.map().unobscuredCenterZoomEase(extent.center(), setZoom); // select the first entity if (issue.entityIds && issue.entityIds.length) { diff --git a/modules/renderer/map.js b/modules/renderer/map.js index 2ea47f1c7..62c5eec88 100644 --- a/modules/renderer/map.js +++ b/modules/renderer/map.js @@ -738,6 +738,21 @@ export function rendererMap(context) { return map; }; + map.unobscuredCenterZoomEase = function(loc, zoom) { + var offset = map.unobscuredOffset(); + var locPx = projection(loc); + var offsetLocPx = [locPx[0] + offset[0], locPx[1] + offset[1]]; + var offsetLoc = projection.invert(offsetLocPx); + map.centerZoomEase(offsetLoc, zoom); + }; + + map.unobscuredOffset = function() { + var openPane = d3_select('.map-panes .map-pane.shown'); + if (!openPane.empty()) { + return [openPane.node().offsetWidth/2, 0]; + } + return [0, 0]; + }; map.zoom = function(z2) { if (!arguments.length) { diff --git a/modules/ui/entity_issues.js b/modules/ui/entity_issues.js index 7e396775c..074079a7f 100644 --- a/modules/ui/entity_issues.js +++ b/modules/ui/entity_issues.js @@ -102,7 +102,7 @@ export function uiEntityIssues(context) { var extent = d.extent(context.graph()); if (extent) { var setZoom = Math.max(context.map().zoom(), 19); - context.map().centerZoomEase(extent.center(), setZoom); + context.map().unobscuredCenterZoomEase(extent.center(), setZoom); } });