Esempio n. 1
0
 def build(self):
     self.title = "Eaglesoft Map"
     print(MapSource.providers.keys())
     box_layout = BoxLayout()
     map_view = MapView(lat=30.005630, lon=73.257950, zoom=8)
     map_view.map_source = "osm"
     map_marker = MapMarker()
     map_marker.lat = 30.005630
     map_marker.lon = 73.257950
     map_marker.source = "map-marker.png"
     map_view.add_widget(map_marker)
     box_layout.add_widget(map_view)
     return box_layout
class Resultat(Screen):
    coords = ListProperty(
        (0, 0))  #Laver en ListProperty for klasse variabel coords
    mark_coords = None  #Sætter klassevariabel mark_coords til at være None.
    markerList = []  #laver en liste for klassevariabel markerList
    ADA = False  #Sætter klassevariabel ADA til False
    UNISEX = False  #Sætter klassevariabel UNISEX til False
    newMap = MapView()  #Lavet et en tom MapView til klassevariabel newMap

    def load_map(self, lokation):
        self.coords = findkoordinater(
            lokation, 0)  #Sætter coords til at være findkordinater
        self.newMap = MapView(
            zoom=10, lat=self.coords[0],
            lon=self.coords[1])  #Laver mapview med data fra coords
        self.ids.map_view.add_widget(
            self.newMap)  #tilføjer MapView som widget til boxlayout i MyApp.kv

    def criteria(self, ada, unisex):
        if ada == "down":  #Hvis id'en ADA's state er down
            self.ADA = True  #Sæt ada til at være true
        else:
            self.ADA = False  #ellers skal det være false

        if unisex == "down":  #Hvis id'en Unisex's state er down
            self.UNISEX = True  #Sæt unisex til at være True
        else:
            self.UNISEX = False  #ellers skal det være false

    def load_markers(self, antal, lokation):
        link = link_constructer(
            antal, self.ADA, self.UNISEX,
            lokation)  #Bruger link_constructor fra data_toiley.py
        data = data_constructer(
            link)  #Bruger data_constructer fra data_toilet.py

        for address in range(
                len(data[0])
        ):  #Laver en løkke som går fra n til længden af data[0] for at finde hvor mange markers der skal laves
            self.mark_coords = findkoordinater(
                data[0][address], 0
            )  #Sætter mark_coords til at være findkordinater af [0][n] for at få koordinater
            if self.mark_coords != None:  #Er self.mark_coords None?
                newMarker = MapMarker(
                    lat=self.mark_coords[0],
                    lon=self.mark_coords[1],
                    source="marker1.png"
                )  #laver en MapMarker med data fra self.mark_coords og bliver gemt i newMarker
                self.newMap.add_widget(
                    newMarker)  #tilføjer newMarker som widget til newMap
                self.markerList.append(
                    newMarker
                )  #tilføjer newMarker til klasse variablen markerList
                #print("dette er",self.mark_coords)

    def remove_markers(self):
        self.ids.map_view.remove_widget(
            self.newMap)  #fjerner newMap fra map_view i MyApp.kv
        for marker in self.markerList:  #Går igennem hver marker i markerList
            self.newMap.remove_widget(
                marker)  #fjerner widget marker fra newMap
Esempio n. 3
0
class AlertDetailScreen(Screen):
    main_screen_manager = ObjectProperty()
    backref = StringProperty()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def goto_backref(self, btn):
        if self.main_screen_manager:
            if self.backref == 'dashboard':
                self.main_screen_manager.show_dashboard(transition='right')
            else:
                self.main_screen_manager.show_alert_list(transition='right')

    def on_enter(self):
        self.mapbox = self.ids.map_box
        self.mapview = MapView()
        self.mapview.zoom = 5
        self.mapview.center_on(40.5960129, -99.5961643)

        import random
        import glob
        counties = glob.glob('*.polygon')
        county = random.choice(counties)
        with open(county, 'r') as f:
            polygons = eval(f.read())

        #self.draw_polygons(polygons)
        polygon_draw_thread = threading.Thread(target=self.draw_polygons,
                                               args=(polygons, ))
        polygon_draw_thread.start()

    def draw_polygons(self, polygons):
        if not polygons:
            return

        polygons = [("severe", polygon) for polygon in polygons]
        geo_json = self.get_geojson(polygons)
        self.gj_layer = GeoJsonMapLayer(geojson=geo_json)
        if self.gj_layer:
            lon, lat = self.gj_layer.center
            self.lon = lon
            self.lat = lat
            self.mapview.lon = self.lon
            self.mapview.lat = self.lat
            min_lon, max_lon, min_lat, max_lat = self.gj_layer.bounds
            radius = haversine(min_lon, min_lat, max_lon, max_lat)
            zoom = get_zoom_for_radius(radius, lat)
            self.mapview.zoom = zoom
            self.mapview.center_on(lat, lon)
        self.mapview.add_widget(self.gj_layer)
        self.mapbox.add_widget(self.mapview)
        #Clock.schedule_once(self.create_marker, 1)

    def create_marker(self, dt):
        self.marker = MapMarker(lat=self.lat, lon=self.lon)
        self.mapview.add_widget(self.marker)

    def on_leave(self):
        self.clear_widgets()

    def get_geojson(self, polygons):
        features = []

        for sev, p in polygons:
            feat = self.get_feature_dict()
            poly = self.fix_polygon(p)
            feat["geometry"]["coordinates"].append(poly)
            feat["properties"]["color"] = self.get_color_for_severity(sev)
            features.append(feat)

        result = {"type": "FeatureCollection", "features": features}

        return result

    def get_feature_dict(self):
        return {
            "type": "Feature",
            "properties": {
                "color": "blue"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": []
            }
        }

    def get_color_for_severity(self, severity):
        sev_dict = {
            "extreme": "red",
            "severe": "orange",
            "moderate": "blue",
            "minor": "green",
            "unknown": "grey"
        }
        return sev_dict.get(severity.lower(), 'grey')

    def fix_polygon(self, polygon):
        p = list(polygon)
        for i in range(len(p)):
            p[i] = p[i][::-1]

        return p

    def get_category_display_text(self, category):
        db_val_to_category_val = {
            "geo": "Earthquakes",
            "met": "Weather",
            "safety": "Public Safety",
            "rescue": "Rescue",
            "fire": "Fire",
            "health": "Health",
            "env": "Environment",
            "transport": "Transportation",
            "infra": "Infrastructure",
            "cbrne": "CBRNE",
            "other": "Other"
        }
        return db_val_to_category_val.get(category, category.title())