def make_colored_track(self, globals, values, scale, altitude_mode, scale_chart=True, **folder_options): style_url = globals.stock.check_hide_children_style.url() folder = kml.Folder(name='Colored by %s' % scale.title, styleUrl=style_url, **folder_options) styles = [kml.Style(kml.LineStyle(color=color, width=self.width)) for color in scale.colors()] discrete_values = map(scale.discretize, values) for sl in util.runs(discrete_values): coordinates = self.track.coords[sl.start:sl.stop + 1] line_string = kml.LineString(coordinates=coordinates, altitudeMode=self.altitude_mode) style_url = kml.styleUrl(styles[discrete_values[sl.start]].url()) placemark = kml.Placemark(style_url, line_string) folder.add(placemark) if scale_chart: href = self.make_scale_chart(globals, scale).get_url() icon = kml.Icon(href=kml.CDATA(href)) overlay_xy = kml.overlayXY(x=0, xunits='fraction', y=1, yunits='fraction') screen_xy = kml.screenXY(x=0, xunits='fraction', y=1, yunits='fraction') size = kml.size(x=0, xunits='fraction', y=0, yunits='fraction') screen_overlay = kml.ScreenOverlay(icon, overlay_xy, screen_xy, size) folder.add(screen_overlay) return kmz.kmz(folder).add_roots(*styles)
def make_none_folder(self, visibility): icon = kml.Icon(href=self.pixel_url) overlay_xy = kml.overlayXY(x=0, xunits='fraction', y=0, yunits='fraction') screen_xy = kml.screenXY(x=0, xunits='fraction', y=0, yunits='fraction') size = kml.size(x=0, xunits='fraction', y=0, yunits='fraction') screen_overlay = kml.ScreenOverlay(icon, overlay_xy, screen_xy, size, visibility=visibility) style_url = self.check_hide_children_style.url() return kml.Folder(screen_overlay, name='None', styleUrl=style_url)
def make_graph(self, globals, values, scale): href = self.make_graph_chart(globals, values, scale).get_url() icon = kml.Icon(href=kml.CDATA(href)) overlay_xy = kml.overlayXY(x=0, xunits='fraction', y=0, yunits='fraction') screen_xy = kml.screenXY(x=0, xunits='fraction', y=16, yunits='pixels') size = kml.size(x=0, xunits='fraction', y=0, yunits='fraction') screen_overlay = kml.ScreenOverlay(icon, overlay_xy, screen_xy, size) name = scale.title.capitalize() + " graph" style_url = globals.stock.check_hide_children_style.url() folder = kml.Folder(screen_overlay, name=name, styleUrl=style_url, visibility=0) return folder