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
2a5118df
Commit
2a5118df
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
fix: shape selection coloring
parent
61569d29
No related branches found
Branches containing commit
No related tags found
Loading
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/widgets/choropleth_map.dart
+58
-51
58 additions, 51 deletions
app/lib/widgets/choropleth_map.dart
app/pubspec.lock
+1
-1
1 addition, 1 deletion
app/pubspec.lock
app/pubspec.yaml
+1
-0
1 addition, 0 deletions
app/pubspec.yaml
with
60 additions
and
52 deletions
app/lib/widgets/choropleth_map.dart
+
58
−
51
View file @
2a5118df
import
'dart:typed_data'
;
import
'package:flutter/material.dart'
;
import
'package:syncfusion_flutter_core/theme.dart'
;
import
'package:syncfusion_flutter_maps/maps.dart'
;
import
'package:latlong2/latlong.dart'
;
import
'../data_classes.dart'
;
/// A class containing thickness data for each subdivision of the map.
...
...
@@ -35,6 +34,7 @@ class ChoroplethMap extends StatefulWidget {
}
class
_ChoroplethMapState
extends
State
<
ChoroplethMap
>
{
late
MapShapeSource
dataSource
;
int
selectedIndex
=
-
1
;
late
MapShapeSource
mapShapeSource
;
late
final
MapZoomPanBehavior
_zoomPanBehavior
=
MapZoomPanBehavior
();
...
...
@@ -52,63 +52,70 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
count
++
;
}
};
// Initialise data source
dataSource
=
MapShapeSource
.
memory
(
widget
.
relation
,
shapeDataField:
'sub_div_id'
,
dataCount:
count
,
primaryValueMapper:
(
int
index
)
=
>
subdivisions
[
index
]
.
sub_div_id
,
shapeColorValueMapper:
(
int
index
)
=
>
subdivisions
[
index
]
.
avgThickness
,
shapeColorMappers:
const
[
MapColorMapper
(
from:
0
,
to:
4
,
color:
Color
(
0xFFff0000
),
text:
'{0},{25}'
),
MapColorMapper
(
from:
4
,
to:
7
,
color:
Color
(
0xffff6a00
),
text:
'75'
),
MapColorMapper
(
from:
7
,
to:
10
,
color:
Color
(
0xFFb1ff00
),
text:
'150'
),
MapColorMapper
(
from:
10
,
to:
400
,
color:
Color
(
0xff4fa8d7
),
text:
'400'
),
],
);
}
@override
Widget
build
(
BuildContext
context
)
{
return
Stack
(
children:
[
SfMaps
(
layers:
[
MapShapeLayer
(
source
:
MapShapeSource
.
memory
(
// Map polygon
widget
.
relation
,
// JSON coordinates from server
shapeDataField:
'sub_div_id'
,
dataCount:
count
,
primaryValueMapper:
(
int
index
)
=
>
subdivisions
[
index
]
.
sub_div_id
,
shapeColorValueMapper:
(
int
index
)
=
>
subdivisions
[
index
]
.
avgThickness
,
shapeColorMappers:
const
[
MapColorMapper
(
from:
0
,
to:
4
,
color:
Color
(
0xFFff0000
),
text:
'{0},{25}'
),
MapColorMapper
(
from:
4
,
to:
7
,
color:
Color
(
0xffff6a00
),
text:
'75'
),
MapColorMapper
(
from:
7
,
to:
10
,
color:
Color
(
0xFFb1ff00
),
text:
'150'
),
MapColorMapper
(
from:
10
,
to:
400
,
color:
Color
(
0xff4fa8d7
),
text:
'400'
),
],
SfMapsTheme
(
data:
SfMapsThemeData
(
// Shape selection behavior
selectionColor:
Colors
.
orange
,
selectionStrokeWidth:
3
,
selectionStrokeColor:
Colors
.
red
[
900
],
),
child:
SfMaps
(
layers:
[
MapShapeLayer
(
source
:
dataSource
,
//zoomPanBehavior: _zoomPanBehavior,
strokeColor:
Colors
.
blue
.
shade50
,
// Shape selection
selectedIndex:
selectedIndex
,
onSelectionChanged:
(
int
index
)
{
setState
(()
{
// Shape selection
selectedIndex
=
index
;
});
widget
.
onSelectionChanged
(
selectedIndex
);
},
),
zoomPanBehavior:
_zoomPanBehavior
,
strokeColor:
Colors
.
blue
.
shade50
,
// Shape selection
selectedIndex:
selectedIndex
,
onSelectionChanged:
(
int
index
)
{
setState
(()
{
selectedIndex
=
index
;
});
widget
.
onSelectionChanged
(
selectedIndex
);
},
selectionSettings:
const
MapSelectionSettings
(
strokeWidth:
3.0
,
// Increase stroke width
color:
Colors
.
black
,
),
),
],
],
),
),
],
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/pubspec.lock
+
1
−
1
View file @
2a5118df
...
...
@@ -454,7 +454,7 @@ packages:
source: hosted
version: "1.2.0"
syncfusion_flutter_core:
dependency:
transitive
dependency:
"direct main"
description:
name: syncfusion_flutter_core
sha256: "3979f0b1c5a97422cadae52d476c21fa3e0fb671ef51de6cae1d646d8b99fe1f"
...
...
This diff is collapsed.
Click to expand it.
app/pubspec.yaml
+
1
−
0
View file @
2a5118df
...
...
@@ -16,6 +16,7 @@ dependencies:
fl_chart
:
^0.20.0-nullsafety1
# Charts and diagrams
google_fonts
:
any
# Fonts
syncfusion_flutter_maps
:
^20.4.41
# Choropleth map
syncfusion_flutter_core
:
any
# Choropleth shape selection
path_provider
:
^2.0.8
shared_preferences
:
any
# Persistent data storage
...
...
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