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

update: dynamic allocation of marker color and size

parent e424a1ca
No related branches found
No related tags found
1 merge request!1Server
...@@ -4,6 +4,7 @@ import 'package:latlong2/latlong.dart'; // Import LatLng class from the latlong ...@@ -4,6 +4,7 @@ import 'package:latlong2/latlong.dart'; // Import LatLng class from the latlong
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
const String port = "8443"; const String port = "8443";
const String serverURI = "https://127.0.0.1:$port/"; const String serverURI = "https://127.0.0.1:$port/";
const String mapEndpoint = "update_map"; const String mapEndpoint = "update_map";
...@@ -50,12 +51,21 @@ class DefaultPage extends StatefulWidget { ...@@ -50,12 +51,21 @@ class DefaultPage extends StatefulWidget {
_DefaultPageState createState() => _DefaultPageState(); _DefaultPageState createState() => _DefaultPageState();
} }
class MarkerData {
final LatLng location;
final double size;
final Color color;
MarkerData({required this.location, required this.size, required this.color});
}
class _DefaultPageState extends State<DefaultPage> { class _DefaultPageState extends State<DefaultPage> {
late Timer _timer; late Timer _timer;
final List<LatLng> locations = [
LatLng(60.8366, 10.8171), final List<MarkerData> markerList = [
LatLng(60.7366, 10.8471), MarkerData(location: LatLng(60.7266, 10.9771), size: 50.0, color: Colors.blue),
LatLng(60.7266, 10.9771), MarkerData(location: LatLng(60.8366, 10.8171), size: 70.0, color: Colors.red),
MarkerData(location: LatLng(60.7366, 10.8471), size: 60.0, color: Colors.green),
]; ];
// Timer initializer // Timer initializer
...@@ -103,26 +113,26 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -103,26 +113,26 @@ class _DefaultPageState extends State<DefaultPage> {
color: Colors.blue, color: Colors.blue,
child: FlutterMap( child: FlutterMap(
options: MapOptions( options: MapOptions(
center: LatLng(60.7666, 10.8471), // Initial center of the map (latitude and longitude) center: LatLng(60.7666, 10.8471),
zoom: 9.0, // Initial zoom level of the map zoom: 9.0,
), ),
children: [ // Add layers directly as children children: [
TileLayer( TileLayer(
urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: ['a', 'b', 'c'], subdomains: ['a', 'b', 'c'],
), ),
MarkerLayer( MarkerLayer( // Dynamically allocate markers based on a list
markers: locations markers: markerList
.map( .map(
(LatLng location) => Marker( (MarkerData markerData) => Marker(
width: 80.0, width: markerData.size,
height: 80.0, height: markerData.size,
point: location, point: markerData.location,
builder: (ctx) => Container( builder: (ctx) => Container(
child: Icon( child: Icon(
Icons.location_on, Icons.location_on,
color: Colors.blue, color: markerData.color,
size: 50.0, size: markerData.size,
), ),
), ),
), ),
......
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