Skip to content
Snippets Groups Projects
Commit 30a6d1b7 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: full shape selection

parent 2a5118df
No related branches found
No related tags found
1 merge request!10Clhp map
......@@ -34,22 +34,20 @@ class ChoroplethMap extends StatefulWidget {
}
class _ChoroplethMapState extends State<ChoroplethMap> {
late MapShapeSource dataSource;
int selectedIndex = -1;
Color selectedColor = Colors.grey; // Initialise to gray
late MapShapeSource dataSource;
late MapShapeSource mapShapeSource;
late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior();
List<SubDiv> subdivisions = <SubDiv>[];
int count = 0;
@override
void initState() {
super.initState();
// Create list of all subdivisions
// Extract all subdivisions from list of measurements
for (Measurement measurement in widget.measurements) {
for (SubDiv subdivision in measurement.subDivs) {
subdivisions.add(subdivision);
count++;
}
};
......@@ -57,32 +55,32 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
dataSource = MapShapeSource.memory(
widget.relation,
shapeDataField: 'sub_div_id',
dataCount: count,
dataCount: subdivisions.length,
primaryValueMapper: (int index) =>
subdivisions[index].sub_div_id,
shapeColorValueMapper: (int index) =>
subdivisions[index].avgThickness,
subdivisions[index].avgThickness, // NB will later be minThickness, fix in server first
shapeColorMappers: const [
MapColorMapper(
from: 0,
to: 4,
color: Color(0xFFff0000),
text: '{0},{25}'),
text: '{0},{4}'),
MapColorMapper(
from: 4,
to: 7,
to: 6,
color: Color(0xffff6a00),
text: '75'),
text: '6'),
MapColorMapper(
from: 7,
to: 10,
from: 6,
to: 8,
color: Color(0xFFb1ff00),
text: '150'),
text: '8'),
MapColorMapper(
from: 10,
from: 8,
to: 400,
color: Color(0xff4fa8d7),
text: '400'),
color: Color(0xFF00d6ff),
text: '>8'),
],
);
}
......@@ -92,8 +90,8 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
return Stack(
children: [
SfMapsTheme(
data: SfMapsThemeData( // Shape selection behavior
selectionColor: Colors.orange,
data: SfMapsThemeData( // Coloring of selected shape
selectionColor: selectedColor,
selectionStrokeWidth: 3,
selectionStrokeColor: Colors.red[900],
),
......@@ -101,13 +99,14 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
layers: [
MapShapeLayer(
source: dataSource,
//zoomPanBehavior: _zoomPanBehavior,
zoomPanBehavior: _zoomPanBehavior,
strokeColor: Colors.blue.shade50,
// Shape selection
selectedIndex: selectedIndex,
onSelectionChanged: (int index) {
setState(() { // Shape selection
onSelectionChanged: (int index) { // Shape selection behavior
setState(() {
selectedIndex = index;
selectedColor = subdivisions[index].color.withOpacity(0.7);
});
widget.onSelectionChanged(selectedIndex);
},
......
No preview for this file type
......@@ -85,7 +85,7 @@ def get_all_markers(self, cursor, waterBodyName):
'CenLatitude': 7.0,
'CenLongitude': 8.0,
'Accuracy': 1.0,
'Color': calculateColor(min_thickness)
'Color': calculateColor(avg_thickness)
}
sub_divisions.append(subdivision)
......@@ -134,7 +134,7 @@ def calculateColor(thickness: float): # NB not final colors nor ranges
if 0 < thickness <= 4:
return 0xFFff0000 # Red
elif 4 < thickness <= 6:
return 0xFFff9400 # Orange
return 0xffff6a00 # Orange
elif 6 < thickness <= 8:
return 0xFFb1ff00 # Green
elif thickness > 8:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment