从路径颤振映射框符号图标

时间:2020-07-09 17:42:02

标签: flutter mapbox symbols mapbox-gl mapbox-marker

我有一个问题,因为它会在计算机上生成图形并将其保存到temp文件夹中,并且Image.assets(路径)通常会向我读取它,但mapbox不会并且不会向我显示此图标,并且所有通常会显示该文件夹中的其他资产,有人有一些想法吗?

 String path = await GenerateSymbol.capturePng(screenshotKey);
 
            m.addSymbol(
              SymbolOptions(
                geometry: LatLng(
                  50.17026301,
                  18.90532861,
                ),
                iconImage: path,
                iconSize: 10,
                iconAnchor: "bottom",
              ),
              {"id": "test"},
            );

其他班级

class GenerateSymbol {

static Future<String> _saveSymbol(Uint8List image) async {
  final directory = await getApplicationDocumentsDirectory();
  File _file = File(directory.absolute.path + '/symbol.png')
  ..writeAsBytesSync(image);
  print(_file.path);
  return _file.path;
}

static Future<String> capturePng(GlobalKey key) async {
  RenderRepaintBoundary boundary = key.currentContext.findRenderObject();

  if (boundary.debugNeedsPaint) {
    await Future.delayed(const Duration(milliseconds: 20));
    return capturePng(key);
  }

  var image = await boundary.toImage();
  var byteData = await image.toByteData(format: ImageByteFormat.png);
  var pngBytes = byteData.buffer.asUint8List();

  String path = await _saveSymbol(pngBytes);

  return path;
 }
}

0 个答案:

没有答案