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

如何在google_maps_flutter中移除摩洛哥与西撒哈拉的虚线争议边界

如何在Flutter的google_maps_flutter中移除摩洛哥与西撒哈拉之间的争议虚线边界

我在Flutter项目中使用google_maps_flutter包展示谷歌地图,需要显示摩洛哥和西撒哈拉区域,但希望移除二者之间谷歌标记的虚线争议边界。

现有代码

final String _mapStyle = ''' 
[   
  {
    "featureType": "administrative.country",
    "elementType": "geometry.stroke",
    "stylers": [
      { "visibility": "off" }
    ]   
  },   
  {
    "featureType": "administrative.province",
    "elementType": "geometry.stroke",
    "stylers": [
       { "visibility": "off" }
    ]   
  } 
] 
''';

Widget customGooglemap() {
  return Stack(
    alignment: Alignment.center,
    children: [
      Container(
        height: MediaQuery.sizeOf(context).width * 0.7,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8.0),
        ),
        child: ClipRRect(
          borderRadius: BorderRadius.circular(10.0),
          child: GoogleMap(
            mapType: isTypeMap ? MapType.normal : MapType.satellite,
            style: _mapStyle,
            onMapCreated: (GoogleMapController controller) {
              _controller.complete(controller);
            },
            onCameraMove: _onCameraMove, // Updates camera position in real-time
            onCameraIdle: _onCameraIdle,
            onCameraMoveStarted: () {
              _hasUserChangedLocation = true;
              setState(() {});
              print("ONCAMERAMOVESTARTED");
            },
            scrollGesturesEnabled: true,
            zoomGesturesEnabled: true,
            zoomControlsEnabled: true,
            gestureRecognizers: Set()
              ..add(Factory<PanGestureRecognizer>(() => PanGestureRecognizer()))
              ..add(Factory<ScaleGestureRecognizer>(() => ScaleGestureRecognizer()))
              ..add(Factory<OneSequenceGestureRecognizer>(() => EagerGestureRecognizer())),
            initialCameraPosition: _currentCameraPosition ?? _kDefaultMoroccoView,
            myLocationEnabled: isLocationPermissionGranted,
            myLocationButtonEnabled: false,
          ),
        ),
      ),
      Positioned(
        child: SvgPicture.asset(
            'asset/icons/location-icon.svg'), // Fixed marker icon at center
      ),
    ],
  );
}

已尝试的方法

  • 尝试通过自定义地图样式setMapStyle隐藏争议边界
  • 查找过通过地图选项或自定义瓦片图层控制政治边界的方法

目前问题:摩洛哥与西撒哈拉之间的虚线边界仍可见,且当前代码会移除所有地图边界。我希望仅移除二者之间的虚线争议边界,请问这是否可行?能否通过google_maps_flutter或自定义地图样式实现该需求?


解决方案

谷歌地图中的争议边界属于administrative.dispute这个featureType,而非普通的国家或省界。你之前的样式仅关闭了国家和省的边界,因此争议虚线仍会显示。

你可以修改地图样式,专门针对争议边界设置隐藏,同时保留其他正常边界:

final String _mapStyle = ''' 
[
  // 隐藏争议区域的边界
  {
    "featureType": "administrative.dispute",
    "elementType": "geometry.stroke",
    "stylers": [
      { "visibility": "off" }
    ]
  },
  // 保留国家边界(可自定义颜色)
  {
    "featureType": "administrative.country",
    "elementType": "geometry.stroke",
    "stylers": [
      { "visibility": "on" },
      { "color": "#cccccc" }
    ]
  },
  // 保留省/州边界(可自定义颜色)
  {
    "featureType": "administrative.province",
    "elementType": "geometry.stroke",
    "stylers": [
      { "visibility": "on" },
      { "color": "#eeeeee" }
    ]
  }
]
''';

修改后,只会隐藏争议区域的虚线边界,其他正常的国家、省界会保留。

补充说明

  • 谷歌地图样式系统不支持针对特定国家/区域的争议边界单独设置,只能全局隐藏所有争议边界。
  • 若必须仅隐藏摩洛哥和西撒哈拉之间的争议线,可考虑使用自定义瓦片图层,但需要自行提供无争议边界的地图瓦片,实现成本较高,且需遵守地图版权规定。

内容的提问来源于stack exchange,提问作者Sumita Naiya

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 03:15:24