示例#1
0
 def make_shadow_folder(self, globals):
     if not self.track.elevation_data:
         return kmz.kmz()
     style_url = globals.stock.radio_folder_style.url()
     folder = kmz.kmz(kml.Folder(name='Shadow', open=0, styleUrl=style_url))
     folder.add(globals.stock.invisible_none_folder)
     style = kml.Style(kml.LineStyle(color='ff000000', width=1))
     folder.add(
         self.make_solid_track(globals,
                               style,
                               'clampToGround',
                               name='Normal'))
     line_style = kml.LineStyle(color='00000000', width=1)
     poly_style = kml.PolyStyle(color='80000000')
     style = kml.Style(line_style, poly_style)
     folder.add(
         self.make_solid_track(globals,
                               style,
                               'absolute',
                               True,
                               name='Extrude',
                               visibility=0))
     style = kml.Style(kml.LineStyle(color=self.color, width=self.width))
     folder.add(
         self.make_solid_track(globals,
                               style,
                               'clampToGround',
                               name='Solid color',
                               visibility=0))
     return folder
示例#2
0
 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)
示例#3
0
 def make_track_folder(self, globals):
     style_url = globals.stock.radio_folder_style.url()
     folder = kmz.kmz(kml.Folder(name='Track', open=1, styleUrl=style_url))
     folder.add(globals.stock.invisible_none_folder)
     if self.track.elevation_data:
         visibility = globals.default_track == 'climb'
         folder.add(
             self.make_colored_track(globals,
                                     self.track.climb,
                                     globals.scales.climb,
                                     'absolute',
                                     visibility=visibility))
         visibility = globals.default_track == 'altitude'
         folder.add(
             self.make_colored_track(globals,
                                     self.track.ele,
                                     globals.scales.altitude,
                                     'absolute',
                                     visibility=visibility))
         visibility = globals.default_track == 'tec'
         folder.add(
             self.make_colored_track(globals,
                                     self.track.tec,
                                     globals.scales.tec,
                                     'absolute',
                                     visibility=visibility))
     visibility = globals.default_track == 'speed'
     folder.add(
         self.make_colored_track(globals,
                                 self.track.speed,
                                 globals.scales.speed,
                                 self.altitude_mode,
                                 visibility=visibility))
     if hasattr(self.track, 'tas'):
         visibility = globals.default_track == 'tas'
         folder.add(
             self.make_colored_track(globals,
                                     self.track.tas,
                                     globals.scales.tas,
                                     self.altitude_mode,
                                     visibility=visibility))
     visibility = globals.default_track == 'time'
     folder.add(
         self.make_colored_track(globals,
                                 self.track.t,
                                 globals.scales.t,
                                 self.altitude_mode,
                                 scale_chart=False,
                                 visibility=visibility))
     visibility = globals.default_track == 'solid_color'
     style = kml.Style(kml.LineStyle(color=self.color, width=self.width))
     folder.add(
         self.make_solid_track(globals,
                               style,
                               self.altitude_mode,
                               name='Solid color',
                               visibility=visibility))
     return folder
示例#4
0
 def make_analysis_style(self, color, bgcolors, rows):
     text = '<h3>$[name]</h3>$[description]' + make_table(rows, bgcolors)
     bg_color = 'ff' + ''.join(reversed(re.findall(r'..', bgcolors[1][1:])))
     balloon_style = kml.BalloonStyle(text=kml.CDATA(text), bgColor=bg_color)
     icon_style = kml.IconStyle(self.icons[0], color=color,
                                scale=self.icon_scales[0])
     label_style = kml.LabelStyle(color=color, scale=self.label_scales[0])
     line_style = kml.LineStyle(color=color, width=4)
     return kml.Style(balloon_style, icon_style, label_style, line_style)
示例#5
0
 def __init__(self):
     self.kmz = kmz.kmz()
     #
     self.icon_scales = [sqrt(x) for x in [0.6, 0.5, 0.4, 0.3]]
     self.icons = [kml.Icon.palette(4, i) for i in [25, 25, 24, 24]]
     self.label_scales = [sqrt(x) for x in [0.6, 0.5, 0.4, 0.3]]
     #
     list_style = kml.ListStyle(listItemType='radioFolder')
     self.radio_folder_style = kml.Style(list_style)
     self.kmz.add_roots(self.radio_folder_style)
     #
     list_style = kml.ListStyle(listItemType='checkHideChildren')
     self.check_hide_children_style = kml.Style(list_style)
     self.kmz.add_roots(self.check_hide_children_style)
     #
     bgcolors = '#ffcccc #ffdddd'.split()
     rows = [
         ['Altitude gain', '$[altitude_change]m'],
         ['Average climb', '$[average_climb]m/s'],
         ['Maximum climb', '$[maximum_climb]m/s'],
         ['Peak climb', '$[peak_climb]m/s'],
         ['Efficiency', '$[efficiency]%'],
         ['Start altitude', '$[start_altitude]m'],
         ['Finish altitude', '$[finish_altitude]m'],
         ['Start time', '$[start_time]'],
         ['Finish time', '$[finish_time]'],
         ['Duration', '$[duration]'],
         ['Accumulated altitude gain', '$[accumulated_altitude_gain]m'],
         ['Accumulated altitude loss', '$[accumulated_altitude_loss]m'],
         ['Drift', '$[average_speed]km/h $[drift_direction]'],
     ]
     self.thermal_style = self.make_analysis_style('cc3333ff', bgcolors,
                                                   rows)
     self.kmz.add_roots(self.thermal_style)
     bgcolors = '#ccccff #ddddff'.split()
     rows = [
         ['Altitude change', '$[altitude_change]m'],
         ['Average descent', '$[average_climb]m/s'],
         ['Maximum descent', '$[maximum_descent]m/s'],
         ['Peak descent', '$[peak_descent]m/s'],
         ['Start altitude', '$[start_altitude]m'],
         ['Finish altitude', '$[finish_altitude]m'],
         ['Start time', '$[start_time]'],
         ['Finish time', '$[finish_time]'],
         ['Duration', '$[duration]'],
         ['Accumulated altitude gain', '$[accumulated_altitude_gain]m'],
         ['Accumulated altitude loss', '$[accumulated_altitude_loss]m'],
     ]
     self.dive_style = self.make_analysis_style('ccff3333', bgcolors, rows)
     bgcolors = '#ccffcc #ddffdd'.split()
     rows = [
         ['Altitude change', '$[altitude_change]m'],
         ['Average descent', '$[average_climb]m/s'],
         ['Distance', '$[distance]km'],
         ['Average glide ratio', '$[average_ld]:1'],
         ['Average speed', '$[average_speed]km/h'],
         ['Start altitude', '$[start_altitude]m'],
         ['Finish altitude', '$[finish_altitude]m'],
         ['Start time', '$[start_time]'],
         ['Finish time', '$[finish_time]'],
         ['Duration', '$[duration]'],
         ['Accumulated altitude gain', '$[accumulated_altitude_gain]m'],
         ['Accumulated altitude loss', '$[accumulated_altitude_loss]m'],
     ]
     self.kmz.add_roots(self.dive_style)
     self.glide_style = self.make_analysis_style('cc33ff33', bgcolors, rows)
     self.kmz.add_roots(self.glide_style)
     #
     self.time_mark_styles = []
     for i in xrange(0, len(self.icons)):
         icon_style = kml.IconStyle(self.icons[i],
                                    scale=self.icon_scales[i])
         label_style = kml.LabelStyle(color='cc33ffff',
                                      scale=self.label_scales[i])
         self.time_mark_styles.append(kml.Style(icon_style, label_style))
     self.kmz.add_roots(*self.time_mark_styles)
     #
     balloon_style = kml.BalloonStyle(text=kml.CDATA('$[description]'))
     icon_style = kml.IconStyle(kml.Icon.palette(4, 46),
                                scale=self.icon_scales[0])
     label_style = kml.LabelStyle(scale=self.label_scales[0])
     self.photo_style = kml.Style(balloon_style, icon_style, label_style)
     self.kmz.add_roots(self.photo_style)
     #
     text = kml.text(kml.CDATA('<h3>$[name]</h3>$[description]'))
     balloon_style = kml.BalloonStyle(text)
     icon_style = kml.IconStyle(self.icons[0],
                                color='ccff33ff',
                                scale=self.icon_scales[0])
     label_style = kml.LabelStyle(color='ccff33ff',
                                  scale=self.label_scales[0])
     line_style = kml.LineStyle(color='ccff33ff', width=2)
     self.xc_style = kml.Style(balloon_style, icon_style, label_style,
                               line_style)
     self.kmz.add_roots(self.xc_style)
     #
     text = kml.text(kml.CDATA('<h3>$[name]</h3>$[description]'))
     balloon_style = kml.BalloonStyle(text)
     icon_style = kml.IconStyle(self.icons[0],
                                color='ccff33ff',
                                scale=self.icon_scales[0])
     label_style = kml.LabelStyle(color='ccff33ff',
                                  scale=self.label_scales[0])
     line_style = kml.LineStyle(color='ccff33ff')
     self.xc_style2 = kml.Style(balloon_style, icon_style, label_style,
                                line_style)
     self.kmz.add_roots(self.xc_style2)
     #
     self.pixel_url = os.path.join('images', 'pixel.png')
     pixel = open(os.path.join(BASE_DIR, self.pixel_url)).read()
     self.kmz.add_files({self.pixel_url: pixel})
     #
     self.visible_none_folder = self.make_none_folder(1)
     self.invisible_none_folder = self.make_none_folder(0)
     #
     animation_icon_url = os.path.join('images', 'paraglider.png')
     self.animation_icon = kml.Icon(href=animation_icon_url)
     animation_icon = open(os.path.join(BASE_DIR,
                                        animation_icon_url)).read()
     files = {animation_icon_url: animation_icon}
     self.kmz.add_files(files)