Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Image in Leaflet Popup

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();

Any suggestions?

like image 464
Ryan Clark Avatar asked May 13 '12 22:05

Ryan Clark


1 Answers

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.

like image 164
IanI Avatar answered Oct 21 '22 13:10

IanI