Using flutter_map: ^7.0.2
, the code for a page widget below aims to present a map, based on the example in the docs and the custom CRS example. When I set wms
to false
, the page correctly renders an OSM map. However, the custom CRS implementation (wms = true
) does not seem to be working – an all-grey ‘map’/image is shown. Looking at the debug tools, it appears that no WMS requests are being made which would suggest some configuration here is wrong leading to flutter map not being able to correctly determine how to display the desired map. However, I am clueless what to try next as no exception or other error seems to occur. The documentation is quite scarce on this so I found no real help there either.
What should be changed in order for the WMS map to be correctly rendered?
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:proj4dart/proj4dart.dart' as proj4;
class PlayMapPage extends StatefulWidget {
const PlayMapPage({super.key});
@override
State<PlayMapPage> createState() => _PlayMapPageState();
}
class _PlayMapPageState extends State<PlayMapPage> {
@override
Widget build(BuildContext context) {
const wms = true;
var dutchGridProjection = proj4.Projection.add('EPSG:28992', '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725 +units=m +no_defs');
final resolutions = <double>[
32768,
16384,
8192,
4096,
2048,
1024,
512,
256,
128,
];
final dutchGridBounds = Bounds<double>(
const Point<double>(-7000, 289000),
const Point<double>(300000, 629000),
);
var dutchGridCRS = Proj4Crs.fromFactory(
code: 'EPSG:28992',
proj4Projection: dutchGridProjection,
resolutions: resolutions,
bounds: dutchGridBounds,
origins: const [Point(0, 0)],
);
return Scaffold(
appBar: AppBar(),
body: FlutterMap(
options: const MapOptions(
initialCenter: wms ? LatLng(128000, 445000) : LatLng(52, 5), // Leaving this at (52, 5) also dose not work.
initialZoom: wms ? 7 : 9,
),
children: [
if (wms)
TileLayer( // Display map tiles from any source
userAgentPackageName: 'com.my-app.app',
maxNativeZoom: resolutions.length, // Scale tiles when the server doesn't support higher zoom levels
//maxZoom: resolutions.length * 1.0,
wmsOptions: WMSTileLayerOptions(
baseUrl: 'https://service.pdok.nl/brt/topraster/wms/v1_0?', // request=GetCapabilities&service=wms
layers: const ['top25raster'],
crs: dutchGridCRS,
),
)
else
TileLayer( // Display map tiles from any source
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', // OSMF's Tile Server
userAgentPackageName: 'com.my-app.app',
maxNativeZoom: 19, // Scale tiles when the server doesn't support higher zoom levels
),
const RichAttributionWidget(
attributions: [
TextSourceAttribution(
'OpenStreetMap contributors',
),
],
),
],
),
);
}
}