You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为FlutterMap中的MapBox瓦片添加版权归属信息?

在FlutterMap中添加MapBox版权标识的实现方法

核心实现思路

MapBox要求必须同时展示Logo和文字版权信息,不需要导出带标识的瓦片,直接在FlutterMap的布局中添加对应组件即可,具体步骤如下:

步骤1:准备MapBox Logo资源

提前从MapBox官方获取Logo图片(提供白色、深色等不同版本,适配你的地图样式),将图片放入项目的assets/images目录,并在pubspec.yaml中配置资源路径:

flutter:
  assets:
    - assets/images/mapbox_logo.png

步骤2:添加版权组件到FlutterMap

在FlutterMap的nonRotatedChildren列表末尾添加一个Align组件,固定版权信息在地图右下角(符合MapBox的放置规范),包含Logo和版权文本:

修改后的完整代码

FlutterMap(
  options: MapOptions(
    center: userLocation ?? bikePosition ?? LatLng(46.94809, 7.44744),
    zoom: 8.0,
    minZoom: 4.0,
    maxZoom: 18.0,
    interactiveFlags: InteractiveFlag.all & ~InteractiveFlag.rotate,
  ),
  nonRotatedChildren: [
    isSatellite
        ? TileLayer(
            urlTemplate:
                "https://api.mapbox.com/styles/v1/twinnerag/cllnbkuiw000c01pe82l86m0s/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoidHdpbm5lcmFnIiwiYSI6ImNsbG1ib3FmdDFoZWEzY3Q2ODRoamloN2UifQ.FVQHAk7oy1RCyvlDqeZW5A",
          )
        : TileLayer(
            urlTemplate:
                "https://api.mapbox.com/styles/v1/twinnerag/cllnbhfsb000b01nz01rg3kby/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoidHdpbm5lcmFnIiwiYSI6ImNsbG1ib3FmdDFoZWEzY3Q2ODRoamloN2UifQ.FVQHAk7oy1RCyvlDqeZW5A"),
    MarkerLayer(
      markers: [
        if (bike != null)
          if (bike.lastLat != null && bike.lastLong != null)
            Marker(
              width: 40.0,
              height: 40.0,
              point: bikePosition,
              builder: (ctx) => Container(
                alignment: Alignment.centerLeft,
                width: 200,
                padding: const EdgeInsets.only(left: 4.5),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(100),
                ),
                child: const Icon(
                  CustomIcons.bike_icon,
                  size: 18,
                  color: CustomColors.copper,
                ),
              ),
            ),
        if (userLocation != null)
          Marker(
            width: 20.0,
            height: 20.0,
            point: userLocation!,
            builder: (ctx) => Container(
              width: 0.1,
              decoration: BoxDecoration(
                color: CustomColors.gray_secondary,
                borderRadius: BorderRadius.circular(100),
                border: Border.all(
                  color: CustomColors.copper,
                  width: 3,
                ),
              ),
            ),
          ),
      ],
    ),
    // MapBox版权信息组件
    Align(
      alignment: Alignment.bottomRight,
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            // MapBox Logo
            Image.asset(
              "assets/images/mapbox_logo.png",
              width: 30,
              height: 30,
            ),
            const SizedBox(width: 4),
            // 版权文本
            const Text(
              "© 2024 Mapbox © 2024 OpenStreetMap contributors",
              style: TextStyle(fontSize: 10),
            ),
          ],
        ),
      ),
    ),
  ],
)

关键规范要求

  • 版权信息必须放在地图右下角,不能被其他UI元素遮挡
  • Logo和文本必须同时展示,不能省略任意一项
  • 文本内容必须包含© Mapbox和© OpenStreetMap contributors,年份可根据实际情况更新
  • 确保Logo大小适配地图,不影响用户体验

关于MapBox Studio导出瓦片的说明

MapBox Studio无法直接导出带版权标识的瓦片,官方明确要求在应用层面单独添加版权组件,这样能保证地图缩放、拖动时标识始终可见且符合版权规范。

内容的提问来源于stack exchange,提问作者Ilian Gion Häsler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 02:44:54