Importált rétegek stílusának szerkesztése
This commit is contained in:
@@ -38,7 +38,7 @@ class AppDatabase {
|
||||
final path = p.join(dbDir.path, 'terepi_seged.db');
|
||||
|
||||
return openDatabase(path,
|
||||
version: 1,
|
||||
version: 2,
|
||||
onConfigure: (db) => db.execute('PRAGMA foreign_keys = ON'),
|
||||
onCreate: _onCreate,
|
||||
onUpgrade: _onUpgrade);
|
||||
@@ -202,6 +202,9 @@ class AppDatabase {
|
||||
source_type TEXT NOT NULL,
|
||||
local_path TEXT NOT NULL,
|
||||
storage_path TEXT,
|
||||
color_hex TEXT,
|
||||
opacity REAL,
|
||||
stroke_width REAL,
|
||||
is_visible INTEGER NOT NULL DEFAULT 1,
|
||||
project_id INTEGER,
|
||||
imported_at TEXT NOT NULL,
|
||||
@@ -224,7 +227,19 @@ class AppDatabase {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {}
|
||||
Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {
|
||||
if (oldVersion < 2) {
|
||||
await db.execute('''
|
||||
ALTER TABLE imported_layers ADD COLUMN color_hex TEXT;
|
||||
''');
|
||||
await db.execute('''
|
||||
ALTER TABLE imported_layers ADD COLUMN opacity REAL;
|
||||
''');
|
||||
await db.execute('''
|
||||
ALTER TABLE imported_layers ADD COLUMN stroke_width REAL;
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
// ── Projects CRUD ─────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -22,6 +22,29 @@ import '../controls/geojson_parser.dart';
|
||||
import '../core/kml_parser.dart';
|
||||
import '../services/project_service.dart';
|
||||
|
||||
class ImportedLayerStyle {
|
||||
final Color color;
|
||||
final double opacity;
|
||||
final double strokeWidth;
|
||||
|
||||
const ImportedLayerStyle({
|
||||
required this.color,
|
||||
this.opacity = 0.35,
|
||||
this.strokeWidth = 2.5,
|
||||
});
|
||||
|
||||
ImportedLayerStyle copyWith({
|
||||
Color? color,
|
||||
double? opacity,
|
||||
double? strokeWidth,
|
||||
}) =>
|
||||
ImportedLayerStyle(
|
||||
color: color ?? this.color,
|
||||
opacity: opacity ?? this.opacity,
|
||||
strokeWidth: strokeWidth ?? this.strokeWidth,
|
||||
);
|
||||
}
|
||||
|
||||
class LayerImportService extends GetxService {
|
||||
static LayerImportService get to => Get.find();
|
||||
|
||||
@@ -40,6 +63,7 @@ class LayerImportService extends GetxService {
|
||||
|
||||
String? _layerDir;
|
||||
static const _uuid = Uuid();
|
||||
final layerStyles = <String, ImportedLayerStyle>{}.obs;
|
||||
|
||||
// ── Inicializálás ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -137,6 +161,11 @@ class LayerImportService extends GetxService {
|
||||
final ext = meta.localPath.split('.').last;
|
||||
loaded.add(_parse(bytes, meta.name, meta.id, ext,
|
||||
isVisible: meta.isVisible));
|
||||
|
||||
final style = meta.getStyle();
|
||||
if (style != null) {
|
||||
layerStyles[meta.id] = style;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Réteg betöltés hiba (${meta.name}): $e');
|
||||
}
|
||||
@@ -271,4 +300,25 @@ class LayerImportService extends GetxService {
|
||||
'kmz' => LayerImportSourceType.kmz,
|
||||
_ => LayerImportSourceType.geoJson,
|
||||
};
|
||||
|
||||
void setLayerStyle(String id, ImportedLayerStyle style) async {
|
||||
layerStyles[id] = style;
|
||||
layerStyles.refresh();
|
||||
layers.refresh();
|
||||
|
||||
final metas = await AppDatabase.instance.listImportedLayers();
|
||||
final meta = metas.firstWhereOrNull((m) => m.id == id);
|
||||
|
||||
if (meta != null) {
|
||||
final hex =
|
||||
'#${style.color.value.toRadixString(16).padLeft(8, '0').substring(2).toUpperCase()}';
|
||||
|
||||
await AppDatabase.instance.updateImportedLayer(meta.copyWith(
|
||||
colorHex: hex,
|
||||
opacity: style.opacity,
|
||||
strokeWidth: style.strokeWidth));
|
||||
}
|
||||
}
|
||||
|
||||
ImportedLayerStyle? getLayerStyle(String id) => layerStyles[id];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user