Map card WIP

This commit is contained in:
estevez-dev
2020-07-20 13:53:18 +03:00
parent bf7983d72e
commit d2d037e468
7 changed files with 118 additions and 17 deletions

View File

@ -21,7 +21,6 @@ class CardData {
switch (rawData['type']) {
case CardType.ENTITIES:
case CardType.HISTORY_GRAPH:
case CardType.MAP:
case CardType.PICTURE_GLANCE:
case CardType.SENSOR:
case CardType.ENTITY:
@ -47,6 +46,9 @@ class CardData {
return CardData(null);
}
break;
case CardType.MAP:
return MapCardData(rawData);
break;
case CardType.ENTITY_BUTTON:
case CardType.BUTTON:
case CardType.PICTURE_ENTITY:
@ -656,7 +658,7 @@ class MapCardData extends CardData {
MapCardData(rawData) : super(rawData) {
//Parsing card data
title = rawData['title'];
List<String> geoLocationSources = rawData['geo_location_sources'] ?? [];
List<dynamic> geoLocationSources = rawData['geo_location_sources'] ?? [];
if (geoLocationSources.isNotEmpty) {
//TODO add entities by source
}
@ -664,8 +666,25 @@ class MapCardData extends CardData {
rawEntities.forEach((rawEntity) {
if (rawEntity is String) {
if (HomeAssistant().entities.isExist(rawEntity)) {
entities.add(EntityWrapper(entity: HomeAssistant().entities.get(rawEntity)));
} else {
entities.add(EntityWrapper(entity: Entity.missed(rawEntity)));
}
} else {
if (HomeAssistant().entities.isExist(rawEntity["entity"])) {
Entity e = HomeAssistant().entities.get(rawEntity["entity"]);
entities.add(
EntityWrapper(entity: HomeAssistant().entities.get(rawEntity)));
EntityWrapper(
entity: e,
stateColor: stateColor,
overrideName: rawEntity["name"]?.toString(),
overrideIcon: rawEntity["icon"],
stateFilter: rawEntity['state_filter'] ?? [],
uiAction: EntityUIAction(rawEntityData: rawEntity)
)
);
} else {
entities.add(EntityWrapper(entity: Entity.missed(rawEntity["entity"])));
}
}
});

View File

@ -1,25 +1,75 @@
part of '../main.dart';
class MapCard extends StatelessWidget {
class MapCard extends StatefulWidget {
final MapCardData card;
const MapCard({Key key, this.card}) : super(key: key);
@override
_MapCardState createState() => _MapCardState();
}
class _MapCardState extends State<MapCard> {
GlobalKey _mapKey = new GlobalKey();
MapController mapController = MapController();
@override
Widget build(BuildContext context) {
List<Marker> markers = [];
List<LatLng> points = [];
widget.card.entities.forEach((entityWrapper) {
double lat = entityWrapper.entity._getDoubleAttributeValue("latitude");
double long = entityWrapper.entity._getDoubleAttributeValue("longitude");
if (lat != null && long != null) {
points.add(LatLng(lat, long));
markers.add(
Marker(
width: 36,
height: 36,
point: LatLng(lat, long),
builder: (ctx) => EntityModel(
handleTap: true,
entityWrapper: entityWrapper,
child: EntityIcon(
size: 36,
),
)
)
);
}
});
return CardWrapper(
child: Padding(
padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, Sizes.rowPadding),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
CardHeader(name: card.title)
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
CardHeader(name: widget.card.title),
AspectRatio(
aspectRatio: 1,
child: GestureDetector(
child: FlutterMap(
key: _mapKey,
mapController: mapController,
options: new MapOptions(
interactive: true,
bounds: LatLngBounds.fromPoints(points),
boundsOptions: FitBoundsOptions(padding: EdgeInsets.all(30)),
),
layers: [
new TileLayerOptions(
urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: ['a', 'b', 'c']
),
new MarkerLayerOptions(
markers: markers,
),
],
)
),
)
],
)
);
}
}