Esempio 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)
Esempio n. 2
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')
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
         title_textstyle_opts=opts.TextStyleOpts(color="yellow"),  # 最开始颜色为#fff,但改为黄色更好看
     )
 )
     .add_control_panel(
     # navigation_control_opts=opts.BMapNavigationControlOpts(position=BMapType.ANCHOR_TOP_RIGHT),
     opts.BMapNavigationControlOpts(  # 地图的平移缩放控件
         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,  # 距离左右偏移量