Пример #1
0
 def test_init_geojson(self):
     """Providing the geojson directly, polygons should get added."""
     options = {}
     mapview = MapView(**options)
     geojson = {}
     kwargs = {"geojson": geojson}
     maplayer = GeoJsonMapLayer(**kwargs)
     mapview.add_layer(maplayer)
     Clock.tick()
     assert maplayer.source == ""
     assert maplayer.geojson == geojson
     assert len(maplayer.canvas_line.children) == 0
     assert len(maplayer.canvas_polygon.children) == 3
     assert len(maplayer.g_canvas_polygon.children) == 0
     geojson = load_json("maps-devrel-google.json")
     kwargs = {"geojson": geojson}
     maplayer = GeoJsonMapLayer(**kwargs)
     mapview = MapView(**options)
     mapview.add_layer(maplayer)
     Clock.tick()
     assert maplayer.source == ""
     assert maplayer.geojson == geojson
     assert len(maplayer.canvas_line.children) == 0
     assert len(maplayer.canvas_polygon.children) == 3
     assert len(maplayer.g_canvas_polygon.children) == 132
Пример #2
0
    def add_boundary(self, password):

        if (password == 1):
            self.bound1 = GeoJsonMapLayer()
            self.bound1.source = os.path.realpath(sys.argv[0]).strip(
                sys.argv[0]
            ) + "data\\" + "鄰里邊界\\" + self.spinner.text + "\\" + self.rank1.text + ".json"
            print(self.bound1.source)
            self.add1_bound.append(self.bound1)
            self.map.add_layer(self.bound1)
            print(self.rank1.text + "邊界")
        elif (password == 2):
            self.bound2 = GeoJsonMapLayer()
            self.bound2.source = os.path.realpath(sys.argv[0]).strip(
                sys.argv[0]
            ) + "data\\" + "鄰里邊界\\" + self.spinner.text + "\\" + self.rank2.text + ".json"
            self.add2_bound.append(self.bound2)
            self.map.add_layer(self.bound2)
            print(self.rank2.text + "邊界")
        elif (password == 3):
            self.bound3 = GeoJsonMapLayer()
            self.bound3.source = os.path.realpath(sys.argv[0]).strip(
                sys.argv[0]
            ) + "data\\" + "鄰里邊界\\" + self.spinner.text + "\\" + self.rank3.text + ".json"

            self.add3_bound.append(self.bound3)
            self.map.add_layer(self.bound3)
            print(self.rank3.text + "邊界")
Пример #3
0
 def test_init_simple(self):
     """Makes sure we can initialize a simple GeoJsonMapLayer object."""
     kwargs = {}
     maplayer = GeoJsonMapLayer(**kwargs)
     assert maplayer.source == ""
     assert maplayer.geojson is None
     assert maplayer.cache_dir == "cache"
Пример #4
0
 def test_init_source(self):
     """
     Providing the source from http(s).
     The json object should get downloaded using the requests library.
     """
     source = "https://storage.googleapis.com/maps-devrel/google.json"
     kwargs = {"source": source}
     response_json = {
         "type": "FeatureCollection",
     }
     with patch_requests_get(response_json) as m_get:
         maplayer = GeoJsonMapLayer(**kwargs)
     assert maplayer.source == source
     assert maplayer.geojson is None
     while maplayer.geojson is None:
         Clock.tick()
     assert maplayer.geojson == response_json
     assert m_get.call_args_list == [mock.call(source)]
Пример #5
0
    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)
    def __init__(self, **kwargs):
        super(Test, self).__init__(**kwargs)

        self.click = 0

        # ---以下定義點擊前三名按鈕時的次數---
        self.add1 = 0
        self.add1_shop_list = []
        self.add1_temp_list = []
        self.add1_rent_list = []
        self.add1_bound = []
        self.bound1 = GeoJsonMapLayer()

        self.add2 = 0
        self.add2_shop_list = []
        self.add2_temp_list = []
        self.add2_rent_list = []
        self.add2_bound = []
        self.bound2 = GeoJsonMapLayer()

        self.add3 = 0
        self.add3_shop_list = []
        self.add3_temp_list = []
        self.add3_rent_list = []
        self.add3_bound = []
        self.bound3 = GeoJsonMapLayer()

        # from geopy.geocoders import Nominatim
        # self.geolocator = Nominatim(user_agent="Brian_map")

        # self.wid = Widget()
        self.progress_bar = MDProgressBar()
        self.popup = MDDialog(title='數據加載中,請稍後!',

                              #content = self.progress_bar
                              )
        self.popup.auto_dismiss = False
        self.popup.add_widget(self.progress_bar)
        self.popup.children[1].size_hint = [1, 1]
        self.popup.children[1].children[5].font_size = 40
        self.popup.children[1].children[5].font_name = 'msjhbd.ttc'
        self.popup.size_hint = [0.5, 0.5]
        self.popup.background_color = [0.5, 0.5, 0.5, 0.75]
        self.progress_bar.value = 1
        self.popup.bind(on_open=self.puopen)

        # 主畫面切成左右兩欄
        self.cols = 3

        # 左欄是一個Gridlayout,有四列
        self.left = MDGridLayout(rows=6, size_hint=[0.4, 1], spacing=[0, 3])
        # 創建地圖
        self.map = FarmersMapView()

        # 左欄最上方要來做店租範圍
        self.left.one = MDGridLayout(size=[590, 657],
                                     rows=2,
                                     size_hint=[1, 0.2],
                                     md_bg_color=[0.39, 0.4, 0.72, 1],
                                     padding=[35, -20, 35, -20],
                                     spacing=[0, -30])
        # 把標籤裝進去最上層
        self.left.one.add_widget(
            Label(text='選擇月租範圍',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  size_hint_y=0.18))
        # 新增一層容器準備裝三個東西
        self.left.one.box = BoxLayout(spacing=8, size_hint_y=0.15)
        # 盒子裝進一個下限input、一上限input、一個'-'tag
        self.lower_bound = MDTextFieldRect(x=275,
                                           hint_text="$下限",
                                           font_name='msjhbd.ttc',
                                           pos_hint={'y': 0.45},
                                           size_hint=[1.5, 0.5],
                                           use_bubble=True,
                                           use_handles=True)
        self.upper_bound = MDTextFieldRect(hint_text="$上限",
                                           font_name='msjhbd.ttc',
                                           pos_hint={'y': 0.45},
                                           center_x=275.76,
                                           center_y=508.20,
                                           size_hint=[1.5, 0.5],
                                           use_bubble=True,
                                           use_handles=True)
        self.dash_sign = MDFlatButton(text='-',
                                      font_size=30,
                                      size_hint=[1, 0.49],
                                      pos_hint={'y': 0.45})
        self.dash_sign.md_bg_color = [1, 1, 1, 1]
        self.left.one.box.add_widget(self.lower_bound)
        self.left.one.box.add_widget(self.dash_sign)
        self.left.one.box.add_widget(self.upper_bound)
        # 盒子裝回上層
        self.left.one.add_widget(self.left.one.box)

        # 新增行政區選單
        self.left.six = MDGridLayout(size=[590, 657],
                                     rows=2,
                                     size_hint=[1, 0.25],
                                     md_bg_color=[0.39, 0.4, 0.72, 1],
                                     padding=[35, -5, 35, 5],
                                     spacing=[0, -10])
        self.left.six.add_widget(
            Label(text='行政區選擇',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.1]))
        self.left.six.box = BoxLayout(size_hint_y=0.15, center_y=390)
        from kivy.uix.spinner import Spinner
        district = [
            "中區", "東區", "西區", "南區", "北區", "西屯區", "南屯區", "北屯區", "豐原區", "大里區",
            "太平區", "清水區", "沙鹿區", "大甲區", "東勢區", "梧棲區", "烏日區", "神岡區", "大肚區",
            "大雅區", "后里區", "霧峰區", "潭子區", "龍井區", "外埔區", "和平區", "石岡區", "大安區",
            "新社區"
        ]
        self.spinner = Spinner(
            text='行政區',
            values=[n for n in district],
            size_hint=(None, None),
            size=(95, 44),
            #pos_hint = {'right':0.2},
            font_name='msjhbd.ttc',
            background_color=[1, 0, 0, 1])
        self.spinner.option_cls.font_name = 'msjhbd.ttc'
        self.spinner.option_cls.background_color = [1, 0, 0, 1]
        #self.spinner.values[0].font_name = 'msjhbd.ttc'
        self.spinner.dropdown_cls.max_height = self.spinner.height * 7 + 7 * 4
        #self.spinner.center_x = 160
        #self.left.six.box.add_widget(BoxLayout(size_hint_y=0.5, size_hint_x=0.5, width=100))
        self.left.six.box.add_widget(
            MDGridLayout(md_bg_color=[0.39, 0.4, 0.72, 1],
                         size_hint=[None, 0.5]))
        self.left.six.box.add_widget(self.spinner)
        self.left.six.add_widget(self.left.six.box)
        #self.left.six.box.children[0].center = (160, 522.1339285)
        #self.spinner.pos_hint = {'right':0.9}
        #self.spinner.center_x = 150

        # 這裡是畫面左欄第二格
        self.left.two = MDGridLayout(rows=2,
                                     size_hint=[1, None],
                                     size=[365, 170],
                                     md_bg_color=[0.39, 0.4, 0.72, 1])
        #self.left.two.center_y = 400
        # 把"指標排序"標籤裝進第二格子的上方
        self.left.two.add_widget(
            Label(text='指標排序',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.1]))
        # 左欄第二格下方增加一個grid容器
        self.left.two.grid = MDGridLayout(rows=3,
                                          size_hint=[1, 0.26],
                                          padding=[30, 0, 20, 0])
        self.left.two.grid.size_hint = [1, 0.26]
        self.left.two.add_widget(self.left.two.grid)
        # 準備三個box放入此grid
        self.left.two.box1 = BoxLayout(size_hint=[1, None],
                                       size=[365, 40],
                                       spacing=13)
        self.left.two.box2 = BoxLayout(size_hint=[1, None],
                                       size=[365, 40],
                                       spacing=13)
        self.left.two.box3 = BoxLayout(size_hint=[1, None],
                                       size=[365, 40],
                                       spacing=13)
        self.left.two.grid.add_widget(self.left.two.box1)
        self.left.two.grid.add_widget(self.left.two.box2)
        self.left.two.grid.add_widget(self.left.two.box3)
        # 處理第一個box的標籤(全用按鈕取代)、輸入
        self.left.two.btn1 = MDRaisedButton(text='      人口特性      ',
                                            font_name='msjhbd.ttc',
                                            font_size='16sp')
        self.left.two.btn1.md_bg_color = [0.55, 0.63, 0.99, 1]
        self.left.two.input1 = MDTextFieldRect(hint_text='請輸入1、2、3:',
                                               size_hint=[1, None],
                                               size=[94, 37],
                                               font_name='msjhbd.ttc')
        self.left.two.input1.size_hint_x = None
        self.left.two.input1.width = 120
        self.left.two.box1.add_widget(self.left.two.btn1)
        self.left.two.box1.add_widget(self.left.two.input1)

        self.left.two.btn3 = MDRaisedButton(text='      薪資所得      ',
                                            font_name='msjhbd.ttc',
                                            font_size='16sp')
        self.left.two.btn3.md_bg_color = [0.68, 0.82, 0.96, 1]
        self.left.two.input3 = MDTextFieldRect(hint_text='請輸入1、2、3:',
                                               size_hint=[1, None],
                                               size=[94, 37],
                                               font_name='msjhbd.ttc')
        self.left.two.input3.size_hint_x = None
        self.left.two.input3.width = 120
        self.left.two.box2.add_widget(self.left.two.btn3)
        self.left.two.box2.add_widget(self.left.two.input3)

        self.left.two.btn5 = MDRaisedButton(text='      人口消長      ',
                                            font_name='msjhbd.ttc',
                                            font_size='16sp')
        self.left.two.btn5.md_bg_color = [0.5, 0.87, 0.98, 1]
        self.left.two.input5 = MDTextFieldRect(hint_text='請輸入1、2、3:',
                                               size_hint=[1, None],
                                               size=[94, 37],
                                               font_name='msjhbd.ttc')
        self.left.two.input5.size_hint_x = None
        self.left.two.input5.width = 120
        self.left.two.box3.add_widget(self.left.two.btn5)
        self.left.two.box3.add_widget(self.left.two.input5)

        # 這裡是畫面左欄第三格
        self.left.three = MDGridLayout(rows=2,
                                       md_bg_color=[0.39, 0.4, 0.72, 1],
                                       size_hint=[1, 0.57])
        # 把"指標排序"標籤裝進第二格子的上方
        self.left.three.add_widget(
            Label(text='選擇競爭對手',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.06]))

        # 左欄第三格下方增加一個grid容器
        self.left.three.grid = MDGridLayout(rows=5,
                                            size_hint=[1, 0.26],
                                            spacing=3,
                                            padding=[30, 0, 40, 0])
        self.left.three.add_widget(self.left.three.grid)
        # 準備五個box放入此grid
        self.left.three.box1 = BoxLayout(size_hint=[1, 0.05])
        self.left.three.box2 = BoxLayout(size_hint=[1, 0.05])
        self.left.three.box3 = BoxLayout(size_hint=[1, 0.05])
        self.left.three.box4 = BoxLayout(size_hint=[1, 0.05])
        #self.left.three.box5 = BoxLayout(size_hint=[1, 0.4])
        self.left.three.box6 = BoxLayout()
        self.left.three.grid.add_widget(self.left.three.box1)
        self.left.three.grid.add_widget(self.left.three.box2)
        self.left.three.grid.add_widget(self.left.three.box3)
        self.left.three.grid.add_widget(self.left.three.box4)

        # 處理第一個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn1 = MDRaisedButton(text='       早餐店         ',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn1.md_bg_color = [0.55, 0.63, 0.99, 1]
        self.left.three.input1 = MDCheckbox()
        self.left.three.input1.x = 140
        self.left.three.input1.selected_color = (1, 1, 1, 1)
        self.left.three.input1.unselected_color = (1, 1, 1, 1)
        self.left.three.box1.add_widget(self.left.three.btn1)
        self.left.three.box1.add_widget(self.left.three.input1)
        # 處理第二個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn2 = MDRaisedButton(text='便當、自助餐店',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn2.md_bg_color = [0.48, 0.81, 0.78, 1]
        self.left.three.input2 = MDCheckbox()
        self.left.three.input2.x = 140
        self.left.three.input2.selected_color = (1, 1, 1, 1)
        self.left.three.input2.unselected_color = (1, 1, 1, 1)
        self.left.three.box2.add_widget(self.left.three.btn2)
        self.left.three.box2.add_widget(self.left.three.input2)
        # 處理第三個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn3 = MDRaisedButton(text='麵店、小吃店    ',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn3.md_bg_color = [0.68, 0.82, 0.96, 1]
        self.left.three.input3 = MDCheckbox()
        self.left.three.input3.x = 140
        self.left.three.input3.selected_color = (1, 1, 1, 1)
        self.left.three.input3.unselected_color = (1, 1, 1, 1)
        self.left.three.box3.add_widget(self.left.three.btn3)
        self.left.three.box3.add_widget(self.left.three.input3)
        # 處理第四個box的標籤(全用按鈕取代)、勾選
        self.left.three.btn4 = MDRaisedButton(text='      餐館餐廳      ',
                                              font_name='msjhbd.ttc',
                                              size_hint=[None, 0.9],
                                              font_size='16sp')
        self.left.three.btn4.md_bg_color = [0.62, 0.84, 0.51, 1]
        self.left.three.input4 = MDCheckbox()
        self.left.three.input4.x = 140
        #self.left.three.input4.color = [1,1,1,2]
        self.left.three.input4.selected_color = (1, 1, 1, 1)
        self.left.three.input4.unselected_color = (1, 1, 1, 1)
        self.left.three.box4.add_widget(self.left.three.btn4)
        self.left.three.box4.add_widget(self.left.three.input4)

        self.run_button = MDRaisedButton(text='Run')

        # 製作廟宇按鈕
        self.left.four = MDGridLayout(rows=2,
                                      size_hint=[1, None],
                                      size=[365, 90],
                                      md_bg_color=[0.39, 0.4, 0.72, 1])
        self.left.four.add_widget(
            Label(text='廟宇出現與否',
                  font_size='20sp',
                  font_name='msjhbd.ttc',
                  height=32,
                  size_hint=[1, 0.025]))
        self.left.four.box = BoxLayout(size_hint=[1, 0.025],
                                       padding=[30, -20, 40, 5])
        self.left.four.add_widget(self.left.four.box)
        self.left.four.btn = MDRaisedButton(text='          廟宇          ',
                                            font_name='msjhbd.ttc',
                                            size_hint=[None, 0.8],
                                            font_size='16sp')
        self.left.four.input = MDCheckbox()
        self.left.four.input.selected_color = (1, 1, 1, 1)
        self.left.four.input.unselected_color = (1, 1, 1, 1)
        self.left.four.box.add_widget(self.left.four.btn)
        self.left.four.box.add_widget(self.left.four.input)

        # 把每一層加回去
        self.left.add_widget(self.left.one)
        self.left.add_widget(self.left.six)
        self.left.add_widget(self.left.two)
        self.left.add_widget(self.left.three)
        self.left.add_widget(self.left.four)
        self.add_widget(self.left)
        self.add_widget(self.map)

        # 測試用的按鈕
        #self.run_button = MDRaisedButton(text='Run')
        self.left.five = MDGridLayout(size_hint=[1, 0.1],
                                      md_bg_color=[0.39, 0.4, 0.72, 1])
        self.left.five.add_widget(self.run_button)
        self.run_button.bind(on_release=self.popup.open)
        self.left.add_widget(self.left.five)
        self.run_button.right = 270
        self.run_button.ripple_alpha = 0.7
        self.run_button.radius = [10, 10, 10, 10]
        self.run_button.md_bg_color = [1, 1, 1, 1]
        self.run_button.text_color = [0, 0, 0, 1]
Пример #7
0
import sys

from kivy.base import runTouchApp

from kivy_garden.mapview import MapMarker, MapView
from kivy_garden.mapview.geojson import GeoJsonMapLayer
from kivy_garden.mapview.utils import get_zoom_for_radius, haversine

if len(sys.argv) > 1:
    source = sys.argv[1]
else:
    source = "https://storage.googleapis.com/maps-devrel/google.json"

options = {}
layer = GeoJsonMapLayer(source=source)

if layer.geojson:
    # try to auto center the map on the source
    lon, lat = layer.center
    options["lon"] = lon
    options["lat"] = lat
    min_lon, max_lon, min_lat, max_lat = layer.bounds
    radius = haversine(min_lon, min_lat, max_lon, max_lat)
    zoom = get_zoom_for_radius(radius, lat)
    options["zoom"] = zoom

view = MapView(**options)
view.add_layer(layer)

if layer.geojson: