Kml, kmz és geojson import és térképi megjelnítésük.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
// Importált réteg modellje.
|
||||
// A GeoJsonParser közvetlenül flutter_map objektumokat gyárt,
|
||||
// ezeket csomagoljuk egy kezelhető rétegbe.
|
||||
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:terepi_seged/enums/layer_import_source_type.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class ImportedLayer {
|
||||
final String id;
|
||||
final String name;
|
||||
final LayerImportSourceType sourceType;
|
||||
|
||||
// flutter_map objektumok — közvetlenül a réteg widgetekbe kerülnek
|
||||
final List<Marker> markers;
|
||||
final List<Polyline> polylines;
|
||||
final List<Polygon> polygons;
|
||||
|
||||
final bool isVisible;
|
||||
final DateTime importedAt;
|
||||
|
||||
const ImportedLayer({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.sourceType,
|
||||
required this.markers,
|
||||
required this.polylines,
|
||||
required this.polygons,
|
||||
this.isVisible = true,
|
||||
required this.importedAt,
|
||||
});
|
||||
|
||||
// ── Statisztikák ──────────────────────────────────────────────────
|
||||
|
||||
int get featureCount => markers.length + polylines.length + polygons.length;
|
||||
|
||||
bool get isEmpty => featureCount == 0;
|
||||
|
||||
// ── Bounding box — zoom a rétegre ─────────────────────────────────
|
||||
|
||||
LatLngBounds? get bounds {
|
||||
final points = <LatLng>[
|
||||
...markers.map((m) => m.point),
|
||||
...polylines.expand((p) => p.points),
|
||||
...polygons.expand((p) => p.points),
|
||||
];
|
||||
if (points.isEmpty) return null;
|
||||
|
||||
var minLat = points.first.latitude;
|
||||
var maxLat = points.first.latitude;
|
||||
var minLon = points.first.longitude;
|
||||
var maxLon = points.first.longitude;
|
||||
|
||||
for (final p in points) {
|
||||
if (p.latitude < minLat) minLat = p.latitude;
|
||||
if (p.latitude > maxLat) maxLat = p.latitude;
|
||||
if (p.longitude < minLon) minLon = p.longitude;
|
||||
if (p.longitude > maxLon) maxLon = p.longitude;
|
||||
}
|
||||
|
||||
return LatLngBounds(
|
||||
LatLng(minLat, minLon),
|
||||
LatLng(maxLat, maxLon),
|
||||
);
|
||||
}
|
||||
|
||||
ImportedLayer copyWith({bool? isVisible}) => ImportedLayer(
|
||||
id: id,
|
||||
name: name,
|
||||
sourceType: sourceType,
|
||||
markers: markers,
|
||||
polylines: polylines,
|
||||
polygons: polygons,
|
||||
isVisible: isVisible ?? this.isVisible,
|
||||
importedAt: importedAt,
|
||||
);
|
||||
|
||||
// ── Gyártó: GeoJsonParser kimenetéből ─────────────────────────────
|
||||
|
||||
static ImportedLayer fromGeoJsonParser({
|
||||
required dynamic parser, // GeoJsonParser
|
||||
required String name,
|
||||
LayerImportSourceType source = LayerImportSourceType.geoJson,
|
||||
}) {
|
||||
return ImportedLayer(
|
||||
id: const Uuid().v4(),
|
||||
name: name,
|
||||
sourceType: source,
|
||||
markers: List.from(parser.markers as List),
|
||||
polylines: List.from(parser.polylines as List),
|
||||
polygons: List.from(parser.polygons as List),
|
||||
importedAt: DateTime.now(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:terepi_seged/enums/layer_import_source_type.dart';
|
||||
|
||||
class ImportedLayerMeta {
|
||||
final String id;
|
||||
final String name;
|
||||
final LayerImportSourceType sourceType;
|
||||
final String localPath; // fájl elérési út
|
||||
final String? storagePath; // Supabase Storage (megosztáskor)
|
||||
final bool isVisible;
|
||||
final int? projectId;
|
||||
final DateTime importedAt;
|
||||
final DateTime? syncedAt;
|
||||
|
||||
const ImportedLayerMeta({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.sourceType,
|
||||
required this.localPath,
|
||||
this.storagePath,
|
||||
this.isVisible = true,
|
||||
this.projectId,
|
||||
required this.importedAt,
|
||||
this.syncedAt,
|
||||
});
|
||||
|
||||
bool get isSynced => storagePath != null;
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'source_type': sourceType.name,
|
||||
'local_path': localPath,
|
||||
'storage_path': storagePath,
|
||||
'is_visible': isVisible ? 1 : 0,
|
||||
'project_id': projectId,
|
||||
'imported_at': importedAt.toIso8601String(),
|
||||
'synced_at': syncedAt?.toIso8601String(),
|
||||
};
|
||||
|
||||
factory ImportedLayerMeta.fromMap(Map<String, dynamic> m) =>
|
||||
ImportedLayerMeta(
|
||||
id: m['id'] as String,
|
||||
name: m['name'] as String,
|
||||
sourceType:
|
||||
LayerImportSourceType.values.byName(m['source_type'] as String),
|
||||
localPath: m['local_path'] as String,
|
||||
storagePath: m['storage_path'] as String?,
|
||||
isVisible: (m['is_visible'] as int) == 1,
|
||||
projectId: m['project_id'] as int?,
|
||||
importedAt: DateTime.parse(m['imported_at'] as String),
|
||||
syncedAt: m['synced_at'] != null
|
||||
? DateTime.parse(m['synced_at'] as String)
|
||||
: null,
|
||||
);
|
||||
|
||||
ImportedLayerMeta copyWith({
|
||||
bool? isVisible,
|
||||
String? storagePath,
|
||||
DateTime? syncedAt,
|
||||
}) =>
|
||||
ImportedLayerMeta(
|
||||
id: id,
|
||||
name: name,
|
||||
sourceType: sourceType,
|
||||
localPath: localPath,
|
||||
storagePath: storagePath ?? this.storagePath,
|
||||
isVisible: isVisible ?? this.isVisible,
|
||||
projectId: projectId,
|
||||
importedAt: importedAt,
|
||||
syncedAt: syncedAt ?? this.syncedAt,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user