Add image title to infowindow of KML-point in Python

Question:

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!

Asked By: Sylvia

||

Answers:

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.

Answered By: CodeMonkey
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.