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