簡體   English   中英

在Leaflet Popup中顯示圖像

[英]Show Image in Leaflet Popup

我正在嘗試使用wunderground的api,Leaflet和Cloudmade在地圖標記中顯示天氣圖標。 我有文字顯示和帶有圖標圖像的變量,但我不知道如何讓它顯示。 這是我的代碼:

jQuery(document).ready(function($) {
    $.ajax({
          url: "http://api.wunderground.com/api/cd48ac26fb540679/conditions/q/pws:KCASANFR128.json",
          dataType: "jsonp",
          success: function(parsed_json) {
              var location = parsed_json['current_observation']['observation_location']['city'];
              var temp_f = parsed_json['current_observation']['temp_f'];
              var icon = parsed_json['current_observation']['icon_url'];
              marker1.bindPopup("Current temperature in " +location+ " is: " + temp_f).openPopup();
        }
    });
});

我試過這個沒有成功:

marker1.bindPopup( <img src=icon> "Current temperature in " +location+ " is: " + temp_f).openPopup();

有什么建議?

標記的bindPopup方法只是將HTML內容作為字符串,因此您還需要用引號括住標記 - 類似於

marker1.bindPopup( "<img src=" + icon_url + "/> Current temperature in " + location + " is: " + temp_f)

應該為你工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM