给地图加一个layer/tile

Add a layer/tile to the map

我正在使用 Mapbox 在 Flutter 中开发一个项目,我正在寻找一种方法将图层或图块导入我的地图,例如这个例子(在 JS 中): https://docs.mapbox.com/mapbox-gl-js/example/adjust-layer-opacity/

到目前为止我可以显示地图了:

import 'package:mapbox_gl/mapbox_gl.dart';

class MapsDemo extends StatelessWidget {

  static const String ACCESS_TOKEN = "...";
  MapboxMapController mapController;

  static const LatLng SOURCE_LOCATION = LatLng(0.0, 0.0);

  void _onMapCreated(MapboxMapController controller) {
    mapController = controller;
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        body: MapboxMap(
      accessToken: MapsDemo.ACCESS_TOKEN,
      onMapCreated: _onMapCreated,
      initialCameraPosition: const CameraPosition(target: SOURCE_LOCATION),
    ));
  }
}

void main() {
  runApp(MaterialApp(home: MapsDemo()));
}

所以这是我的完整问题: 有没有办法获得给定位置的 x*x 正方形(或圆弧)layer/tile 并将其显示在地图上的正确坐标处?

谢谢!

我不确定 mapbox_gl 包是否支持图层,但有一个完整的包可以在地图上找到添加的图层。也许你可以检查这个。

https://pub.dev/packages/flutter_map

编辑: MapboxMapController 中有两个方法。你可以使用它们。

Future<List> queryRenderedFeatures(
     Point<double> point, List<String> layerIds, List<Object> filter) async {
   return MapboxGlPlatform.getInstance(_id)
       .queryRenderedFeatures(point, layerIds, filter);
 }

 Future<List> queryRenderedFeaturesInRect(
     Rect rect, List<String> layerIds, String filter) async {
   return MapboxGlPlatform.getInstance(_id)
       .queryRenderedFeaturesInRect(rect, layerIds, filter);
 }

最好的方法是按照 Akif 的建议使用 flutter_map: https://pub.dev/packages/flutter_map https://github.com/fleaflet/flutter_map

在他们的示例中,页面“overlay_image”完全符合我的要求。