pythoninfowindowgoogle-earth

Add image title to infowindow of KML-point in Python


I created a KML point with a corresponding image in an infowindow.

test_point = kml.newpoint(name="test_name", description = '<img src="path/latest_image.jpg" width="500" height="500" align="left"/>',coords=[(10,70,100)]) 

The image is displayed correctly but I would like to add a title and a description of the image. Furthermore I want to change the background color of the window in which the image is displayed. How do I insert these elements? I have tried several approaches, but I do not know the correct structure.

Thanks in advance, help is appreciated!


Solution

  • You can force an image description to display in the infobox below the image by formatting it as a HTML table.

    The title of infobox uses the name field of the placemark, which you can use as the title of the image.

    import simplekml
    
    kml = simplekml.Kml()
    
    test_point = kml.newpoint(name="test_name",
      description = '''<table><tr><td><img src="path/latest_image.jpg"
     width="500" height="500" align="left"/></td></tr>
     <tr><td>Image caption</table></td></tr></table>''',
      coords=[(10,70,100)]) 
      
    kml.save("test.kml")
    

    You can further customize the infobox by applying a BalloonStyle. See API.