Ejemplo n.º 1
0
def test_bmap_map_control_panel(fake_writer):
    bmap = (BMap().add_schema(
        baidu_ak=FAKE_API_KEY, center=[
            -0.118092, 51.509865
        ]).add_coordinate("London", -0.118092, 51.509865).add(
            "bmap",
            [list(z) for z in zip(TEST_LOCATION, TEST_VALUE)],
            type_=ChartType.LINES,
            label_opts=opts.LabelOpts(formatter="{b}"),
        ).add_control_panel(
            copyright_control_opts=opts.BMapCopyrightTypeOpts(position=3),
            maptype_control_opts=opts.BMapTypeControlOpts(
                type_=BMapType.MAPTYPE_CONTROL_DROPDOWN),
            scale_control_opts=opts.BMapScaleControlOpts(),
            overview_map_opts=opts.BMapOverviewMapControlOpts(is_open=True),
            navigation_control_opts=opts.BMapNavigationControlOpts(),
            geo_location_control_opts=opts.BMapGeoLocationControlOpts(),
        ))
    bmap.render()
    content = fake_writer.call_args[0][1]
    assert_in("new BMap.CopyrightControl", content)
    assert_in("new BMap.MapTypeControl", content)
    assert_in("new BMap.ScaleControl", content)
    assert_in("new BMap.OverviewMapControl", content)
    assert_in("new BMap.NavigationControl", content)
    assert_in("new BMap.GeolocationControl", content)
Ejemplo n.º 2
0
def bmap_heatmap(index_lngLat,
                 index_value,
                 title='',
                 width="1000px",
                 height="600px") -> BMap:
    c = (
        BMap(
            init_opts=opts.InitOpts(theme="white", width=width, height=height))
        # .add_schema(baidu_ak=Baidu_AK, center=[110.3131940000, 20.0274250000], zoom=13, map_style=get_map_style())  #缩放比例12-14之间可行
        .add_schema(baidu_ak=Baidu_AK,
                    center=[110.3131940000, 20.0274250000],
                    zoom=13).set_global_opts(
                        title_opts=opts.TitleOpts(title=title),
                        visualmap_opts=opts.VisualMapOpts(pos_top='5%',
                                                          pos_right='5%')))
    # 增加坐标点信息
    for key, value in index_lngLat.items():
        c.add_coordinate(key, value[0], value[1])

# 热力图
    c.add(
        "出发地热力图",
        index_value[0],
        type_="heatmap",
        label_opts=opts.LabelOpts(formatter="{b}"),
    )

    # 点图
    c.add(
        "出发地位置",
        index_value[0],
        type_="scatter",
        symbol_size=3,
        # color='rgb(1, 1, 1)',
        # itemstyle_opts= opts.ItemStyleOpts(color='rgb(1, 1, 1)'),
        label_opts=opts.LabelOpts(is_show=False),
    )
    # 热力图
    c.add(
        "到达地热力图",
        index_value[1],
        type_="heatmap",
        label_opts=opts.LabelOpts(formatter="{b}"),
    )

    # 点图
    c.add(
        "到达地位置",
        index_value[1],
        type_="scatter",
        symbol_size=3,
        label_opts=opts.LabelOpts(is_show=False),
    )

    c.add_control_panel(
        navigation_control_opts=opts.BMapNavigationControlOpts(
            offset_height=30),
        scale_control_opts=opts.BMapScaleControlOpts(),
    )
    return c
Ejemplo n.º 3
0
    def bmap_route_map() -> BMap:
        c = (
            BMap().add_schema(baidu_ak=Baidu_AK,
                              center=[110.3014600000, 20.0132350000],
                              zoom=13)  #缩放比例12-14之间可行
            .set_global_opts(
                title_opts=opts.TitleOpts(
                    title="09/20 17:30-17:31"),  # 更改title====================
                visualmap_opts=opts.VisualMapOpts(is_show=False),
            ))

        # 增加路径线
        c.add(
            "行车路径模拟",
            type_="lines",
            is_polyline=True,
            data_pair=taix_lines,
            linestyle_opts=opts.LineStyleOpts(opacity=0.2, width=0.5),
            # 如果不是最新版本的话可以注释下面的参数(效果差距不大)
            # progressive=200,
            # progressive_threshold=500
        )

        c.add_control_panel(
            navigation_control_opts=opts.BMapNavigationControlOpts(
                offset_height=30),
            scale_control_opts=opts.BMapScaleControlOpts(),
        )

        return c
Ejemplo n.º 4
0
def get_eventbmap(pos) -> BMap:
    #[(lo,la),(lo,la)]这种格式即可
    BAIDU_AK = "HOTBRAfU1jGcQKHBX15ucKsfZO722eyN"
    center = (117.20, 39.12)
    c = BMap()
    c.add_schema(
        baidu_ak=BAIDU_AK,
        center=[117.20, 39.12],
        zoom=10,
        is_roam=False,
    )
    sequence = []
    for i in range(len(pos)):
        c.add_coordinate(str(i), pos[i][0], pos[i][1])  #[(posindex,lo,la)]
        sequence.append((str(i), 0.1))  #这里名字和pos要对应
    c.add(
        "投诉坐标",  #系列名称
        sequence,
        type_="scatter",  #"heatmap" 可以切换显示的类型热力图或散点图
        label_opts=opts.LabelOpts(formatter="{b}"),
        symbol_size=5)
    c.set_series_opts(effect_opts=opts.EffectOpts(is_show=True),
                      label_opts=opts.LabelOpts(is_show=False))
    c.add_control_panel(
        scale_control_opts=opts.BMapScaleControlOpts(),
        navigation_control_opts=opts.BMapNavigationControlOpts(),
        maptype_control_opts=opts.BMapTypeControlOpts())
    #c.set_global_opts(visualmap_opts=opts.VisualMapOpts())
    return c
Ejemplo n.º 5
0
    def bmap_heatmap() -> BMap:
        c = (
            BMap(init_opts = opts.InitOpts(theme = "white"))
            .add_schema(baidu_ak=Baidu_AK, center=[110.3014600000, 20.0132350000], zoom=13)  #缩放比例12-14之间可行
            .set_global_opts(
                title_opts=opts.TitleOpts(title="10/04 中秋节 18:00-22:00"),  # 更改title====================
                visualmap_opts=opts.VisualMapOpts(pos_top='5%', pos_right='5%'),
            )
        )
        # 增加坐标点信息
        for key, value in index_lngLat.items():
            c.add_coordinate(key, value[0], value[1])

       # 热力图
        c.add(
                "出发地热力图",
                index_value[0],
                type_="heatmap",
                label_opts=opts.LabelOpts(formatter="{b}"),
            )

        # 点图
        c.add(
                "出发地位置",
                index_value[0],
                type_="scatter",
                symbol_size=3,
                # color='rgb(1, 1, 1)',
                # itemstyle_opts= opts.ItemStyleOpts(color='rgb(1, 1, 1)'),
                label_opts=opts.LabelOpts(is_show=False),
            )
        # 热力图
        c.add(
                "到达地热力图",
                index_value[1],
                type_="heatmap",
                label_opts=opts.LabelOpts(formatter="{b}"),
            )

         # 点图
        c.add(
                "到达地位置",
                index_value[1],
                type_="scatter",
                symbol_size=3,
                label_opts=opts.LabelOpts(is_show=False),
            )


        c.add_control_panel(navigation_control_opts=opts.BMapNavigationControlOpts(offset_height=30),
                            scale_control_opts=opts.BMapScaleControlOpts(),
                            )
        return c
Ejemplo n.º 6
0
    def bmap_linemap() -> BMap:
        c = (
            BMap(init_opts=opts.InitOpts(
                theme="white", width="1000px", height="600px")).add_schema(
                    baidu_ak=Baidu_AK,
                    center=[110.3131940000, 20.0274250000],
                    zoom=13)  #缩放比例12-14之间可行
            .set_global_opts(
                title_opts=opts.TitleOpts(
                    title="10/01 国庆节 机场出发"),  # 更改title====================
                visualmap_opts=opts.VisualMapOpts(),
            ))
        # 增加坐标点
        for key, value in index_lngLat.items():
            c.add_coordinate(key, value[0], value[1])

        # 增加坐标点的值
        c.add(
            "",
            index_value,
            type_=ChartType.EFFECT_SCATTER,
            symbol_size=4,
            label_opts=opts.LabelOpts(is_show=False),
            color="white",
        )

        # 增加连线图
        c.add(
            "行程起始-终止位置",
            route_pair,
            type_=ChartType.LINES,
            is_large=True,
            large_threshold=100,
            effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,
                                        symbol_size=5,
                                        color="blue"),
            linestyle_opts=opts.LineStyleOpts(curve=0.1, opacity=0.7),
        )
        # c.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

        c.add_control_panel(
            navigation_control_opts=opts.BMapNavigationControlOpts(
                offset_height=30),
            scale_control_opts=opts.BMapScaleControlOpts(),
        )
        return c
    def bmap_heatmap() -> BMap:
        c = (
            BMap(init_opts=opts.InitOpts(
                theme="white", width="1000px", height="600px")).add_schema(
                    baidu_ak=Baidu_AK,
                    center=[110.3131940000, 20.0274250000],
                    zoom=13)  #缩放比例12-14之间可行
            .set_global_opts(
                title_opts=opts.TitleOpts(
                    title="POI分布"),  # 更改title====================
                visualmap_opts=opts.VisualMapOpts(pos_top='5%',
                                                  pos_right='5%')))
        # 增加坐标点信息
        for key, value in index_lngLat.items():
            c.add_coordinate(key, value[0], value[1])

        # # 不同类数据的点图
        # for label, data in index_value.items():
        #     c.add(
        #             label,
        #             data,
        #             type_="scatter",
        #             symbol_size=3,
        #             # color='rgb(1, 1, 1)',
        #             # itemstyle_opts= opts.ItemStyleOpts(color='rgb(1, 1, 1)'),
        #             label_opts=opts.LabelOpts(is_show=False),
        #         )

        # 不同类数据的热力图
        for label, data in index_value.items():
            c.add(
                label,
                data,
                type_="heatmap",
                label_opts=opts.LabelOpts(formatter="{b}"),
            )

        c.add_control_panel(
            navigation_control_opts=opts.BMapNavigationControlOpts(
                offset_height=30),
            scale_control_opts=opts.BMapScaleControlOpts(),
        )
        return c
Ejemplo n.º 8
0
def get_gridbmap(message) -> BMap:
    BAIDU_AK = "HOTBRAfU1jGcQKHBX15ucKsfZO722eyN"
    pos = (117.20, 39.12)
    #jscode = "console.log('hi hi');"#可嵌入jscode
    #jscode = "functions(param){bmap.addEventListener('click', function(e){alert(e.point.lng + ','+ e.point.lat);});}"
    #每两个点画一条线
    j = [[{
        "coord": [117.20, 39.12]
    }, {
        "coord": [118.21, 41.12]
    }], [{
        "coord": [119.21, 41.12]
    }, {
        "coord": [115.21, 41.12]
    }]]
    c = (
        BMap().add_schema(
            baidu_ak=BAIDU_AK, center=[117.20, 39.12], zoom=12).add(
                "",
                type_="lines",
                data_pair=j,
                is_polyline=True,
                is_large=False,
                linestyle_opts=opts.LineStyleOpts(color="purple",
                                                  opacity=0.6,
                                                  width=1),
            ).set_series_opts(effect_opts=opts.EffectOpts(is_show=False),
                              label_opts=opts.LabelOpts(is_show=False)).
        add_control_panel(
            scale_control_opts=opts.BMapScaleControlOpts(),
            navigation_control_opts=opts.BMapNavigationControlOpts(),
            maptype_control_opts=opts.BMapTypeControlOpts(),
            #copyright_control_opts=opts.BMapCopyrightTypeOpts(copyright_="我的")
            #geo_location_control_opts=opts.BMapGeoLocationControlOpts()
            #overview_map_opts=opts.BMapOverviewMapControlOpts(is_open=True),
        )
        #.add_js_funcs(jscode)
        #.set_global_opts(title_opts=opts.TitleOpts(title="BMap-基本示例"))
    )
    return c
Ejemplo n.º 9
0
def get_bmap(pos) -> BMap:
    BAIDU_AK = "HOTBRAfU1jGcQKHBX15ucKsfZO722eyN"
    #center = (117.20, 39.12)
    c = BMap()
    c.add_schema(baidu_ak=BAIDU_AK,
                 center=[117.20, 39.12],
                 zoom=10,
                 is_roam=False)
    sequence = []
    for i in range(len(pos)):
        #print(pos[i])
        c.add_coordinate(pos[i][0], pos[i][2], pos[i][1])
        sequence.append((str(i), 5))
    c.add(
        "投诉坐标",  #系列名称
        sequence,
        type_="scatter",  #"heatmap" 可以切换显示的类型热力图或散点图
        label_opts=opts.LabelOpts(formatter="{b}"),
        symbol_size=4  #scatter大小
    )
    #.add("bmap",
    #[{"coord":[117.21, 39.13],"sim":10},{"coord":[117.20, 39.13],"sim":20},{"coord":[117.21, 39.12],"sim":5}],
    #[list(z) for z in zip(Faker.provinces, Faker.values())],#zip将迭代对像打包成元组最后的结果是[['浙江',v1],['广东',v2]]
    #[[117.21, 39.13],[117.20, 39.12],[117.22, 39.10],[117.25, 39.11],[117.19, 39.02],[117.20, 39.12]],
    #type_="heatmap",
    #label_opts=opts.LabelOpts(formatter="{b}"))
    c.set_series_opts(
        effect_opts=opts.EffectOpts(is_show=True),
        label_opts=opts.LabelOpts(is_show=False),
    )
    c.add_control_panel(
        scale_control_opts=opts.BMapScaleControlOpts(),
        navigation_control_opts=opts.BMapNavigationControlOpts(),
        maptype_control_opts=opts.BMapTypeControlOpts())
    #copyright_control_opts=opts.BMapCopyrightTypeOpts(copyright_="我的")
    #geo_location_control_opts=opts.BMapGeoLocationControlOpts()
    #overview_map_opts=opts.BMapOverviewMapControlOpts(is_open=True),
    #c.set_global_opts(visualmap_opts=opts.VisualMapOpts(pos_left="right"))
    return c
Ejemplo n.º 10
0
                 })
    coord = prepare_coord(load_street_pickle())
    for s, (long, lat) in coord.items():
        m.add_coordinate(s, long, lat)
    speed, n_slice = read_speed()
    # Match T-GCN expand 3 times... (don't know why)
    idx_map = list(range(0, 114 - 12 - 3 - 1)) + list(range(114, 143 - 12 - 3))
    pred_speed, n_slice1 = read_pred_speed()
    assert len(idx_map) == n_slice1
    m.add(series_name="actual",
          type_="heatmap",
          data_pair=get_data_pair(speed, 0)).add(
              series_name="predict",
              type_="heatmap",
              data_pair=get_data_pair(pred_speed, 0),
          ).add_control_panel(
              copyright_control_opts=opts.BMapCopyrightTypeOpts(position=3),
              maptype_control_opts=opts.BMapTypeControlOpts(
                  type_=BMapType.MAPTYPE_CONTROL_DROPDOWN),
              scale_control_opts=opts.BMapScaleControlOpts(),
              overview_map_opts=opts.BMapOverviewMapControlOpts(is_open=True),
              navigation_control_opts=opts.BMapNavigationControlOpts(),
              geo_location_control_opts=opts.BMapGeoLocationControlOpts(),
          ).set_global_opts(
              visualmap_opts=opts.VisualMapOpts(
                  min_=0,
                  max_=60,
                  range_color=['blue', 'blue', 'green', 'yellow', 'red']),
              title_opts=opts.TitleOpts(title="Traffic Status of Xi'An"))
    m.render('test.html')
Ejemplo n.º 11
0
def bmap_lines() -> BMap:
    with open(
        os.path.join("fixtures", "hangzhou-tracks.json"), "r", encoding="utf-8"
    ) as f:
        j = json.load(f)
    c = (
        BMap()
        .add_schema(
            baidu_ak=BAIDU_MAP_AK,
            center=[120.13066322374, 30.240018034923],
            zoom=14,
            is_roam=True,
            map_style={
                "styleJson": [
                    {
                        "featureType": "water",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "land",
                        "elementType": "all",
                        "stylers": {"color": "#f3f3f3"},
                    },
                    {
                        "featureType": "railway",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "highway",
                        "elementType": "all",
                        "stylers": {"color": "#fdfdfd"},
                    },
                    {
                        "featureType": "highway",
                        "elementType": "labels",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "arterial",
                        "elementType": "geometry",
                        "stylers": {"color": "#fefefe"},
                    },
                    {
                        "featureType": "arterial",
                        "elementType": "geometry.fill",
                        "stylers": {"color": "#fefefe"},
                    },
                    {
                        "featureType": "poi",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "green",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "subway",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "manmade",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "local",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "arterial",
                        "elementType": "labels",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "boundary",
                        "elementType": "all",
                        "stylers": {"color": "#fefefe"},
                    },
                    {
                        "featureType": "building",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "label",
                        "elementType": "labels.text.fill",
                        "stylers": {"color": "#999999"},
                    },
                ]
            },
        )
        .add(
            "",
            type_="lines",
            data_pair=j,
            is_polyline=True,
            is_large=True,
            linestyle_opts=opts.LineStyleOpts(color="purple", opacity=0.6, width=1),
        )
        .add_control_panel(
            maptype_control_opts=opts.BMapTypeControlOpts(
                type_=BMapType.MAPTYPE_CONTROL_DROPDOWN
            ),
            scale_control_opts=opts.BMapScaleControlOpts(),
            overview_map_opts=opts.BMapOverviewMapControlOpts(is_open=True),
        )
        .set_global_opts(title_opts=opts.TitleOpts(title="BMap-杭州热门步行路线"))
    )
    return c
Ejemplo n.º 12
0
     position=0,  # 等同于anchor_top_left,1、2、3分别为右上,左下,右下
     offset_height=50,  # 距离上部偏移量
     offset_width=10,  # 距离左右偏移量
     type_=0,  # 0-4表示NAVIGATION_CONTROL_LARGE/SMALL/PAN/ZOOM,又标准平移缩放滑块/平移缩放/仅平移/仅缩放
     is_show_zoom_info=True,  # 是否显示级别提示信息
     is_enable_geo_location=True,  # 控件是否集成定位功能
 ),  # 若下面还有add_contorl_panel里面的空间调整,这里必须有“,”,若没有,可以没有逗号
 opts.BMapOverviewMapControlOpts(  # 缩略地图控件
     # position=0,  # 等同于anchor_top_left,1、2、3分别为右上,左下,右下
     # offset_height=50,  # 距离上部偏移量
     # offset_width=10,  # 距离左右偏移量
     is_open=True,
 ),
 opts.BMapScaleControlOpts(  # 比例尺控件
     # position=0,  # 等同于anchor_top_left,1、2、3分别为右上,左下,右下
     # offset_height=50,  # 距离上部偏移量
     # offset_width=10,  # 距离左右偏移量
 ),
 opts.BMapTypeControlOpts(  # 切换地图类型的控件
     # position=0,
     type_=2,  # MAPTYPE_CONTROL_HORIZONTAL/DROPDOWN/MAP,按钮水平方式展示为0,下拉列表为1,图片方式为2(设置该类型后无法指定 maptypes 属性)
 ),
 opts.BMapCopyrightTypeOpts(  # 版权控件,您可以在地图上添加自己的版权信息
     # position=0,
     # offset_height=50, # 距离上部偏移量
     # offset_width=10,  # 距离左右偏移量
     copyright_="made by shh",  # Copyright 的文本内容, 可以放入 HTML 标签
 ),
 opts.BMapGeoLocationControlOpts(  # 地图定位的控件,使用 HTML5 浏览器定位功能
     # position=0,
     # offset_height=50, # 距离上部偏移量