Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_placemark_style(self):
style = styles.Style(styles=[styles.PolyStyle(color='7f000000')])
place = kml.Placemark(styles=[style])
place2 = kml.Placemark()
place2.append_style(style)
expected = """
1
7f000000
1
1
def test_create_document_style(self):
style = styles.Style(styles=[styles.PolyStyle(color='7f000000')])
doc = kml.Document(styles=[style])
doc2 = kml.Document()
doc2.append_style(style)
expected = """
1
7f000000
1
1
"""
k = kml.KML()
k.from_string(doc)
self.assertEqual(len(list(k.features())), 1)
self.assertTrue(
isinstance(list(list(k.features())[0].styles())[0], styles.StyleMap)
)
sm = list(list(list(k.features())[0].styles()))[0]
self.assertTrue(isinstance(sm.normal, styles.Style))
self.assertEqual(len(list(sm.normal.styles())), 1)
self.assertTrue(isinstance(list(sm.normal.styles())[0], styles.LabelStyle))
self.assertTrue(isinstance(sm.highlight, styles.Style))
self.assertTrue(isinstance(sm.highlight, styles.Style))
self.assertEqual(len(list(sm.highlight.styles())), 2)
self.assertTrue(isinstance(list(sm.highlight.styles())[0], styles.LineStyle))
self.assertTrue(isinstance(list(sm.highlight.styles())[1], styles.PolyStyle))
k2 = kml.KML()
k2.from_string(k.to_string())
self.assertEqual(k.to_string(), k2.to_string())
# Convert the flight path array [time, lat, lon, alt, comment] into a LineString object.
track_points = []
for _point in flight_path:
# Flight path array is in lat,lon,alt order, needs to be in lon,lat,alt
track_points.append([_point[2],_point[1],_point[3]])
_flight_geom = LineString(track_points)
# Define the Line and Polygon styles, which are used for the flight path, and the extrusions (if enabled)
flight_track_line_style = fastkml.styles.LineStyle(
ns=ns,
color=track_color,
width=track_width)
flight_extrusion_style = fastkml.styles.PolyStyle(
ns=ns,
color=poly_color)
flight_track_style = fastkml.styles.Style(
ns=ns,
styles=[flight_track_line_style, flight_extrusion_style])
# Generate the Placemark which will contain the track data.
flight_line = fastkml.kml.Placemark(
ns=ns,
id=placemark_id,
name=name,
styles=[flight_track_style])
# Add the track data to the Placemark
flight_line.geometry = fastkml.geometry.Geometry(
def __init__(
self, ns=None, id=None, color=None, colorMode=None, fill=1, outline=1
):
super(PolyStyle, self).__init__(ns, id, color, colorMode)
self.fill = fill
self.outline = outline
def from_element(self, element):
super(Style, self).from_element(element)
style = element.find('%sIconStyle' % self.ns)
if style is not None:
thestyle = IconStyle(self.ns)
thestyle.from_element(style)
self.append_style(thestyle)
style = element.find('%sLineStyle' % self.ns)
if style is not None:
thestyle = LineStyle(self.ns)
thestyle.from_element(style)
self.append_style(thestyle)
style = element.find('%sPolyStyle' % self.ns)
if style is not None:
thestyle = PolyStyle(self.ns)
thestyle.from_element(style)
self.append_style(thestyle)
style = element.find('%sLabelStyle' % self.ns)
if style is not None:
thestyle = LabelStyle(self.ns)
thestyle.from_element(style)
self.append_style(thestyle)
style = element.find('%sBalloonStyle' % self.ns)
if style is not None:
thestyle = BalloonStyle(self.ns)
thestyle.from_element(style)
self.append_style(thestyle)