Skip to content

Commit b49a07d

Browse files
committed
Improve map panning and popup consistency: updated handleClick logic, fixed image size, truncated seller name
1 parent 9332881 commit b49a07d

File tree

2 files changed

+69
-30
lines changed

2 files changed

+69
-30
lines changed

src/components/shared/map/Map.tsx

+28-15
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,38 @@ const Map = ({
135135
// Function to handle marker click
136136
const handleMarkerClick = (sellerCoordinates: LatLngTuple) => {
137137
if (!mapRef.current) return;
138-
138+
139139
const map = mapRef.current;
140140
const currentZoom = map.getZoom();
141-
142-
// Set the view to the seller's coordinates
143-
map.setView(sellerCoordinates, currentZoom, { animate: true });
144-
// Get the position of the clicked marker
141+
const maxZoom = map.getMaxZoom();
142+
143+
// Check if zoom & pan have already been applied
144+
const hasZoomed = mapRef.current?.getContainer().dataset.zoomApplied === "true";
145+
146+
if (hasZoomed) return; // Prevent further zoom & pan on second click
147+
148+
// Apply zoom increase only once
149+
const targetZoom = Math.min(currentZoom + 3, maxZoom);
150+
const zoomLevel = targetZoom;
151+
152+
// Convert marker lat/lng to pixel position
145153
const markerPoint = map.latLngToContainerPoint(sellerCoordinates);
146-
// Get the width and height of the map container
147-
const mapSize = map.getSize();
148-
const mapWidth = mapSize.x;
149-
const mapHeight = mapSize.y;
150-
// Calculate the offsets to center the marker in the map view
151-
const panOffset = L.point(mapWidth / 2 - markerPoint.x, mapHeight / 2 - markerPoint.y);
152-
153-
// Pan the map by the calculated offset
154-
map.panBy(panOffset, { animate: false }); // Disable animation to make the movement instant
154+
155+
// Adjust popup position: move **left (-X) and UP (-Y)**
156+
const offsetX = -3; // Slight left shift
157+
const offsetY = 28; // Moves UP instead of down
158+
const panOffset = L.point(offsetX, offsetY);
159+
160+
// Calculate new center position based on offset
161+
const newCenter = map.containerPointToLatLng(markerPoint.subtract(panOffset));
162+
163+
// Apply view changes **only once**
164+
map.setView(newCenter, zoomLevel, { animate: false });
165+
166+
// Mark zoom as applied (prevents further zooming & movement)
167+
mapRef.current.getContainer().dataset.zoomApplied = "true";
155168
};
156-
169+
157170
useEffect(() => {
158171
if (mapRef.current) {
159172
fetchInitialCoordinates(); // Fetch sellers when map is ready

src/components/shared/map/MapMarkerPopup.tsx

+41-15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ const MapMarkerPopup = ({ seller }: { seller: any }) => {
1616
? seller.image
1717
: '/images/logo.svg';
1818

19+
const truncateChars = (text: string, maxChars: number): string => {
20+
return text.length > maxChars ? text.slice(0, maxChars) + '...' : text;
21+
};
22+
23+
24+
25+
1926
const translateSellerCategory = (category: string): string => {
2027
switch (category) {
2128
case 'activeSeller':
@@ -35,26 +42,45 @@ const MapMarkerPopup = ({ seller }: { seller: any }) => {
3542
<div style={{ position: 'relative', zIndex: 20, padding: '10px' }}>
3643
{/* Seller name and type - Close with a small gap */}
3744
<div style={{ textAlign: 'center', marginBottom: '5px' }}>
38-
<h2 style={{ fontWeight: 'bold', fontSize: '18px', marginBottom: '2px' }}>
39-
{seller.name}
40-
</h2>
45+
<h2
46+
style={{
47+
fontWeight: 'bold',
48+
fontSize: '15px',
49+
marginBottom: '2px',
50+
whiteSpace: 'nowrap',
51+
overflow: 'hidden',
52+
textOverflow: 'ellipsis',
53+
}}
54+
>
55+
{truncateChars(seller.name, 12)} {/* Adjust limit as needed */}
56+
</h2>
57+
58+
59+
4160
{seller.seller_type && (
42-
<p style={{ fontSize: '14px', color: '#6B7280', marginTop: '0px', marginBottom: '4px' }}>
43-
{translateSellerCategory(seller.seller_type)}
44-
</p>
61+
<p style={{ fontSize: '14px', color: '#6B7280', marginTop: '0px', marginBottom: '4px' }}>
62+
{translateSellerCategory(seller.seller_type)}
63+
</p>
64+
4565
)}
4666
</div>
4767

4868
{/* Seller image - Close to seller type */}
49-
<div style={{ textAlign: 'center', marginBottom: '5px' }}>
50-
<Image
51-
src={imageUrl}
52-
alt="Seller Image"
53-
width={150}
54-
height={50}
55-
style={{ borderRadius: '0px', objectFit: 'cover', display: 'block', margin: '0 auto' }}
56-
/>
57-
</div>
69+
<div style={{ width: '150px', height: '70px', overflow: 'hidden', margin: '0 auto', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
70+
<Image
71+
src={imageUrl}
72+
alt="Seller Image"
73+
width={imageUrl === '/images/logo.svg' ? 80 : 150}
74+
height={imageUrl === '/images/logo.svg' ? 40 : 70}
75+
style={{
76+
objectFit: imageUrl === '/images/logo.svg' ? 'contain' : 'cover',
77+
width: imageUrl === '/images/logo.svg' ? '80px' : '100%',
78+
height: imageUrl === '/images/logo.svg' ? '40px' : '100%',
79+
}}
80+
/>
81+
</div>
82+
83+
5884

5985
{/* Trust-o-meter Label - Close to image */}
6086
<p style={{ textAlign: 'center', fontWeight: 'bold', fontSize: '14px', marginBottom: '2px' }}>

0 commit comments

Comments
 (0)