我有一個嵌入到我的網站的Google地圖,顯示人們創建的旅行傳單標記。在Google地圖infoWindowContent內部,我顯示旅行傳單標題和旅行傳單橫幅照片。 像這樣: 如果infoWindowContent中的某個字段爲空,Google地圖標記不會顯示
但是,當用戶決定不上傳旅遊傳單的橫幅照片,谷歌地圖在標記消失,因爲橫幅照片是空的。 下面是infoWindowContent短代碼:
var infoWindowContent = [
@foreach($flyer as $flyers)
[
'<div class="info_content">' +
'<a href="{{ $flyers->title }}">' +
'<img class="ui top aligned small image" src="/travel/{{ $flyers->thumbnail_path }}" alt="Test">' +
'<h5>{{ $flyers->title }}</h5>' +
'</a>' +
'</div>'
],
@endforeach
];
如何讓這個即使沒有旅遊傳單的橫幅照片顯示,標記仍然顯示在地圖上?
*********** EDIT ******************* 我嘗試這樣做:
@foreach($flyer as $flyers)
@if(empty($flyers->thumbnail_path))
var image = '<img class="ui top aligned small image" src="/travel/src/public/css/01.jpg" alt="Test">';
@else
var image = '<img class="ui top aligned small image" src="/travel/{{ $flyers->thumbnail_path }}" alt="Test">';
@endif
@endforeach
var infoWindowContent = [
@foreach($flyer as $flyers)
[
'<div class="info_content">' +
'<a href="{{ $flyers->title }}">' +
image +
'<h5>{{ $flyers->title }}</h5>' +
'</a>' +
'</div>'
],
@endforeach
];
但它仍然只返回存在的照片,並且如果沒有橫幅圖像則不顯示標記。我也試過:但沒有運氣。
@if(file_exists($flyers->thumbnail_path))
@if(file_exists(public_path($flyers->thumbnail_path)))
@if($flyers->thumbnail_path === '')
@if(isset($flyers->thumbnail_path))
想到的一個快速解決方案是某種錯誤處理。你應該首先檢查你想要注入到infoWindow中的數據是否存在,如果存在,那麼你顯示它就像你已經在做的那樣,如果沒有,那麼你應該爲infoWindow創建一個不同的內容。這只是一個可能的方法的想法,但記住數據未正確檢索並使您的應用程序正常工作的用例是一種很好的做法。 – G4bri3l
嗯....讓我看看 – David
檢查我的編輯頂部 – David