Skip to content

Commit

Permalink
0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mu-dawood committed Jun 13, 2022
1 parent 578641a commit 9aaf076
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 83 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.1"
version: "0.1.2"
path:
dependency: transitive
description:
Expand Down
84 changes: 68 additions & 16 deletions lib/src/location_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,56 @@ class FormattedLocation with _$FormattedLocation {
const FormattedLocation._();
const factory FormattedLocation({
///reference to the Nominatim internal database ID
@Default('') String placeId,
required String placeId,

/// latitude of the centroid of the object
required double lat,

/// longitude of the centroid of the object
required double lon,
@Default('') String licence,
required String licence,

///reference to the OSM object
@Default('') String osmType,
required String osmType,
String? icon,

/// reference to the OSM object
int? osmId,
required int osmId,

/// search rank of the object
int? placeRank,
required int placeRank,

///key of the main OSM tag
@Default('') String category,
required String category,

/// value of the main OSM tag
@Default('') String type,
required String type,

/// computed importance rank
double? importance,
@Default('') String addressType,
@Default('') String name,
required double importance,
required String addressType,
required String name,

///full comma-separated address
@Default('') String displayName,
required String displayName,

/// dictionary of address details
@Default(Address()) Address address,
required Address address,

/// dictionary with additional useful tags like website or max speed
@Default({}) Map<String, dynamic> extratags,
required Map<String, dynamic> extratags,

/// dictionary with full list of available names including ref etc
@Default({}) Map<String, dynamic> namedetails,
required Map<String, dynamic> namedetails,

///area of corner coordinates
LatLngBounds? boundingBox,
required LatLngBounds? boundingBox,

/// GeoBounds of object
required GeoGeometry geojson,
@Default({}) Map<String, String> names,
required Map<String, String> names,
}) = _FormattedLocation;

String get identifier => "$category-$osmId-$osmType";
@override
String toString() {
Expand Down Expand Up @@ -113,6 +114,57 @@ class FormattedLocation with _$FormattedLocation {
};
}

static FormattedLocation fromLatLng({
required double lat,
required double lon,
String placeId = '',
String addressType = '',
String category = '',
String licence = '',
String type = '',
String name = '',
String osmType = '',
String? displayName,
String? icon,
Address address = const Address(),
Map<String, String> names = const {},
Map<String, String> extratags = const {},
Map<String, String> namedetails = const {},
LatLngBounds? boundingBox,
GeoGeometry? geojson,
double importance = 0,
int placeRank = 0,
int osmId = 0,
}) {
return FormattedLocation(
placeId: placeId,
address: address,
names: names,
lat: lat,
lon: lon,
addressType: addressType,
boundingBox: boundingBox,
category: category,
displayName: displayName ?? '$lat, $lon',
extratags: extratags,
geojson: geojson ??
GeoGeometry.point(
LatLng(lon, lat),
Color((math.Random().nextDouble() * 0xFFFFFF).toInt())
.withOpacity(1.0),
),
importance: importance,
licence: licence,
name: name,
namedetails: namedetails,
osmId: osmId,
osmType: osmType,
placeRank: placeRank,
type: type,
icon: icon,
);
}

static FormattedLocation fromJson(Map<String, dynamic> json) {
if (json["error"] != null) {
throw Exception(json["error"]);
Expand Down
Loading

0 comments on commit 9aaf076

Please sign in to comment.