Skip to content

Commit 0c36701

Browse files
committed
SiteMap do not draw non-instersecting polygons
1 parent d0ec05c commit 0c36701

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/components/SiteMap/SiteMapFeature.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ var SiteMapFeature = function SiteMapFeature(props) {
294294

295295

296296
var neonContextHydrated = state.neonContextHydrated,
297+
mapBounds = state.map.bounds,
297298
focusLocation = state.focusLocation.current,
298299
featureData = state.featureData[parentFeature ? parentFeature.type : featureType][parentFeature ? parentFeature.KEY : featureKey];
299300

@@ -1397,6 +1398,15 @@ var SiteMapFeature = function SiteMapFeature(props) {
13971398

13981399

13991400
if (featureShape === 'Polygon') {
1401+
// If the polygon boundary does not intersect the map bounds then do not render it
1402+
// We see this when the map bounds are entirely contained within a boundary but the
1403+
// feature is still visible, resulting in an always-on popup with no context otherwise
1404+
if (!(0, _SiteMapUtils.calculateLocationsInBounds)({
1405+
X: shapeData
1406+
}, mapBounds).length) {
1407+
return null;
1408+
}
1409+
14001410
shapeProps = _extends({}, featureStyle || {}, polygonInteractionProps); // ReactLeaflet does not suport the mask prop, so add it as an unused class.
14011411
// The LayoutEffect in SiteMapLeaflet.jsx then applies it as a mask attribute.
14021412

src/lib_components/components/SiteMap/SiteMapFeature.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
import SiteMapContext from './SiteMapContext';
4242
import {
4343
getHref,
44+
calculateLocationsInBounds,
4445
FEATURES,
4546
FEATURE_TYPES,
4647
NLCD_CLASSES,
@@ -238,6 +239,7 @@ const SiteMapFeature = (props) => {
238239
*/
239240
const {
240241
neonContextHydrated,
242+
map: { bounds: mapBounds },
241243
focusLocation: { current: focusLocation },
242244
featureData: {
243245
[parentFeature ? parentFeature.type : featureType]: {
@@ -1326,6 +1328,10 @@ const SiteMapFeature = (props) => {
13261328
}
13271329
// Polygon
13281330
if (featureShape === 'Polygon') {
1331+
// If the polygon boundary does not intersect the map bounds then do not render it
1332+
// We see this when the map bounds are entirely contained within a boundary but the
1333+
// feature is still visible, resulting in an always-on popup with no context otherwise
1334+
if (!calculateLocationsInBounds({ X: shapeData }, mapBounds).length) { return null; }
13291335
shapeProps = {
13301336
...featureStyle || {},
13311337
...polygonInteractionProps,

src/lib_components/components/SiteMap/__tests__/SiteMapUtils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ describe('SiteMap - SiteMapUtils', () => {
111111
'X', 'Y', 'Z',
112112
]);
113113
});
114+
test('correctly excludes boundaries that do not intersect the bounds', () => {
115+
const smallerBounds = { lat: [15, 20], lng: [-6, 0] };
116+
expect(calculateLocationsInBounds(coordLocations, smallerBounds)).toStrictEqual([
117+
'Y',
118+
]);
119+
});
114120
test('correctly returns empty set for invalid inputs', () => {
115121
expect(calculateLocationsInBounds({})).toStrictEqual([]);
116122
expect(calculateLocationsInBounds('bad locations')).toStrictEqual([]);

0 commit comments

Comments
 (0)