我正在使用 flutter_map_tile_cache lib 来缓存图块,但我无法缓存 WMSTileLayerOptions 图层,请提供任何解决方案
TileLayer(
wmsOptions: WMSTileLayerOptions(
baseUrl: 'https://apps.xyz.com:8080/myserver/wms/?',
layers: ['XYZLAYER:stateboundary],
format: 'image/png',
transparent: true,
),
backgroundColor: Colors.transparent,
userAgentPackageName: 'com.example.xyz',
tileProvider: FMTC.instance('mapStore').getTileProvider(),
),
出现如下错误:- FMTCBrowsingError:无法从缓存或网络加载图块,因为缓存中缺少该图块并且无法建立与服务器的连接。
flutter 库“flutter_map”和“cached_network_image”可以满足我们的要求。
我们需要这样实现:
class CachedNetworkTileProvider extends TileProvider {
@override
ImageProvider getImage(TileCoordinates coordinates, TileLayer options)
{
return CachedNetworkImageProvider(getTileUrl(coordinates, options));
}
}
还有
TileLayer(wmsOptions: WMSTileLayerOptions(
baseUrl: 'https://apps.example.com:8080/myserver/wms/?',
layers: ['XYZLAYER:stateboundary'],
format: 'image/png',
transparent: true,
),
backgroundColor: Colors.transparent,
userAgentPackageName: 'com.example.xyz',
tileProvider: CachedNetworkTileProvider(),
),