kadoshms / react-jvectormap

A react wrapper for jvectormap maps
MIT License
98 stars 70 forks source link

Map resets zoom after marker selection. #78

Closed natikos closed 2 years ago

natikos commented 3 years ago

I handle selection markers by myself. When user zoom in and selects a marker, then map resets zoom and go to full-size mode (scale = 1).

There are appropriate functions.

          onMarkerClick={(e, index) => {
              const isNew = !shownLabelIndexes.includes(index);
              const newArray = isNew
                ? [...shownLabelIndexes, index]
                : shownLabelIndexes.filter(el => el !== index);
              setShownLabelIndexes(newArray);
              // map.setScale(markerSelectionZoom);
              map.scale = markerSelectionZoom;
            }}
         onViewportChange={(e, scale) => {
              if (map && scale !== 1) {
                markerSelectionZoom = scale;
                map.scale = scale;
              }
            }}

and here my variables and state in components:

  const [shownLabelIndexes, setShownLabelIndexes] = useState([]);
  const [ref, { width }] = useDimensions();
  const mapRef = useRef(null);
  const map = mapRef.current && mapRef.current.getMapObject();
  let markerSelectionZoom = 1;
kadoshms commented 2 years ago

Closing for inactivity.