Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sara Savanovic Djordjevic
PROG2900
Commits
2d6d1f8e
Commit
2d6d1f8e
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: InteractivePolygon
parent
056e99b2
No related branches found
No related tags found
1 merge request
!3
Choropleth map implementation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/lib/pages/widgets/interactive_polygon.dart
+60
-16
60 additions, 16 deletions
app/lib/pages/widgets/interactive_polygon.dart
app/lib/pages/widgets/map_widget.dart
+5
-16
5 additions, 16 deletions
app/lib/pages/widgets/map_widget.dart
with
65 additions
and
32 deletions
app/lib/pages/widgets/interactive_polygon.dart
+
60
−
16
View file @
2d6d1f8e
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'../marker_handler/marker_data.dart'
;
import
'../marker_handler/marker_data.dart'
;
import
'package:latlong2/latlong.dart'
as
latLng
;
// InteractivePolygon returns a Polygon object wrapped in a
GestureDetector
// InteractivePolygon returns a Polygon object wrapped in a
CustomPaint,
// in order to make the Polygon clickable
//
which is then wrapped in a GestureDetector. This is
in order to make the Polygon clickable
class
InteractivePolygon
extends
StatelessWidget
{
class
InteractivePolygon
extends
StatelessWidget
{
final
List
<
Offset
>
points
;
final
List
<
latLng
.
LatLng
>
points
;
final
void
Function
(
Measurement
)
?
onTap
;
final
void
Function
(
Measurement
)
?
onTap
;
final
Color
color
;
final
Color
color
;
final
double
strokeWidth
;
final
double
strokeWidth
;
...
@@ -24,7 +25,8 @@ class InteractivePolygon extends StatelessWidget {
...
@@ -24,7 +25,8 @@ class InteractivePolygon extends StatelessWidget {
child:
CustomPaint
(
child:
CustomPaint
(
painter:
PolygonPainter
(
painter:
PolygonPainter
(
points:
points
,
points:
points
,
color:
color
,
bodyColor:
color
,
borderColor:
Colors
.
deepOrange
,
strokeWidth:
strokeWidth
,
strokeWidth:
strokeWidth
,
),
),
),
),
...
@@ -35,39 +37,81 @@ class InteractivePolygon extends StatelessWidget {
...
@@ -35,39 +37,81 @@ class InteractivePolygon extends StatelessWidget {
// PolygonPainter takes the points, color, and stroke width from a
// PolygonPainter takes the points, color, and stroke width from a
// object of type InteractivePolygon, and renders it
// object of type InteractivePolygon, and renders it
class
PolygonPainter
extends
CustomPainter
{
class
PolygonPainter
extends
CustomPainter
{
final
List
<
Offset
>
points
;
final
List
<
latLng
.
LatLng
>
points
;
final
Color
color
;
final
Color
bodyColor
;
final
Color
borderColor
;
final
double
strokeWidth
;
final
double
strokeWidth
;
PolygonPainter
({
PolygonPainter
({
required
this
.
points
,
required
this
.
points
,
required
this
.
c
olor
,
required
this
.
bodyC
olor
,
required
this
.
strokeWidth
,
required
this
.
strokeWidth
,
required
this
.
borderColor
,
});
});
// paint() iterates through all the vertices of the polygon and connects
// paint() iterates through all the vertices of the polygon and connects
// each sequential pair with a line
// each sequential pair with a line
@override
@override
void
paint
(
Canvas
canvas
,
Size
size
)
{
void
paint
(
Canvas
canvas
,
Size
size
)
{
final
paint
=
Paint
()
final
Paint
body
=
Paint
();
body
.
.
color
=
bodyColor
.
.
style
=
PaintingStyle
.
fill
.
.
strokeWidth
=
0
;
final
Paint
border
=
Paint
();
border
.
.
color
=
borderColor
.
.
style
=
PaintingStyle
.
stroke
.
.
strokeCap
=
StrokeCap
.
round
.
.
strokeWidth
=
1.0
;
final
path
=
Path
();
if
(
points
.
isNotEmpty
)
{
final
firstPoint
=
points
.
first
;
path
.
moveTo
(
firstPoint
.
latitude
,
firstPoint
.
longitude
);
for
(
var
i
=
1
;
i
<
points
.
length
;
i
++
)
{
final
point
=
points
[
i
];
path
.
lineTo
(
point
.
latitude
,
point
.
longitude
);
}
path
.
close
();
canvas
.
drawPath
(
path
,
body
);
// Render body
canvas
.
drawPath
(
path
,
border
);
// Render border
}
else
{
print
(
"Error in rendering polygon. No points provided"
);
}
/*final paint = Paint()
..color = color
..color = color
..style = PaintingStyle.stroke
..style = PaintingStyle.stroke
..strokeWidth = strokeWidth;
..strokeWidth = strokeWidth;
final path = Path();
final path = Path();
path
.
moveTo
(
points
[
0
]
.
dx
,
points
[
0
]
.
dy
);
if (points.isNotEmpty) {
for
(
var
i
=
1
;
i
<
points
.
length
;
i
++
)
{
final firstPoint = points.first;
path
.
lineTo
(
points
[
i
]
.
dx
,
points
[
i
]
.
dy
);
// Render line between vertices
path.moveTo(firstPoint.latitude, firstPoint.longitude);
}
path
.
close
();
canvas
.
drawPath
(
path
,
paint
);
for (var i = 1; i < points.length; i++) {
final point = points[i];
path.lineTo(point.latitude, point.longitude);
}
path.close();
canvas.drawPath(path, paint);
}
else {
print("Error in rendering polygon. No points provided");
}*/
}
}
@override
@override
bool
shouldRepaint
(
PolygonPainter
oldDelegate
)
{
bool
shouldRepaint
(
PolygonPainter
oldDelegate
)
{
return
oldDelegate
.
points
!=
points
||
return
oldDelegate
.
points
!=
points
||
oldDelegate
.
c
olor
!=
c
olor
||
oldDelegate
.
bodyC
olor
!=
bodyC
olor
||
oldDelegate
.
strokeWidth
!=
strokeWidth
;
oldDelegate
.
strokeWidth
!=
strokeWidth
;
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/lib/pages/widgets/map_widget.dart
+
5
−
16
View file @
2d6d1f8e
...
@@ -6,6 +6,7 @@ import 'stat_charts.dart';
...
@@ -6,6 +6,7 @@ import 'stat_charts.dart';
import
'sat_layer.dart'
;
import
'sat_layer.dart'
;
import
'package:flutter_map/flutter_map.dart'
;
import
'package:flutter_map/flutter_map.dart'
;
import
'interactive_polygon.dart'
;
import
'interactive_polygon.dart'
;
import
'package:latlong2/latlong.dart'
as
latLng
;
/// MapContainerWidget is the main widget that contains the map with all
/// MapContainerWidget is the main widget that contains the map with all
...
@@ -69,21 +70,9 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
...
@@ -69,21 +70,9 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
urlTemplate:
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
,
urlTemplate:
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
,
subdomains:
const
[
'a'
,
'b'
,
'c'
],
subdomains:
const
[
'a'
,
'b'
,
'c'
],
),
),
/*PolygonLayer(
polygons: widget.markerList.map((Measurement measurement) {
return Polygon(
points: points, // Use list of corner coordinates to render polygon
color: Colors.blue.withOpacity(0.5),
isFilled: true,
);
}).toList(),
),*/
// Custom polygon class for clickable polygons
// Custom polygon class for clickable polygons
InteractivePolygon
(
InteractivePolygon
(
// Map corner coordinates for each measurement to Offset object
points:
widget
.
markerList
.
expand
((
measurement
)
=
>
measurement
.
corners
)
.
toList
(),
points:
widget
.
markerList
.
expand
((
measurement
)
=
>
measurement
.
corners
.
map
((
corner
)
=
>
Offset
(
corner
.
latitude
,
corner
.
longitude
)))
.
toList
(),
onTap:
(
Measurement
measurement
)
{
// Pass current measurement to onTap
onTap:
(
Measurement
measurement
)
{
// Pass current measurement to onTap
setState
(()
{
setState
(()
{
selectedMarker
=
measurement
;
// Set selectedMarker to clicked measurement
selectedMarker
=
measurement
;
// Set selectedMarker to clicked measurement
...
@@ -103,10 +92,10 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
...
@@ -103,10 +92,10 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
selectedMarker
=
measurement
;
selectedMarker
=
measurement
;
});
});
},
},
child:
const
Icon
(
child:
Icon
(
Icons
.
severe_cold
,
Icons
.
severe_cold
,
color:
Colors
.
blue
,
color:
measurement
==
selectedMarker
?
Colors
.
green
:
Colors
.
blue
,
size:
30.0
,
size:
measurement
==
selectedMarker
?
40.0
:
30.0
,
),
),
),
),
);
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment