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

fix: shape selection

parent a3ef2ca7
No related branches found
No related tags found
1 merge request!7Clhp map
import 'dart:typed_data'; import 'dart:typed_data';
import '../marker_handler/marker_data.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_maps/maps.dart'; import 'package:syncfusion_flutter_maps/maps.dart';
import 'dart:math'; import 'dart:math';
import '../marker_handler/marker_data.dart'; import 'dart:convert';
/// A class containing thickness data for each subdivision of the map. /// A class containing thickness data for each subdivision of the map.
class IceThicknessModel { class IceThicknessModel {
IceThicknessModel(this.sub_div_id, this.thickness, this.color, this.isSelected); IceThicknessModel(this.sub_div_id, this.thickness, this.color, this.savedColor);
final String sub_div_id; final String sub_div_id;
final int thickness; final int thickness;
Color color; Color color;
bool isSelected; final Color savedColor;
} }
/// ChoroplethMap is a stateful widget that contains a choropleth map. /// ChoroplethMap is a stateful widget that contains a choropleth map.
/// The map is created using the Syncfusion Flutter Maps library and /// The map is created using the Syncfusion Flutter Maps library and
/// coordinates fetched from the server. /// coordinates fetched from the server.
class ChoroplethMap extends StatefulWidget { class ChoroplethMap extends StatefulWidget {
const ChoroplethMap({ const ChoroplethMap({Key? key,
Key? key,
required this.relation, required this.relation,
required this.measurements, required this.measurements
}) : super(key: key); }) : super(key: key);
final Uint8List relation; final Uint8List relation;
...@@ -32,10 +32,11 @@ class ChoroplethMap extends StatefulWidget { ...@@ -32,10 +32,11 @@ class ChoroplethMap extends StatefulWidget {
} }
class _ChoroplethMapState extends State<ChoroplethMap> { class _ChoroplethMapState extends State<ChoroplethMap> {
int selectedIndex = -1;
late MapShapeSource mapShapeSource; late MapShapeSource mapShapeSource;
late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior(); late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior();
List<IceThicknessModel> iceThicknessList = <IceThicknessModel>[]; List<IceThicknessModel> iceThicknessList = <IceThicknessModel>[];
List<Color> testColors = [ List<Color> testColors = [ // NB test color
const Color(0xff8a003b), const Color(0xff8a003b),
const Color(0xff8a4300), const Color(0xff8a4300),
const Color(0xff8a7a00), const Color(0xff8a7a00),
...@@ -49,11 +50,11 @@ class _ChoroplethMapState extends State<ChoroplethMap> { ...@@ -49,11 +50,11 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
final Random random = Random(); final Random random = Random();
for (int i = 0; i <= 120; i++) { for (int i = 0; i <= 120; i++) {
int ran = random.nextInt(4); // NB test color int ran = random.nextInt(5); // NB test color
Color randomColor = testColors[ran]; Color randomColor = testColors[ran];
int randomNumber = random.nextInt(21); // 0 -> 20, NB: temp test data int randomNumber = random.nextInt(21); // 0 -> 20, NB: temp test data
iceThicknessList.add(IceThicknessModel(i.toString(), randomNumber, randomColor, false)); iceThicknessList.add(IceThicknessModel(i.toString(), randomNumber, randomColor, randomColor));
} }
} }
...@@ -64,23 +65,32 @@ class _ChoroplethMapState extends State<ChoroplethMap> { ...@@ -64,23 +65,32 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
SfMaps( SfMaps(
layers: [ layers: [
MapShapeLayer( MapShapeLayer(
source: MapShapeSource.memory( source: MapShapeSource.memory( // Map polygon
widget.relation, widget.relation, // JSON coordinates from server
shapeDataField: 'sub_div_id', shapeDataField: 'sub_div_id',
dataCount: iceThicknessList.length, dataCount: iceThicknessList.length,
primaryValueMapper: (int index) => iceThicknessList[index].sub_div_id, primaryValueMapper: (int index) => iceThicknessList[index].sub_div_id,
shapeColorValueMapper: (int index) => iceThicknessList[index].color, shapeColorValueMapper: (int index) => iceThicknessList[index].color,
), ),
//color: Colors.blue.shade400, // Map color
zoomPanBehavior: _zoomPanBehavior, zoomPanBehavior: _zoomPanBehavior,
strokeColor: Colors.black, strokeColor: Colors.black,
// Shape selection
selectedIndex: selectedIndex,
onSelectionChanged: (int index) { onSelectionChanged: (int index) {
setState(() { setState(() {
selectedIndex = index;
for (int i = 0; i < iceThicknessList.length; i++) { for (int i = 0; i < iceThicknessList.length; i++) {
iceThicknessList[i].isSelected = i == index; iceThicknessList[i].color = i == index ? Colors.red : iceThicknessList[i].savedColor;
iceThicknessList[i].color = i == index ? Colors.red : iceThicknessList[i].color;
} }
}); });
print("Selection triggered");
}, },
selectionSettings: MapSelectionSettings(
color: Colors.orange,
strokeColor: Colors.red[900],
strokeWidth: 3,
),
), ),
], ],
), ),
...@@ -88,3 +98,4 @@ class _ChoroplethMapState extends State<ChoroplethMap> { ...@@ -88,3 +98,4 @@ class _ChoroplethMapState extends State<ChoroplethMap> {
); );
} }
} }
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