From b6635e5a517dace09fa9187f8950af1b6d517ee5 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Sat, 15 Feb 2025 11:48:40 +0800 Subject: [PATCH] fix: fix map marker click and handle null values - Comment out marker click listener to fix a bug - Update _map.html.erb to handle null values in the city - Improve error handling This commit addresses a bug where clicking the map marker caused unexpected behavior. The changes involve commenting out the click listener to fix the issue, and updating the view template to handle potential null values in the city object to prevent unexpected behavior. --- app/javascript/controllers/map_controller.js | 6 +++--- app/views/cities/_map.html.erb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/javascript/controllers/map_controller.js b/app/javascript/controllers/map_controller.js index 5956afe..cca4004 100644 --- a/app/javascript/controllers/map_controller.js +++ b/app/javascript/controllers/map_controller.js @@ -43,9 +43,9 @@ export default class extends Controller { const marker = new mapboxgl.Marker() .setLngLat([this.longitudeValue, this.latitudeValue]) .addTo(this.map); - marker.getElement().addEventListener('click', () => { - this.showPopup(); - }); + // marker.getElement().addEventListener('click', () => { + // this.showPopup(); + // }); // 默认弹出窗口 // this.showPopup(); diff --git a/app/views/cities/_map.html.erb b/app/views/cities/_map.html.erb index ae6e00c..2f5b375 100644 --- a/app/views/cities/_map.html.erb +++ b/app/views/cities/_map.html.erb @@ -8,7 +8,7 @@ data-map-longitude-value="<%= @city.longitude %>" data-map-token-value="<%= Rails.application.credentials.dig(:mapbox, :token) %>" data-map-weather-art-value="<%= @city.latest_weather_art.to_json %>" - data-map-weather-art-url-value="<%= rails_blob_url(@city.latest_weather_art.webp_image.processed ) %>" + data-map-weather-art-url-value="<%= rails_blob_url(@city&.latest_weather_art&.webp_image&.processed ) if @city&.latest_weather_art&.image&.attached %>" class="h-[500px] w-full rounded-b-2xl z-10" style="touch-action: none" >