Skip to content

Commit

Permalink
Fix for multiple lang countries, nodes in relations can be moved, fix…
Browse files Browse the repository at this point in the history
… for blue marker, faint walking path everywhere, showers are micromapping, disable snapping plaques
  • Loading branch information
Zverik committed May 25, 2024
1 parent 5cd21b3 commit 4fad866
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ _Unreleased_
* Added the recent walked path display in small blue dots.
* GeoScribbles drawing is locked by default.
* When deleting an amenity with a unique address, suggest keeping the address.
* Now possible to move nodes that are relation members.
* Fixed blue marker for unmovable objects in the editor.
* Minimum supported Android version is 5.0 now, due to Flutter upgrade.

## 5.0
Expand Down
4 changes: 3 additions & 1 deletion lib/fields/hours/days_editors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ class WeekdaysPanel extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final locProvider = ref.watch(countryLocaleProvider);
final currentLoc = AppLocalizations.of(context)!;
final loc =
ref.watch(countryLocaleProvider).loc ?? AppLocalizations.of(context)!;
locProvider.multiple ? currentLoc : locProvider.loc ?? currentLoc;
final weekdayTitles = loc.fieldHoursWeekdays.split(' ');

return Row(
Expand Down
8 changes: 5 additions & 3 deletions lib/helpers/good_tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ bool isAmenityTags(Map<String, String> tags) {
'bench',
'parking_space',
'clothes_dryer',
'dressing_room',
'shower',
'waste_basket',
'bicycle_parking',
'shelter',
Expand Down Expand Up @@ -418,8 +420,8 @@ SnapTo detectSnap(Map<String, String> tags) {
};
if (kSnapRailway.contains(tags['railway']!)) return SnapTo.railway;
} else if ({'traffic_calming', 'barrier'}.contains(k)) return SnapTo.highway;
else if (k == 'historic' && {'plaque', 'blue_plaque'}.contains(tags['memorial']))
return SnapTo.building;
// else if (k == 'historic' && {'plaque', 'blue_plaque'}.contains(tags['memorial']))
// return SnapTo.building;
else if (k == 'public_transport' && tags['public_transport'] == 'stop_position') {
if (tags['bus'] == 'yes' || tags['trolleybus'] == 'yes')
return SnapTo.highway;
Expand All @@ -439,7 +441,7 @@ bool isSnapTargetTags(Map<String, String> tags, [SnapTo? kind]) {
return !{'platform', 'station', 'signal_box', 'platform_edge'}
.contains(tags['railway']);
if (tags.containsKey('building') && (kind == null || kind == SnapTo.building))
return tags['building'] != 'roof';
return tags['building'] != 'roof' && tags['building'] != 'part';
if (tags.containsKey('barrier') && (kind == null || kind == SnapTo.wall))
return {'wall', 'fence'}.contains(tags['barrier']);
return false;
Expand Down
8 changes: 6 additions & 2 deletions lib/helpers/osm_api_converters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,15 @@ class MarkReferenced extends Converter<List<OsmElement>, List<OsmElement>> {
}

// Process references in this element
final isMember = element.id.type == OsmElementType.relation
? IsMember.relation
: IsMember.way;

if (refs != null) {
for (final ref in refs) {
final el = _stack[ref];
if (el != null) {
referenced.add(el.copyWith(isMember: true));
referenced.add(el.copyWith(isMember: isMember));
_stack.remove(ref);
} else {
_refs.add(ref);
Expand All @@ -342,7 +346,7 @@ class MarkReferenced extends Converter<List<OsmElement>, List<OsmElement>> {

// Emit if already referenced, stash otherwise
if (_refs.contains(element.id)) {
referenced.add(element.copyWith(isMember: true));
referenced.add(element.copyWith(isMember: isMember));
_refs.remove(element.id);
} else {
_stack[element.id] = element;
Expand Down
12 changes: 7 additions & 5 deletions lib/helpers/pin_marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';

class PinMarker extends Marker {
PinMarker(LatLng location, {Color color = Colors.white})
PinMarker(LatLng location, {Color color = Colors.white, bool blend = true})
: super(
point: location,
rotate: true,
alignment: Alignment(0.0, -0.7),
child: BlendMask(
blendMode: BlendMode.difference,
child: Icon(Icons.location_pin, color: color),
),
child: blend
? BlendMask(
blendMode: BlendMode.difference,
child: Icon(Icons.location_pin, color: color),
)
: Icon(Icons.location_pin, color: color),
);
}
10 changes: 7 additions & 3 deletions lib/models/amenity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,14 @@ class OsmChange extends ChangeNotifier implements Comparable {
bool get isArea => element?.isArea ?? false;
bool get isPoint => element?.isPoint ?? true;
bool get canDelete =>
(element?.isPoint ?? true) && !(element?.isMember ?? false);
(element?.isPoint ?? true) &&
(element == null || element?.isMember == IsMember.no);
bool get isBuilding =>
detectKind(getFullTags(), {ElementKind.building}) == ElementKind.building;
bool get canMove => canDelete && (isNew || kind != ElementKind.entrance);
bool get canMove =>
(element?.isPoint ?? true) &&
(element?.isMember != IsMember.way) &&
(isNew || kind != ElementKind.entrance);
ElementKind get kind => detectKind(getFullTags());
bool get isIncomplete => needsMoreInfo(getFullTags());

Expand Down Expand Up @@ -292,7 +296,7 @@ class OsmChange extends ChangeNotifier implements Comparable {
version: newVersion ?? 1,
timestamp: DateTime.now(),
tags: getFullTags(),
isMember: element?.isMember ?? false,
isMember: element?.isMember ?? IsMember.no,
// overriding location call for toXML()
center: newLocation ?? element?.center,
downloaded: DateTime.now(),
Expand Down
21 changes: 16 additions & 5 deletions lib/models/osm_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class OsmMember {
}
}

enum IsMember { no, way, relation }

class OsmElement {
final OsmId id;
final Map<String, String> tags;
Expand All @@ -88,7 +90,7 @@ class OsmElement {
final List<int>? nodes;
final Map<int, LatLng>? nodeLocations; // not stored to the database
final List<OsmMember>? members;
final bool isMember;
final IsMember isMember;

OsmElementType get type => id.type;

Expand All @@ -103,7 +105,7 @@ class OsmElement {
this.nodes,
this.nodeLocations,
this.members,
this.isMember = false,
this.isMember = IsMember.no,
}) : center = center ??
(geometry is Polygon
? geometry.findPointOnSurface()
Expand All @@ -115,7 +117,7 @@ class OsmElement {
int? version,
LatLng? center,
Geometry? geometry,
bool? isMember,
IsMember? isMember,
List<int>? nodes,
Map<int, LatLng>? nodeLocations,
bool currentTimestamp = false,
Expand Down Expand Up @@ -174,6 +176,7 @@ class OsmElement {
factory OsmElement.fromJson(Map<String, dynamic> data) {
List<dynamic>? members = json.decode(data['members']);
String? nodes = data['nodes'];
final int m = data['is_member'];
return OsmElement(
id: OsmId.fromString(data['osmid']),
version: data['version'],
Expand All @@ -192,7 +195,11 @@ class OsmElement {
?.whereType<String>()
.map((e) => OsmMember.fromString(e))
.toList(),
isMember: data['is_member'] == 1,
isMember: m == 1
? IsMember.way
: m == 2
? IsMember.relation
: IsMember.no,
);
}

Expand All @@ -217,7 +224,11 @@ class OsmElement {
'tags': json.encode(tags),
'nodes': nodes?.join(','),
'members': json.encode(members?.map((e) => e.toString()).toList()),
'is_member': isMember ? 1 : 0,
'is_member': isMember == IsMember.relation
? 2
: isMember == IsMember.way
? 1
: 0,
};
}

Expand Down
8 changes: 7 additions & 1 deletion lib/providers/country_locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ class CountryLocaleController extends ChangeNotifier {

Locale? locale;
AppLocalizations? loc;
bool multiple = false;

CountryLocaleController(this._ref);

update(LatLng? location) async {
location ??= _ref.read(effectiveLocationProvider);

Locale? newLocale;
bool newMultiple = false;
if (location != null) {
for (final l in _getLanguageKeysForLocation(location)) {
final localesToTest = _getLanguageKeysForLocation(location);
// We get two for each language.
newMultiple = localesToTest.length > 2;
for (final l in localesToTest) {
if (AppLocalizations.delegate.isSupported(l)) {
newLocale = l;
break;
Expand All @@ -33,6 +38,7 @@ class CountryLocaleController extends ChangeNotifier {

if (newLocale != locale) {
locale = newLocale;
multiple = newMultiple;
loc = newLocale == null
? null
: await AppLocalizations.delegate.load(newLocale);
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ class _PoiEditorPageState extends ConsumerState<PoiEditorPage> {
} else if (answer == kKeepAddress) {
// Delete all tags except address.
for (final k in amenity.getFullTags().keys)
if (!k.startsWith('addr:') || k == 'addr:floor')
amenity.removeTag(k);
if (!k.startsWith('addr:') || k == 'addr:floor') amenity.removeTag(k);
saveAndClose();
}
}
Expand Down Expand Up @@ -607,7 +606,8 @@ class _PoiEditorPageState extends ConsumerState<PoiEditorPage> {
),
),
if (!amenity.canMove)
PinMarker(amenity.location, color: Colors.red.shade900),
PinMarker(amenity.location,
color: Colors.red.shade900, blend: false),
],
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/modes/entrances.dart
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class _EntrancesPaneState extends ConsumerState<EntrancesPane> {
reset: tileResetController.stream,
),
AttributionWidget(imagery),
WalkPathPolyline(),
WalkPathPolyline(faint: true),
LocationMarkerWidget(),
if (newLocation != null)
CircleLayer(
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:every_door/screens/settings.dart';
import 'package:every_door/widgets/attribution.dart';
import 'package:every_door/widgets/loc_marker.dart';
import 'package:every_door/widgets/track_button.dart';
import 'package:every_door/widgets/walkpath.dart';
import 'package:every_door/widgets/zoom_buttons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
Expand Down Expand Up @@ -328,6 +329,7 @@ class _AmenityMapState extends ConsumerState<AmenityMap> {
reset: tileResetController.stream,
),
LocationMarkerWidget(),
WalkPathPolyline(faint: true),
if (trackLocation != null)
CircleLayer(
circles: [
Expand Down
8 changes: 5 additions & 3 deletions lib/widgets/walkpath.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class WalkPathPolyline extends ConsumerWidget {
const WalkPathPolyline({super.key});
final bool faint;

const WalkPathPolyline({super.key, this.faint = false});

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -13,10 +15,10 @@ class WalkPathPolyline extends ConsumerWidget {
return PolylineLayer(polylines: [
Polyline(
points: walkPath,
color: Colors.blue,
color: Colors.blue.withOpacity(faint ? 0.3 : 0.5),
isDotted: true,
strokeWidth: 3.0,
borderColor: Colors.black38,
borderColor: Colors.black26,
borderStrokeWidth: 3.0,
),
]);
Expand Down

0 comments on commit 4fad866

Please sign in to comment.