def add_gps_point(self, lat, lon): mpoint = ogm.MapPoint() mpoint.set_degrees(lat, lon) self.map.gps_add(lat, lon, heading=ogm.MAP_INVALID) self.update_lbl_coords(lat, lon) 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.MapPoint() p.set_degrees(0.0, 0.0) # self.osm.convert_screen_to_geographic(x, y, p) p = self.osm.convert_screen_to_geographic(x, y) lat, lon = p.get_degrees() tooltip.set_markup("%+.4f, %+.4f" % (lat, lon)) return True return False
def __init__(self): super(Window, self).__init__() self.connect('destroy', Gtk.main_quit) self.set_default_size(500, 500) self.set_title('OsmGpsMap test') punto_cota_cota = [-16.538275, -68.069592] self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.add(self.box) self.map = osmgpsmap.Map() self.box.pack_start(self.map, True, True, 0) self.layer_osd = osmgpsmap.MapOsd(show_dpad=True, show_zoom=True, show_crosshair=True, show_coordinates=True, show_scale=True) self.map.layer_add(self.layer_osd) max_zoom, min_zoom = self.map.props.max_zoom, self.map.props.min_zoom print(max_zoom, min_zoom) self.map.set_center_and_zoom(punto_cota_cota[0], punto_cota_cota[1], max_zoom) self.map_track = osmgpsmap.MapTrack() self.point = osmgpsmap.MapPoint() self.point.set_degrees(punto_cota_cota[0], punto_cota_cota[1]) self.map_track.add_point(self.point) # print(self.map_track.get_points()) self.map.track_add(self.map_track) # self.box.pack_start(self.map_track, True, True, 0) # self.grid = Gtk.Grid() # self.box.pack_start(self.grid, True, True, 0) self.lbl_coords = Gtk.Label("Coordenadas") self.box.pack_start(self.lbl_coords, False, True, 0)
def ors_call(self, dummy): try: self.osm.track_remove(self.orsRoute) except: pass try: sel = self.ors_profile.get_active_iter() if sel is not None: model = self.ors_profile.get_model() orsProfile = model[sel][0] except: orsProfile = 'driving-car' if self.pref_select_fastest.get_active(): pref = 'fastest' else: pref = 'shortest' try: Route = [] for i in range(len(self.via_route)): Route.append([self.via_route[i][1], self.via_route[i][0]]) Route.insert(0, [self.start_route[1], self.start_route[0]]) Route.append([self.end_route[1], self.end_route[0]]) body = { "coordinates": Route, "elevation": "true", "preference": pref } except: return headers = { 'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8', 'Authorization': '5b3ce3597851110001cf624831f2d1f9129542dfbd9a148cd579f14b', 'Content-Type': 'application/json; charset=utf-8' } call = requests.post( 'https://api.openrouteservice.org/v2/directions/' + orsProfile + '/geojson', json=body, headers=headers, timeout=10) # print(call.status_code, call.reason) # print(call.text) if call.status_code == 200: self.route_json = json.loads(call.text) self.coords = self.route_json['features'][0]['geometry'][ 'coordinates'] self.orsRoute = OsmGpsMap.MapTrack(editable=True, alpha=1, line_width=2) self.orsRoute.connect('point-changed', self.edit) for i in range(len(self.coords)): pt = OsmGpsMap.MapPoint() pt.set_degrees(float(self.coords[i][1]), float(self.coords[i][0])) self.orsRoute.add_point(pt) self.osm.track_add(self.orsRoute) self.calc_track_length(self.orsRoute, 0) # 0 is for the dummy arg bbox = self.route_json['features'][0]['bbox'] self.osm.zoom_fit_bbox(bbox[1], bbox[4], bbox[0], bbox[3]) self.instruction = '' for i in range( len(self.route_json['features'][0]['properties'] ['segments'])): for j in range( len(self.route_json['features'][0]['properties'] ['segments'][i]['steps'])): step = self.route_json['features'][0]['properties'][ 'segments'][i]['steps'][j] stepDistance = step['distance'] if stepDistance > 1000: stepDistance = str( round((stepDistance / 1609.34) * 100) / 100) + ' miles' else: stepDistance = str(stepDistance) + 'm' self.instruction = self.instruction + '- ' + step[ 'instruction'] + ' (' + stepDistance + ')\n'
def upload_gpx(self, gpx_button): dialog = Gtk.FileChooserDialog(title="Please choose a GPX file", parent=self, action=Gtk.FileChooserAction.OPEN) dialog.add_buttons( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK, ) filter = Gtk.FileFilter() filter.set_name("GPX") filter.add_pattern("*.gpx") dialog.add_filter(filter) filter = Gtk.FileFilter() filter.set_name("All files") filter.add_pattern("*") dialog.add_filter(filter) response = dialog.run() if response == Gtk.ResponseType.OK: gpx_file = open(dialog.get_filename(), 'r') gpx = gpxpy.parse(gpx_file) tr = [] self.coords = [] try: for track in gpx.tracks: for segment in track.segments: for pt in segment.points: lat = '{0}'.format(pt.latitude, pt.longitude, pt.elevation) lon = '{1}'.format(pt.latitude, pt.longitude, pt.elevation) elev = '{2}'.format(pt.latitude, pt.longitude, pt.elevation) self.coords.append([lon, lat, elev]) pt = OsmGpsMap.MapPoint() pt.set_degrees(float(lat), float(lon)) tr.append(pt) except: pass try: for waypoint in gpx.waypoints: lat = '{0}'.format(waypoint.latitude, waypoint.longitude, waypoint.elevation) lon = '{1}'.format(waypoint.latitude, waypoint.longitude, waypoint.elevation) elev = '{2}'.format(waypoint.latitude, waypoint.longitude, waypoint.elevation) self.coords.append([lon, lat, elev]) waypoint = OsmGpsMap.MapPoint() waypoint.set_degrees(float(lat), float(lon)) tr.append(waypoint) except: pass try: for trk in gpx.routes: # for track in gpx.tracks: # for segment in track.segments: for pt in trk.points: lat = '{0}'.format(pt.latitude, pt.longitude, pt.elevation) lon = '{1}'.format(pt.latitude, pt.longitude, pt.elevation) elev = '{2}'.format(pt.latitude, pt.longitude, pt.elevation) self.coords.append([lon, lat, elev]) pt = OsmGpsMap.MapPoint() pt.set_degrees(float(lat), float(lon)) tr.append(pt) except: pass if len(tr) > 0: self.route = OsmGpsMap.MapTrack(color=Gdk.RGBA(0, 0, 100, 1), line_width=3, alpha=1) for pt in tr: self.route.add_point(pt) self.osm.track_add(self.route) try: self.calc_track_length(self.route, 0) # 0 is for the dummy arg except: self.len_label.set_text('No length') # self.route.connect('point-changed', self.calc_track_length) beg = tr[0].get_degrees() end = tr[len(tr) - 1].get_degrees() self.osm.zoom_fit_bbox(beg[0], end[0], beg[1], end[1]) try: st = GdkPixbuf.Pixbuf.new_from_file_at_size( self.path + '/images/marker-start-icon-2x.png', 50, 50) self.startImage = self.osm.image_add(beg[0], beg[1], st) nd = GdkPixbuf.Pixbuf.new_from_file_at_size( self.path + '/images/marker-end-icon-2x.png', 50, 50) self.endImage = self.osm.image_add(end[0], end[1], nd) except: pass else: self.len_label.set_text('Can\'t read GPX') # elif response == Gtk.ResponseType.CANCEL: # print("Cancel clicked") dialog.destroy()