Пример #1
0
class mapviewApp(App):
    
    def storeLocation(self, **kwargs):
        locationData = kwargs
        print("WEEEE")
        print(locationData)
        gps.stop()
        
        self.mapview.center_on(locationData["lat"], locationData["lon"])
        return locationData


    def getLocation(self):
        gps.configure(on_location=self.storeLocation)
        gps.start(minTime=1000, minDistance=1)
    
    
    def build(self):
        layer = ClusteredMarkerLayer()
        
        a = MapMarker()
        # self.mapview.add_marker(, cls=MapMarker)
        layer.add_marker(lon=32.092, lat=34.807, cls=MapMarker)
        
        self.mapview = MapView(zoom=15, lat=32.092, lon=34.807)
        self.mapview.map_source.min_zoom = 14
        # self.mapview.add_widget(layer)
        
        data = get_geo_data()
        
        places = data["places"]

        for place in places:
            if place["categories"][0]["id"] == "45":
                pin_color = "data/pin-red.png"
                
            else:
                pin_color = "data/pin-blue.png"
            marker = MapMarker(lat=float(place["location"]["lat"]), lon=float(place["location"]["lng"]),source=pin_color)
            # layer.add_marker(marker)
            self.mapview.add_marker(marker)
            
        
        if platform == "android":
            print("gps.py: Android detected. Requesting permissions")
            request_android_permissions()

        
        try:
            print(self.getLocation())
        except NotImplementedError:
            print("location not NotImplemented")

        return self.mapview
Пример #2
0
class MapScreen(Screen):
    def __init__(self, **kwargs):
        super(MapScreen, self).__init__(**kwargs)
        self.fl = FloatLayout()
        with self.fl.canvas:
            Color(1, 1, 1, .8, mode='rgba')
            Rectangle(size=Window.size)

        self.mapview = MapView(zoom=13,
                               lat=48.35,
                               lon=-1.2,
                               pos_hint={"top": 0.9},
                               size_hint=(1, .7))
        self.arret_list = []
        self.bus_onMap = None
        self.arret_onMap = None
        self.button_menu = Button(height=40,
                                  width=40,
                                  size_hint=(None, None),
                                  pos=(20, 0),
                                  pos_hint={'top': 0.97})
        self.button_menu.bind(on_press=lambda x: self.get_coo())
        self.button_tr_info = Button(size_hint=(1 / 3, .1),
                                     pos=(0, 0),
                                     pos_hint={'top': 0.1},
                                     text="Menu")
        self.button_tr_info.bind(on_press=self.pressMenu)
        self.button_tr_map = Button(size_hint=(1 / 3, .1),
                                    pos=(Window.size[0] / 3, 0),
                                    pos_hint={'top': 0.1},
                                    text="Map")
        self.button_tr_map.bind(on_press=self.pressMap)
        self.button_tr_bus = Button(size_hint=(1 / 3, .1),
                                    pos=(Window.size[0] / 1.5, 0),
                                    pos_hint={'top': 0.1},
                                    text="Bus")
        self.button_tr_bus.bind(on_press=self.pressBus)
        self.fl.add_widget(self.button_menu)
        self.fl.add_widget(self.button_tr_info)
        self.fl.add_widget(self.button_tr_map)
        self.fl.add_widget(self.button_tr_bus)

        self.fl.add_widget(self.mapview)
        self.add_widget(self.fl)

    def pressMenu(self, *args):
        busapp.screenmanager.current = "Menu principal"

    def pressMap(self, *args):
        busapp.screenmanager.current = "Menu map"

    def pressBus(self, *args):
        busapp.screenmanager.current = "Menu bus"

    def addBusMarker(self, bus_taken):
        info = data_bus[bus_taken]
        if self.bus_onMap == True:
            self.mapview.remove_marker(self.bus_marker)
            self.removeArretMarker()
        else:
            self.bus_onMap = True
        self.bus_marker = MapMarkerPopup(lat=info["latitude"],
                                         lon=info["longitude"],
                                         source="bus_marker2.png",
                                         size=(20, 20))

        self.bus_marker.add_widget(
            Label(pos=(0, -40), text=bus_taken, color=(0, 0, 0, 1)))
        self.mapview.add_marker(self.bus_marker)

        self.mapview.get_latlon_at(Window.size[0] / 2,
                                   Window.size[1] / 2,
                                   zoom=None)
        self.addArretMarker("Ligne-" + info["ligne"])

    def addArretMarker(self, ligne):
        for arret in data_stop[ligne]:
            print(arret)
            arret_marker = MapMarkerPopup(
                lat=data_stop[ligne][arret]["latitude"],
                lon=data_stop[ligne][arret]["longitude"],
                source="bus_stop.png")
            arret_marker.add_widget(
                Label(pos=(0, -40),
                      text=data_stop[ligne][arret]["name"],
                      color=(0, 0, 0, 1)))
            self.arret_list.append(arret_marker)
            self.mapview.add_marker(arret_marker)

    def removeArretMarker(self):
        for arret in self.arret_list:
            self.mapview.remove_marker(arret)
        self.arret_list.clear()

    def get_coo(self):
        print(self.arret_list)
        print(
            str(
                self.mapview.get_latlon_at(Window.size[0] / 2,
                                           Window.size[1] / 2,
                                           zoom=None)))
Пример #3
0
class Forecast(Screen):
    def __init__(self, **kwargs):

        super().__init__(**kwargs)

        self.current_time = datetime.now()

        #test variable
        self.test = ""
        self.type = ""
        self.status = ""

        #image
        self.image_bool = True

        #gps config and start, get lat and lon values
        self.address = ""
        self.lat = 0
        self.lon = 0

        main_layout = BoxLayout(orientation="vertical")

        actual_forecast = GridLayout(cols=2,
                                     size_hint=(1, 0.3))  #size_hint= (1, 1))
        Clock.schedule_interval(self.update_image, 300)
        self.img = Image(source="./umbrella.png",
                         size_hint=(0.4, 1),
                         pos_hint={
                             "center_x": 0.5,
                             "center_y": 0.5
                         })
        info = BoxLayout(orientation="vertical")
        Clock.schedule_interval(self.update_clock, 1)
        self.time_label = Label(text=self.current_time.strftime("%H:%M:%S"))
        info.add_widget(self.time_label)
        self.pos_label = Label(text=f"{self.address} + {self.test}",
                               text_size=(info.width * 3, None))
        info.add_widget(self.pos_label)

        actual_forecast.add_widget(self.img)
        actual_forecast.add_widget(info)

        main_layout.add_widget(actual_forecast)

        # if platform == "android":
        #     Clock.schedule_interval(self.gps_run, 10)

        self.next_forecast = BoxLayout(orientation="vertical")
        next = Label(text="Prévisions à venir",
                     size_hint=(1, 0.2),
                     text_size=(Window.width * 0.9, None))
        self.next_forecast.add_widget(next)

        self.map = MapView(zoom=11, lat=float(self.lat), lon=float(self.lon))
        self.current_loc = MapMarker(lat=float(self.lat),
                                     lon=float(self.lon),
                                     source="./marker.png")
        self.current_loc.bind(on_press=self.marker_popup)
        self.map.add_marker(self.current_loc)
        self.next_forecast.add_widget(self.map)
        main_layout.add_widget(self.next_forecast)

        button = Button(text="Agenda", size_hint=(1, 0.2))
        button.bind(on_press=self.get_dairy)
        main_layout.add_widget(button)

        self.add_widget(main_layout)

    def marker_popup(self, *args):
        box = BoxLayout(orientation="vertical")
        text = "Vous êtes au: \n" + self.address
        label = Label(text=text, text_size=(Window.width * 0.9, None))
        ok_button = Button(text="OK", size_hint=(1, 0.2))
        ok_button.bind(on_press=self.marker_popup_dismiss)
        box.add_widget(label)
        box.add_widget(ok_button)
        self.mark_popup = Popup(title="Informations:", content=box)
        self.mark_popup.open()

    def marker_popup_dismiss(self, *args):
        self.mark_popup.dismiss()

    def get_dairy(self, *arg):
        my_app.sm.current = "Agenda"

    def update_clock(self, *args):
        self.time_label.text = main_time().strftime("%H:%M:%S")

        self.pos_label.text = f"{self.address} + {self.test} \n {self.lat}, {self.lon}"  #Une phrase super gavée longue pour tester ce que je veux faire
        self.current_loc.lat = float(self.lat)
        self.current_loc.lon = float(self.lon)

        if self.image_bool and self.lat != 0 and self.lon != 0:
            if get_current_weather(self.lat, self.lon) < 0.1:
                self.img.source = "./sun.png"
            else:
                self.img.source = "./umbrella.png"
            self.image_bool = False

    def update_image(self, *args):
        if get_current_weather(self.lat, self.lon) < 0.1:
            self.img.source = "./sun.png"
        else:
            self.img.source = "./umbrella.png"