def do_draw(self, gpsmap, drawable):
        """
        draw the circles and the rectangles
        """
        for circle in self.circles:
            # TODO: Calculate only the nw and sw corners
            d = geopy.distance.VincentyDistance(kilometers=circle[0])
            center = geopy.point.Point(circle[1], circle[2])
            np = d.destination(center, 0)
            ep = d.destination(center, 90)
            sp = d.destination(center, 180)
            wp = d.destination(center, 270)
            osm_np = osmgpsmap.point_new_degrees(np[0], np[1])
            osm_ep = osmgpsmap.point_new_degrees(ep[0], ep[1])
            osm_sp = osmgpsmap.point_new_degrees(sp[0], sp[1])
            osm_wp = osmgpsmap.point_new_degrees(wp[0], wp[1])
            
            view_np = gpsmap.convert_geographic_to_screen(osm_np)
            view_ep = gpsmap.convert_geographic_to_screen(osm_ep)
            view_sp = gpsmap.convert_geographic_to_screen(osm_sp)
            view_wp = gpsmap.convert_geographic_to_screen(osm_wp)

            # Why do I get only circles of one color even though the debug lists correct values in the print ?
            c = gtk.gdk.color_parse(circle[3])
            cmap = drawable.get_colormap()
            c = cmap.alloc_color(c)
            drawable.set_colormap(cmap)
            ggc = drawable.new_gc(c,c)
            ggc.set_line_attributes(self.config['distance_line_width'], ggc.line_style, ggc.cap_style, ggc.join_style)
            # TODO: There probably is a better way to calculate these but I don't care, this works now
            drawable.draw_arc(ggc, False, view_wp[0], view_np[1], (view_ep[0] - view_wp[0]), (view_sp[1] - view_np[1]), 0, 360*64)
Esempio n. 2
0
 def do_draw(self, gpsmap, drawable):
     gc = drawable.new_gc()
     for circle in self.circles:
         top_left = osmgpsmap.point_new_degrees(circle[1] + circle[0],
                                                circle[2] - circle[0])
         bottom_right = osmgpsmap.point_new_degrees(circle[1] - circle[0],
                                                    circle[2] + circle[0])
         x, y = gpsmap.convert_geographic_to_screen(top_left)
         x2, y2 = gpsmap.convert_geographic_to_screen(bottom_right)
         drawable.draw_arc(gc, False, x, y, x2 - x, y2 - y, 0, 360 * 64)
     for rectangle in self.rectangles:
         top_left, bottom_right = rectangle
         x, y = gpsmap.convert_geographic_to_screen(top_left)
         x2, y2 = gpsmap.convert_geographic_to_screen(bottom_right)
         # be sure when can select a region in all case.
         if (x < x2):
             if (y < y2):
                 drawable.draw_rectangle(gc, False, x, y, x2 - x, y2 - y)
             else:
                 drawable.draw_rectangle(gc, False, x, y2, x2 - x, y - y2)
         else:
             if (y < y2):
                 drawable.draw_rectangle(gc, False, x2, y, x - x2, y2 - y)
             else:
                 drawable.draw_rectangle(gc, False, x2, y2, x - x2, y - y2)
Esempio n. 3
0
 def motion_event(self, osmmap, event):
     """
     Show the place name if found on the status bar
     """
     current = osmgpsmap.point_new_degrees(0.0, 0.0)
     osmmap.convert_screen_to_geographic(int(event.x), int(event.y),
                                         current)
     lat, lon = current.get_degrees()
     if self.zone_selection:
         # We draw a rectangle to show the selected region.
         layer = self.get_selection_layer()
         if layer:
             self.osm.layer_remove(layer)
         self.selection_layer = self.add_selection_layer()
         if self.end_selection == None:
             self.selection_layer.add_rectangle(self.begin_selection,
                                                current)
         else:
             self.selection_layer.add_rectangle(self.begin_selection,
                                                self.end_selection)
     else:
         places = self.is_there_a_place_here(lat, lon)
         mess = ""
         for p in places:
             if mess != "":
                 mess += " || "
             mess += p[0]
         self.uistate.status.pop(self.context_id)
         self.context_id = self.uistate.status.push(1, mess)
Esempio n. 4
0
File: map.py Progetto: robotang/wasp
 def _on_map_changed(self, _map):
     if self.lat and self.lon:
         if MAP_NEW_API:
             p = osmgpsmap.point_new_degrees(self.lat, self.lon)
             pixel_x, pixel_y = _map.convert_geographic_to_screen(p)
         else:
             pixel_x, pixel_y = _map.geographic_to_screen(self.lat, self.lon)
         self._alt.update_pixel_x(pixel_x)
Esempio n. 5
0
    def __init__(self, track, title, color, width, height, show_terrain):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.set_default_size(width, height)
        self.connect('destroy', lambda x: gtk.main_quit())
        self.vbox = gtk.VBox(False, 0)
        self.add(self.vbox)
        #        self.osm = osmgpsmap.GpsMap(repo_uri = "http://acetate.geoiq.com/tiles/acetate-hillshading/#Z/#X/#Y.png")
        if show_terrain:
            self.osm = osmgpsmap.GpsMap(
                repo_uri="http://khm.google.com/vt/lbw/lyrs=p&x=#X&y=#Y&z=#Z")
        else:
            self.osm = osmgpsmap.GpsMap(
                repo_uri="http://mt1.google.com/vt/lyrs=y&x=#X&y=#Y&z=#Z")


#        self.osm = osmgpsmap.GpsMap(repo_uri="http://tile.openstreetmap.org/#Z/#X/#Y.png")
        self.osm.layer_add(osmgpsmap.GpsMapOsd(show_dpad=True, show_zoom=True))
        self.osm.connect('button_release_event', self._map_clicked)
        #        self.osm.connect("motion_notify_event", self.update_distance)
        #connect keyboard shortcuts
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_FULLSCREEN,
                                       gtk.gdk.keyval_from_name("F11"))
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_UP,
                                       gtk.gdk.keyval_from_name("Up"))
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_DOWN,
                                       gtk.gdk.keyval_from_name("Down"))
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_LEFT,
                                       gtk.gdk.keyval_from_name("Left"))
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_RIGHT,
                                       gtk.gdk.keyval_from_name("Right"))
        self.vbox.pack_start(self.osm)
        self.status_bar = gtk.Statusbar()
        self.vbox.pack_start(self.status_bar, False, False, 0)
        #        gobject.timeout_add(500, self.updateDistance)
        # create the track
        map_track = osmgpsmap.GpsMapTrack()
        map_track.set_property("line-width", 2)
        map_track.set_property("color", gtk.gdk.color_parse(color))
        for i in range(0, len(track.trackpoints)):
            map_track.add_point(
                osmgpsmap.point_new_degrees(track.trackpoints.lats[i],
                                            track.trackpoints.lngs[i]))
        self.osm.track_add(map_track)
        # center the track
        (center_lat, lat_range) = track.get_mid_point_range("lats")
        (center_lng, lng_range) = track.get_mid_point_range("lngs")
        max_range = max(lat_range, lng_range)
        if max_range > 0.04: zoom = 14
        else: zoom = 15
        self.osm.set_center_and_zoom(latitude=center_lat,
                                     longitude=center_lng,
                                     zoom=zoom)
        # TODO: add numbers every 1/2 mile on the track. We'll need an image for each number to
        # do this
        #        pb = gtk.gdk.pixbuf_new_from_file_at_size (num + ".png", 24, 24)
        #        self.osm.image_add(lat, lon, pb)
        self.set_title(title)
Esempio n. 6
0
File: map.py Progetto: MorS25/wasp
 def _on_map_changed(self, _map):
     if self.lat and self.lon:
         if MAP_NEW_API:
             p = osmgpsmap.point_new_degrees(self.lat, self.lon)
             pixel_x, pixel_y = _map.convert_geographic_to_screen(p)
         else:
             pixel_x, pixel_y = _map.geographic_to_screen(
                 self.lat, self.lon)
         self._alt.update_pixel_x(pixel_x)
    def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip, data=None):
        if keyboard_tip:
            return False

        p = osmgpsmap.point_new_degrees(0.0, 0.0)
        self.osm.convert_screen_to_geographic(x, y, p)
        lat,lon = p.get_degrees()
        self.show_tooltips = True
        tooltip.set_markup("%+.5f, %+.5f" % p.get_degrees())
        tooltip.set_icon_from_stock(gtk.STOCK_HOME, gtk.ICON_SIZE_MENU)
        return True
Esempio n. 8
0
    def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip, data=None):
        if keyboard_tip:
            return False

        if self.show_tooltips:
            p = osmgpsmap.point_new_degrees(0.0, 0.0)
            self.osm.convert_screen_to_geographic(x, y, p)
            lat, lon = p.get_degrees()
            tooltip.set_markup("%+.4f, %+.4f" % p.get_degrees())
            return True

        return False
    def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip, data=None):
        if keyboard_tip:
            return False

        if self.show_tooltips:
            p = osmgpsmap.point_new_degrees(0.0, 0.0)
            self.osm.convert_screen_to_geographic(x, y, p)
            lat,lon = p.get_degrees()
            tooltip.set_markup("%+.4f, %+.4f" % (lat, lon ))
            return True

        return False
Esempio n. 10
0
    def __init__(self, track, title, color, width, height, show_terrain):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.set_default_size(width, height)
        self.connect('destroy', lambda x: gtk.main_quit())
        self.vbox = gtk.VBox(False, 0)
        self.add(self.vbox)
#        self.osm = osmgpsmap.GpsMap(repo_uri = "http://acetate.geoiq.com/tiles/acetate-hillshading/#Z/#X/#Y.png")
        if show_terrain:
            self.osm = osmgpsmap.GpsMap(repo_uri=
                                        "http://khm.google.com/vt/lbw/lyrs=p&x=#X&y=#Y&z=#Z")
        else:
            self.osm = osmgpsmap.GpsMap(repo_uri="http://mt1.google.com/vt/lyrs=y&x=#X&y=#Y&z=#Z")
#        self.osm = osmgpsmap.GpsMap(repo_uri="http://tile.openstreetmap.org/#Z/#X/#Y.png")
        self.osm.layer_add(osmgpsmap.GpsMapOsd(show_dpad=True, show_zoom=True))
        self.osm.connect('button_release_event', self._map_clicked)
#        self.osm.connect("motion_notify_event", self.update_distance)
        #connect keyboard shortcuts
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_FULLSCREEN, gtk.gdk.keyval_from_name("F11"))
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_UP, gtk.gdk.keyval_from_name("Up"))
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_DOWN, gtk.gdk.keyval_from_name("Down"))
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_LEFT, gtk.gdk.keyval_from_name("Left"))
        self.osm.set_keyboard_shortcut(osmgpsmap.KEY_RIGHT, gtk.gdk.keyval_from_name("Right"))
        self.vbox.pack_start(self.osm)
        self.status_bar = gtk.Statusbar()
        self.vbox.pack_start(self.status_bar, False, False, 0)
#        gobject.timeout_add(500, self.updateDistance)
        # create the track
        map_track = osmgpsmap.GpsMapTrack()
        map_track.set_property("line-width", 2)
        map_track.set_property("color", gtk.gdk.color_parse(color))
        for i in range(0, len(track.trackpoints)): 
            map_track.add_point(osmgpsmap.point_new_degrees(track.trackpoints.lats[i], 
                                                           track.trackpoints.lngs[i]))
        self.osm.track_add(map_track)
        # center the track
        (center_lat, lat_range) = track.get_mid_point_range("lats")
        (center_lng, lng_range) = track.get_mid_point_range("lngs")
        max_range = max(lat_range, lng_range)
        if max_range > 0.04: zoom = 14
        else: zoom = 15
        self.osm.set_center_and_zoom(latitude=center_lat, longitude=center_lng, zoom=zoom)
        # TODO: add numbers every 1/2 mile on the track. We'll need an image for each number to 
        # do this
        #        pb = gtk.gdk.pixbuf_new_from_file_at_size (num + ".png", 24, 24)
        #        self.osm.image_add(lat, lon, pb)
        self.set_title(title)
Esempio n. 11
0
 def draw_data(self,layer_index):
     layer_features=[]
     color_name,width,alpha=self.data.styles[layer_index]
     color=gtk.gdk.Color(color_name)
     for coordinates in self.data.layers[layer_index].data_to_track():
         tracks=[]
         for points in coordinates:
             track=osmgpsmap.GpsMapTrack()
             for point in points:
                 p=osmgpsmap.point_new_degrees(*point)
                 track.add_point(p)
             track.set_property('line-width',width)
             track.set_property('color',color)
             track.set_property('alpha',alpha)
             self.map.track_add(track)
             tracks.append(track)
         layer_features.append(tracks)
     self.layers_features.append(layer_features)
Esempio n. 12
0
File: map.py Progetto: robotang/wasp
    def _on_gps(self, msg, header, payload):
        fix,sv,self.lat,self.lon,hsl,hacc,vacc = msg.unpack_scaled_values(payload)

        #convert from mm to m
        hsl = hsl/1000.0

        if fix:
            if MAP_AVAILABLE:
                heading = osmgpsmap.INVALID
                if MAP_NEW_API:
                    self._map.gps_add(self.lat, self.lon, heading)
                    px, py = self._map.convert_geographic_to_screen(osmgpsmap.point_new_degrees(self.lat, self.lon))
                else:
                    self._map.draw_gps(self.lat, self.lon, heading)
                    px, py = self._map.geographic_to_screen(self.lat, self.lon)
                self._alt.update_pixel_x_and_altitude(px, hsl)
            else:
                self._alt.update_altitude(hsl)

            self._flight_track.append( geo.GeoPoint(lat=self.lat, lon=self.lon, alt=hsl) )
Esempio n. 13
0
File: map.py Progetto: MorS25/wasp
    def _on_gps(self, msg, header, payload):
        fix, sv, self.lat, self.lon, hsl, hacc, vacc = msg.unpack_scaled_values(
            payload)

        #convert from mm to m
        hsl = hsl / 1000.0

        if fix:
            if MAP_AVAILABLE:
                heading = osmgpsmap.INVALID
                if MAP_NEW_API:
                    self._map.gps_add(self.lat, self.lon, heading)
                    px, py = self._map.convert_geographic_to_screen(
                        osmgpsmap.point_new_degrees(self.lat, self.lon))
                else:
                    self._map.draw_gps(self.lat, self.lon, heading)
                    px, py = self._map.geographic_to_screen(self.lat, self.lon)
                self._alt.update_pixel_x_and_altitude(px, hsl)
            else:
                self._alt.update_altitude(hsl)

            self._flight_track.append(
                geo.GeoPoint(lat=self.lat, lon=self.lon, alt=hsl))
Esempio n. 14
0
 def map_clicked(self, osm, event):
     lat, lon = self.osm.get_event_location(event).get_degrees()
     current = osmgpsmap.point_new_degrees(0.0, 0.0)
     osm.convert_screen_to_geographic(int(event.x), int(event.y), current)
     lat, lon = current.get_degrees()
     if event.button == 1:
         if self.end_selection is not None:
             self.activate_selection_zoom(osm, event)
             self.end_selection = None
         else:
             # do we click on a marker ?
             marker = self.is_there_a_marker_here(event, lat, lon)
     elif event.button == 2 and event.type == gtk.gdk.BUTTON_PRESS:
         self.begin_selection = current
         self.end_selection = None
         self.zone_selection = True
     elif event.button == 2 and event.type == gtk.gdk.BUTTON_RELEASE:
         self.end_selection = current
         self.zone_selection = False
     elif gui.utils.is_right_click(event):
         self.build_nav_menu(osm, event, lat, lon)
     else:
         self.save_center(lat, lon)
Esempio n. 15
0
 def _update_distance(self, osm, event):
     p = osmgpsmap.point_new_degrees(self.min_lat, self.min_lng)
     self.osm.convert_screen_to_geographic(int(event.x), int(event.y), p)
     self.status_bar.push(
         1,
         str(self.min_lat + p.rlat) + "," + str(self.min_lng + p.rlon))
Esempio n. 16
0
File: map.py Progetto: MorS25/wasp
 def add(self, lat, lon, alt):
     self.append((lat, lon, alt))
     if MAP_NEW_API:
         p = osmgpsmap.point_new_degrees(lat, lon)
         self.maptrack.add_point(p)
Esempio n. 17
0
 def _update_distance(self, osm, event):
     p = osmgpsmap.point_new_degrees(self.min_lat, self.min_lng)
     self.osm.convert_screen_to_geographic(int(event.x), int(event.y), p)
     self.status_bar.push(1, str(self.min_lat + p.rlat) + "," + str(self.min_lng + p.rlon))
Esempio n. 18
0
File: map.py Progetto: robotang/wasp
 def add(self, lat, lon, alt):
     self.append( (lat,lon,alt) )
     if MAP_NEW_API:
         p = osmgpsmap.point_new_degrees(lat,lon)
         self.maptrack.add_point(p)