Improve pin click behavior: scroll to card if exists, pan map if not

- When clicking a pin, check if property card exists in loaded results
- If card exists: scroll to it smoothly and highlight (no map pan)
- If card doesn't exist: pan map to center on pin, reload results
- Add isCardScroll flag to ignore stray map events during card scroll
- Skip scroll reset in InfiniteScroll when pin-triggered pan
This commit is contained in:
Hanson.xyz Dev
2025-12-17 03:53:52 -06:00
parent 63b8fec917
commit 5522d18ada
2 changed files with 37 additions and 11 deletions
File diff suppressed because one or more lines are too long
@@ -706,7 +706,7 @@
}, },
/** /**
* Handle marker click - center map on pin, highlight card * Handle marker click - scroll to card if exists, otherwise pan map
*/ */
onMarkerClick: function(propertyId) { onMarkerClick: function(propertyId) {
var self = this; var self = this;
@@ -734,17 +734,32 @@
this.setMarkerColor(propertyId, 'amber'); this.setMarkerColor(propertyId, 'amber');
this.setMarkerZIndex(propertyId, 10000); // Amber on top this.setMarkerZIndex(propertyId, 10000); // Amber on top
// Immediately highlight card if visible (no scroll) // Check if card exists in the infinite scroll area
var $card = $('#property-' + propertyId); var $card = $('#property-' + propertyId);
if ($card.length) { if ($card.length) {
// Card exists - scroll to it and highlight, don't pan map
$card.addClass('property-card-highlighted'); $card.addClass('property-card-highlighted');
}
// Set flag to ignore any pending map events
this.isCardScroll = true;
// Smooth scroll to card
$('html, body').animate({
scrollTop: $card.offset().top - 120
}, 300, function() {
// Clear flag after scroll animation completes
setTimeout(function() {
self.isCardScroll = false;
}, 100);
});
} else {
// Card not in view - pan map to load new results
// Set flag so updateFromMap knows not to clear selection // Set flag so updateFromMap knows not to clear selection
this.isPinClickPan = true; this.isPinClickPan = true;
// Pan map to center on clicked pin (this triggers updateFromMap) // Pan map to center on clicked pin (this triggers updateFromMap)
this.map.panTo([markerInfo.lat, markerInfo.lng]); this.map.panTo([markerInfo.lat, markerInfo.lng]);
}
}, },
/** /**
@@ -1341,6 +1356,11 @@
* Called by PropertyMap when map moves/zooms * Called by PropertyMap when map moves/zooms
*/ */
updateFromMap: function(bounds, center) { updateFromMap: function(bounds, center) {
// If we're in the middle of scrolling to a card, ignore this map event
if (PropertyMap.isCardScroll) {
return;
}
this.mapBounds = bounds; this.mapBounds = bounds;
this.mapCenter = center; this.mapCenter = center;
this.isMapUpdate = true; this.isMapUpdate = true;
@@ -1355,8 +1375,9 @@
this.$results.html('<div class="property-results-loading"><div class="spinner"></div></div>'); this.$results.html('<div class="property-results-loading"><div class="spinner"></div></div>');
// Reset infinite scroll state before loading new content // Reset infinite scroll state before loading new content
// Skip scroll adjustment if this is a pin-triggered pan (we'll scroll to card later)
if (InfiniteScrollState.isEnabled) { if (InfiniteScrollState.isEnabled) {
InfiniteScroll.reset(); InfiniteScroll.reset(PropertyMap.isPinClickPan);
} }
// Block scroll state until user actually scrolls // Block scroll state until user actually scrolls
@@ -2327,11 +2348,16 @@
/** /**
* Reset (called on filter change) * Reset (called on filter change)
* @param {boolean} skipScroll - If true, don't adjust scroll position
*/ */
reset: function() { reset: function(skipScroll) {
InfiniteScrollState.pages = {}; InfiniteScrollState.pages = {};
InfiniteScrollState.pendingPage = null; InfiniteScrollState.pendingPage = null;
if (skipScroll) {
return;
}
// Scroll to bottom edge of .property-filters - bottom margin + masthead height // Scroll to bottom edge of .property-filters - bottom margin + masthead height
var $filters = $('.property-filters').first(); var $filters = $('.property-filters').first();
var $masthead = $('#masthead'); var $masthead = $('#masthead');