Skip to content

Commit 2772595

Browse files
committed
Add circle & overlay image layers to EPSG:3413 example
1 parent 5bc5cb0 commit 2772595

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

example/assets/map/epsg3413/amsr2.png

51.9 KB
Loading

example/lib/pages/epsg3413_crs.dart

+46-29
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,10 @@ class _EPSG3413PageState extends State<EPSG3413Page> {
1919

2020
double? maxZoom;
2121

22-
// Define start center
23-
proj4.Point point = proj4.Point(x: 90, y: 0);
24-
25-
String initText = 'Map centered to';
26-
27-
late final proj4.Projection epsg4326;
28-
29-
late final proj4.Projection epsg3413;
30-
3122
@override
3223
void initState() {
3324
super.initState();
3425

35-
epsg4326 = proj4.Projection.get('EPSG:4326')!;
36-
37-
// EPSG:3413 is a user-defined projection from a valid Proj4 definition string
38-
// From: http://epsg.io/3413, proj definition: http://epsg.io/3413.proj4
39-
// Find Projection by name or define it if not exists
40-
epsg3413 = proj4.Projection.get('EPSG:3413') ??
41-
proj4.Projection.add('EPSG:3413',
42-
'+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs');
43-
4426
// 9 example zoom level resolutions
4527
final resolutions = <double>[
4628
32768,
@@ -61,6 +43,13 @@ class _EPSG3413PageState extends State<EPSG3413Page> {
6143

6244
maxZoom = (resolutions.length - 1).toDouble();
6345

46+
// EPSG:3413 is a user-defined projection from a valid Proj4 definition string
47+
// From: http://epsg.io/3413, proj definition: http://epsg.io/3413.proj4
48+
// Find Projection by name or define it if not exists
49+
final proj4.Projection epsg3413 = proj4.Projection.get('EPSG:3413') ??
50+
proj4.Projection.add('EPSG:3413',
51+
'+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs');
52+
6453
epsg3413CRS = Proj4Crs.fromFactory(
6554
code: 'EPSG:3413',
6655
proj4Projection: epsg3413,
@@ -74,8 +63,26 @@ class _EPSG3413PageState extends State<EPSG3413Page> {
7463

7564
@override
7665
Widget build(BuildContext context) {
66+
// These circles should have the same pixel radius on the map
67+
final circles = [
68+
CircleMarker(
69+
point: LatLng(90, 0),
70+
radius: 20000,
71+
useRadiusInMeter: true,
72+
color: Colors.red,
73+
)
74+
];
75+
for (final lon in [-90.0, 0.0, 90.0, 180.0]) {
76+
circles.add(CircleMarker(
77+
point: LatLng(80, lon),
78+
radius: 20000,
79+
useRadiusInMeter: true,
80+
color: Colors.red,
81+
));
82+
}
83+
7784
return Scaffold(
78-
appBar: AppBar(title: const Text('EPSG:4326 CRS')),
85+
appBar: AppBar(title: const Text('EPSG:3413 CRS')),
7986
drawer: buildDrawer(context, EPSG3413Page.route),
8087
body: Padding(
8188
padding: const EdgeInsets.all(8.0),
@@ -92,23 +99,17 @@ class _EPSG3413PageState extends State<EPSG3413Page> {
9299
),
93100
),
94101
),
95-
Padding(
96-
padding: const EdgeInsets.only(top: 8.0, bottom: 2.0),
97-
child: Text(
98-
'$initText (${point.x.toStringAsFixed(5)}, ${point.y.toStringAsFixed(5)}) in EPSG:4326.',
99-
),
100-
),
101-
Padding(
102-
padding: const EdgeInsets.only(top: 2.0, bottom: 2.0),
102+
const Padding(
103+
padding: EdgeInsets.only(top: 8.0, bottom: 2.0),
103104
child: Text(
104-
'Which is (${epsg4326.transform(epsg3413, point).x.toStringAsFixed(2)}, ${epsg4326.transform(epsg3413, point).y.toStringAsFixed(2)}) in EPSG:3413.',
105+
'This page demonstrates some tricky edge-cases for maps with a polar projection.',
105106
),
106107
),
107108
Flexible(
108109
child: FlutterMap(
109110
options: MapOptions(
110111
crs: epsg3413CRS,
111-
center: LatLng(point.x, point.y),
112+
center: LatLng(90, 0),
112113
zoom: 3.0,
113114
maxZoom: maxZoom,
114115
),
@@ -125,6 +126,22 @@ class _EPSG3413PageState extends State<EPSG3413Page> {
125126
layers: ['gebco_north_polar_view'],
126127
),
127128
),
129+
CircleLayerOptions(
130+
circles: circles,
131+
),
132+
OverlayImageLayerOptions(
133+
overlayImages: [
134+
OverlayImage(
135+
bounds: LatLngBounds(
136+
LatLng(72.7911372, 162.6196478),
137+
LatLng(85.2802493, 79.794166),
138+
),
139+
imageProvider: Image.asset(
140+
'map/epsg3413/amsr2.png',
141+
).image,
142+
)
143+
],
144+
)
128145
],
129146
),
130147
),

example/pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ flutter:
5959
- assets/map/anholt_osmbright/14/8725/
6060
- assets/map/anholt_osmbright/14/8726/
6161
- assets/map/anholt_osmbright/14/8727/
62+
- assets/map/epsg3413/amsr2.png

lib/src/layer/overlay_image_layer.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class OverlayImageLayer extends StatelessWidget {
7373
map.project(overlayImage.bounds.northWest) - map.getPixelOrigin(),
7474
map.project(overlayImage.bounds.southEast) - map.getPixelOrigin(),
7575
);
76-
76+
7777
return Positioned(
7878
left: bounds.topLeft.x.toDouble(),
7979
top: bounds.topLeft.y.toDouble(),

0 commit comments

Comments
 (0)