2024-04-20 14:32:01 +00:00
|
|
|
import 'package:anyhow/anyhow.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_map/flutter_map.dart';
|
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
2024-04-20 19:14:11 +00:00
|
|
|
import 'package:geojson_vi/geojson_vi.dart';
|
2024-04-20 14:32:01 +00:00
|
|
|
import 'package:latlong2/latlong.dart';
|
|
|
|
|
|
|
|
part 'model.freezed.dart';
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
class Feature with _$Feature {
|
|
|
|
const Feature._();
|
|
|
|
|
|
|
|
const factory Feature({
|
|
|
|
required String name,
|
|
|
|
required FeatureType type,
|
|
|
|
String? description,
|
2024-04-20 19:14:11 +00:00
|
|
|
required GeoJSONGeometry geometry,
|
2024-04-20 14:32:01 +00:00
|
|
|
int? level,
|
|
|
|
}) = _Feature;
|
|
|
|
|
|
|
|
bool isPolygon() {
|
2024-04-20 19:14:11 +00:00
|
|
|
return geometry is GeoJSONPolygon;
|
2024-04-20 14:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isPoint() {
|
2024-04-20 19:14:11 +00:00
|
|
|
return geometry is GeoJSONPoint;
|
2024-04-20 14:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result<Polygon> getPolygon({Polygon Function(List<LatLng>)? constructor}) {
|
|
|
|
if (isPolygon()) {
|
|
|
|
constructor ??= (pts) => Polygon(
|
2024-04-20 19:14:11 +00:00
|
|
|
points: pts,
|
|
|
|
borderColor: Colors.black26,
|
|
|
|
borderStrokeWidth: 2.0,
|
|
|
|
);
|
|
|
|
final polygon = geometry as GeoJSONPolygon;
|
2024-04-20 14:32:01 +00:00
|
|
|
// print(polygon.geometry!.geoSeries[0].geoPoints);
|
2024-04-20 19:14:11 +00:00
|
|
|
final points =
|
|
|
|
// polygon.coordinates[0].map((e) => LatLng(e[0], e[1])).toList();
|
|
|
|
polygon.coordinates[0].map((e) => LatLng(e[1], e[0])).toList();
|
2024-04-20 14:32:01 +00:00
|
|
|
|
|
|
|
// print(points);
|
|
|
|
return Ok(constructor(points));
|
|
|
|
} else {
|
|
|
|
return bail("Feature Geometry is not a Polygon");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<LatLng> getPoint() {
|
|
|
|
if (isPoint()) {
|
2024-04-20 19:14:11 +00:00
|
|
|
final point = geometry as GeoJSONPoint;
|
|
|
|
return Ok(LatLng(point.coordinates[1], point.coordinates[0]));
|
2024-04-20 14:32:01 +00:00
|
|
|
} else {
|
|
|
|
return bail("Feature Geometry is not a Point");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
class FeatureType with _$FeatureType {
|
|
|
|
// multiple feature types like lecture hall, toliet, ...
|
|
|
|
const factory FeatureType.building() = Building;
|
|
|
|
const factory FeatureType.lectureHall() = LectureHall;
|
|
|
|
const factory FeatureType.room() = Room;
|
|
|
|
const factory FeatureType.door(List<String> connects) = Door;
|
|
|
|
const factory FeatureType.toilet(String toilet_type) = Toilet;
|
|
|
|
const factory FeatureType.stairs(List<int> connects_levels) = Stairs;
|
|
|
|
const factory FeatureType.lift(List<int> connects_levels) = Lift;
|
|
|
|
const factory FeatureType.publicTransport(
|
|
|
|
List<String> bus_lines, List<String> tram_lines) = PublicTransport;
|
|
|
|
}
|