From 7da2cda6a735ce8b14a3aecd24653c76d8127583 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mi=C5=82osz=20Grocholewski?= <m.grocholewski@atcomp.pl>
Date: Tue, 5 Nov 2024 14:00:52 +0100
Subject: [PATCH] Resolve MIN-57 "Feat/ reactant product"

---
 .../utils/shapes/elements/BaseMultiPolygon.ts        |  2 +-
 .../MapViewerVector/utils/shapes/layer/Layer.ts      |  3 ++-
 .../utils/shapes/reaction/Reaction.ts                | 12 ++++++++----
 .../MapViewerVector/utils/shapes/text/Text.ts        |  2 +-
 .../Map/MapViewer/utils/config/useOlMapView.ts       |  5 +++--
 5 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon.ts b/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon.ts
index 05baa60d..240901b7 100644
--- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon.ts
+++ b/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon.ts
@@ -150,7 +150,7 @@ export default abstract class BaseMultiPolygon {
     this.feature = new Feature({
       geometry: new MultiPolygon(this.polygons),
       getTextScale: (resolution: number): number => {
-        const maxZoom = mapInstance?.getView().getMaxZoom();
+        const maxZoom = mapInstance?.getView().get('originalMaxZoom');
         if (maxZoom) {
           const minResolution = mapInstance?.getView().getResolutionForZoom(maxZoom);
           if (minResolution) {
diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.ts b/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.ts
index bd6fac33..0554c9db 100644
--- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.ts
+++ b/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.ts
@@ -283,7 +283,8 @@ export default class Layer {
   };
 
   protected getStyle(feature: FeatureLike, resolution: number): Style | Array<Style> | void {
-    const minResolution = this.mapInstance?.getView().getMinResolution();
+    const maxZoom = this.mapInstance?.getView().get('originalMaxZoom');
+    const minResolution = this.mapInstance?.getView().getResolutionForZoom(maxZoom);
     const style = feature.get('style');
     if (!minResolution || !style) {
       return [];
diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.ts b/src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.ts
index 2535e785..56f57fe4 100644
--- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.ts
+++ b/src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.ts
@@ -251,13 +251,16 @@ export default class Reaction {
 
   protected getOperator(operator: Operator): Feature<Circle> {
     const firstSegment = operator.line.segments[0];
+    let zIndex: number;
     let radius: number;
 
     if (operator.operatorText) {
+      zIndex = this.zIndex + 1;
       radius = Math.abs(
         this.pointToProjection({ x: 0, y: 0 })[0] - this.pointToProjection({ x: 6, y: 0 })[0],
       );
     } else {
+      zIndex = this.zIndex;
       radius = Math.abs(
         this.pointToProjection({ x: 0, y: 0 })[0] - this.pointToProjection({ x: 1.8, y: 0 })[0],
       );
@@ -270,10 +273,10 @@ export default class Reaction {
 
     const circleStyle = getStyle({
       geometry: circle,
-      zIndex: this.zIndex + 1,
+      zIndex,
       lineWidth: 1,
-      borderColor: this.line.color,
-      fillColor: this.line.color,
+      borderColor: operator.line.color,
+      fillColor: operator.line.color,
     });
 
     if (operator.operatorText) {
@@ -299,7 +302,8 @@ export default class Reaction {
   }
 
   protected getStyle(feature: FeatureLike, resolution: number): Style | Array<Style> | void {
-    const minResolution = this.mapInstance?.getView().getMinResolution();
+    const maxZoom = this.mapInstance?.getView().get('originalMaxZoom');
+    const minResolution = this.mapInstance?.getView().getResolutionForZoom(maxZoom);
     const style = feature.get('style');
     if (!minResolution || !style) {
       return [];
diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.ts b/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.ts
index a5a72e4c..6d84b083 100644
--- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.ts
+++ b/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.ts
@@ -81,7 +81,7 @@ export default class Text {
     this.feature = new Feature({
       geometry: this.point,
       getTextScale: (resolution: number): number => {
-        const maxZoom = mapInstance?.getView().getMaxZoom();
+        const maxZoom = mapInstance?.getView().get('originalMaxZoom');
         if (maxZoom) {
           const minResolution = mapInstance?.getView().getResolutionForZoom(maxZoom);
           if (minResolution) {
diff --git a/src/components/Map/MapViewer/utils/config/useOlMapView.ts b/src/components/Map/MapViewer/utils/config/useOlMapView.ts
index 3193f5fa..bdaabeaf 100644
--- a/src/components/Map/MapViewer/utils/config/useOlMapView.ts
+++ b/src/components/Map/MapViewer/utils/config/useOlMapView.ts
@@ -57,11 +57,12 @@ export const useOlMapView = ({ mapInstance }: UseOlMapViewInput): MapConfig['vie
       zoom: mapInitialPosition.z,
       showFullExtent: OPTIONS.showFullExtent,
       zoomFactor: 2 ** (1 / 3),
+      originalMaxZoom: mapSize.maxZoom * 3,
       maxZoom:
-        mapSize.width < 1.5 * mapSize.tileSize || mapSize.height < 1.5 * mapSize.tileSize
+        mapSize.width < 1.6 * mapSize.tileSize || mapSize.height < 1.6 * mapSize.tileSize
           ? Math.max(15, mapSize.maxZoom * 3)
           : mapSize.maxZoom * 3,
-      minZoom: mapSize.minZoom,
+      minZoom: mapSize.minZoom * 3,
       extent,
     }),
     [
-- 
GitLab