显示图像在单张弹出 [英] Show Image in Leaflet Popup
本文介绍了显示图像在单张弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让天气图标使用wunderground的API,单张及Cloudmade在地图标记来显示。我已经得到了文本显示和图标图像的变量,但我不知道如何得到它显示。这是我的code:
I'm trying to get the weather icon to show in a map marker using wunderground's api, Leaflet and Cloudmade. I've got the text showing and a variable with the icon image, but I'm not sure how to get it to show. Here's my code:
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();
}
});
});
我想这没有成功:
I tried this with no success:
marker1.bindPopup( <img src=icon> "Current temperature in " +location+ " is: " + temp_f).openPopup();
有什么建议?
推荐答案
标记的bindPopup方法只需要HTML内容为一个字符串,所以你需要围绕你的标签与报价,以及 - 有点像
The marker's bindPopup method just takes HTML content as a string, so you'll need to surround your tags with quotes as well - something like
marker1.bindPopup( "<img src=" + icon_url + "/> Current temperature in " + location + " is: " + temp_f)
应该为你工作。
ought to work for you.
这篇关于显示图像在单张弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文