From 6ef3f680b4bb9ce4f106d28430d3c2a0a1ca8e71 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Mon, 24 May 2021 11:36:46 +1000 Subject: [PATCH] Fix performance issues with editing map fog with lots of shapes --- src/components/map/MapFog.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/components/map/MapFog.js b/src/components/map/MapFog.js index 43b4ea4..963f677 100644 --- a/src/components/map/MapFog.js +++ b/src/components/map/MapFog.js @@ -2,6 +2,7 @@ import React, { useState, useEffect, useCallback } from "react"; import shortid from "shortid"; import { Group, Line } from "react-konva"; import useImage from "use-image"; +import Color from "color"; import diagonalPattern from "../../images/DiagonalPattern.png"; @@ -489,6 +490,17 @@ function MapFog({ const holes = shape.data.holes && shape.data.holes.map((hole) => hole.reduce(reducePoints, [])); + const opacity = editable + ? !shape.visible + ? editOpacity / 2 + : editOpacity + : 1; + // Control opacity only on fill as using opacity with stroke leads to performance issues + const fill = new Color(colors[shape.color] || shape.color).alpha(opacity); + const stroke = + editable && active + ? colors.lightGray + : colors[shape.color] || shape.color; return (