Skip to content

Commit

Permalink
Merge pull request #69 from ketanchoyal/feat/v4
Browse files Browse the repository at this point in the history
Feat/v4
  • Loading branch information
ketanchoyal authored Apr 25, 2023
2 parents 1095c63 + 36d6505 commit 11980f1
Show file tree
Hide file tree
Showing 31 changed files with 1,937 additions and 264 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# [4.0.0-beta.1] - 25 April 2023
## Breaking Changes
- PlaceSearch and ReverseGeoCoding classes are now merged into one class called GeoCoding with two methods `getPlaces` and `getAddress` since both of them are using the same API.

## New Features
- MapBox's new [SearchBox API](https://docs.mapbox.com/api/search/search-box/) is added to the package.
- Overal code refactoring

# [3.2.0] - 21 April 2023
- Added BBox in Forward Geododing API (As per MapBox API we can use BBox to get the results in a specific area)

Expand All @@ -17,7 +25,7 @@
- Homepage URL fixed

## [3.0.1] - 14 Sep 2021
- Added [Places type]((https://docs.mapbox.com/api/search/geocoding/#data-types)) to filter Search [PR #48]
- Added [Places type](https://docs.mapbox.com/api/search/geocoding/#data-types) to filter Search [PR #48]

## [3.0.0-nullsafety.0] - 07 Mar 2021
- Migrate to null safety [Pull Request #43]
Expand Down
57 changes: 46 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
[![Pub](https://img.shields.io/pub/v/mapbox_search)](https://pub.dev/packages/mapbox_search)
# About

## Note: Breaking Changes in 4.x.x

- PlaceSearch and ReverseGeoCoding classes are now merged into one class called GeoCoding with two methods `getPlaces` and `getAddress` since both of them are using the same API.
- MapBox's new [SearchBox API](https://docs.mapbox.com/api/search/search-box/) is added to the package.

This package provides easy api calls to MapBox Search API.

Also, it contains an static map image generator 😆.
Also, it contains an static map image generator.

[Maki Icons](https://labs.mapbox.com/maki-icons/) can be used now in marker icon

Expand All @@ -26,9 +31,36 @@ Then, add the following to your `pubspec.yaml` file:

# Examples

### SearchBox API
```dart
SearchBoxAPI search = SearchBoxAPI(
apiKey: MAPBOX_KEY,
limit: 6,
);
```
##### Get Suggestions
```dart
SuggestionResponse searchPlace = await search.getSuggestions(
"central",
);
```

##### Get mapbox_id
- From SuggestionResponse
```dart
String mapboxId = searchPlace.suggestions[0].mapboxId;
```

##### Get Place Details
```dart
RetrieveResonse searchPlace = await search.getPlace(mapboxId);
```



### Reverse GeoCoding
```dart
var reverseGeoCoding = ReverseGeoCoding(
var reverseGeoCoding = GeoCoding(
apiKey: 'API Key',
limit: 5,
);
Expand All @@ -38,16 +70,24 @@ Future<List<MapBoxPlace>> geAddress() =>
Location(lat: 72.0, lng: 76.00),
);
```
### Places Seach

### Forward GeoCoding Seach
```dart
var placesSearch = PlacesSearch(
var geocoding = GeoCoding(
apiKey: 'API Key',
country: "BR",
limit: 5,
types: [PlaceType.address, PlaceType.place],
);
Future<List<MapBoxPlace>> getPlaces() =>
placesSearch.getPlaces("New York");
geocoding.getPlaces(
"central park",
proximity: Location(
lat: -19.984634,
lng: -43.9502958,
),
);
```

### Static Image
Expand Down Expand Up @@ -108,8 +148,3 @@ String getStaticImageWithoutMarker() => staticImage.getStaticUrlWithoutMarker(

<img src="https:/ketanchoyal/mapbox_search/raw/dev/Screenshots/staticImages.png" alt="Static Map Image"/>

## Search Widget

<img src="https:/ketanchoyal/mapbox_search/raw/dev/Screenshots/search2.png" alt="Demo"/>

<img src="https:/ketanchoyal/mapbox_search/raw/dev/Screenshots/search1.png" alt="Demo"/>
Binary file removed Screenshots/search1.png
Binary file not shown.
Binary file removed Screenshots/search2.png
Binary file not shown.
10 changes: 6 additions & 4 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import 'dart:core';

import 'package:mapbox_search/mapbox_search.dart';

// import 'credentials.dart';
final MAPBOX_KEY = '';

Future<void> main() async {
String apiKey = MAPBOX_KEY; //Set up a test api key before running
final apiKey = MAPBOX_KEY; //Set up a test api key before running

await geoCoding(apiKey).catchError(print);
await placesSearch(apiKey).catchError(print);
}

///Reverse GeoCoding sample call
Future geoCoding(String apiKey) async {
var geoCodingService = ReverseGeoCoding(
var geoCodingService = GeoCoding(
apiKey: apiKey,
country: "BR",
limit: 5,
Expand All @@ -28,15 +30,15 @@ Future geoCoding(String apiKey) async {

///Places search sample call
Future placesSearch(String apiKey) async {
var placesService = PlacesSearch(
var placesService = GeoCoding(
apiKey: apiKey,
country: "BR",
limit: 5,
);

var places = await placesService.getPlaces(
"patio",
location: Location(
proximity: Location(
lat: -19.984634,
lng: -43.9502958,
),
Expand Down
108 changes: 108 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.11.0"
collection:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted
version: "1.17.1"
crypto:
dependency: transitive
description:
name: crypto
sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67
url: "https://pub.dev"
source: hosted
version: "3.0.2"
http:
dependency: transitive
description:
name: http
sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482"
url: "https://pub.dev"
source: hosted
version: "0.13.5"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
mapbox_search:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "3.2.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
source_span:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.1"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
uuid:
dependency: transitive
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
url: "https://pub.dev"
source: hosted
version: "3.0.7"
sdks:
dart: ">=2.18.0 <3.0.0"
13 changes: 13 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: example
description: A Flutter package for place search using MapBox Api and for Static map image
version: 1.0.0
publish_to: "none" # Remove this line if you wish to publish to pub.dev

homepage: https:/ketanchoyal/mapbox_search

environment:
sdk: ">=2.17.0 <3.0.0"

dependencies:
mapbox_search:
path: ../
5 changes: 5 additions & 0 deletions lib/colors/cielab_color.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of color;

/// A color in the CIELAB color space.
class CielabColor extends Color {
final num l;
final num a;
Expand All @@ -12,10 +13,13 @@ class CielabColor extends Color {
return xyz.toRgbColor();
}

/// Converts the color to HSL color space.
HslColor toHslColor() => this.toRgbColor().toHslColor();

/// Converts the color to HSV color space.
HsvColor toHsvColor() => this.toRgbColor().toHsvColor();

/// Converts the color to XYZ color space.
XyzColor toXyzColor() {
Map<String, num> xyz = {
'x': a / 500 + (l + 16) / 116,
Expand All @@ -36,6 +40,7 @@ class CielabColor extends Color {
return XyzColor(xyz['x']!, xyz['y']!, xyz['z']!);
}

// Returns a CielabColor with the same color values as this Color.
CielabColor toCielabColor() => this;

String toString() => "l: $l, a: $a, b: $b";
Expand Down
3 changes: 2 additions & 1 deletion lib/colors/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ abstract class Color {
return 256 * 256 * rgb.r.toInt() + 256 * rgb.g.toInt() + rgb.b.toInt();
}

operator ==(Object other) => other is Color && this.hashCode == other.hashCode;
operator ==(Object other) =>
other is Color && this.hashCode == other.hashCode;

operator [](String key) => this.toMap()[key];

Expand Down
19 changes: 13 additions & 6 deletions lib/colors/color_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class ColorFilter {
/**
* Makes the color lighter by the percentage specified in the first argument, or by 10% if no percentage is specified. Percentages should be specified as a float, e.g. an argument of 0.25 will result in a color 25% lighter than the original. The lightening conversion is performed by adjusting the y component of the color in XYZ color space.
*/
static ColorFilter lighten = new ColorFilter((Color inputColor, [List? args]) {
static ColorFilter lighten =
new ColorFilter((Color inputColor, [List? args]) {
CielabColor color = inputColor.toCielabColor();
num percent = 0.1;
if (args is List && args.length > 0 && args[0] is num) {
if (args is List && args.isNotEmpty && args[0] is num) {
percent = args[0];
}
return new CielabColor(color.l * (1 + percent), color.a, color.b);
Expand All @@ -37,15 +38,21 @@ class ColorFilter {
*/
static ColorFilter sepia = new ColorFilter((Color baseColor, [List? args]) {
RgbColor color = baseColor.toRgbColor();
return new RgbColor(min(RgbColor.rMax, (color.r * 0.393 + color.g * 0.769 + color.b * 0.189)),
min(RgbColor.gMax, (color.r * 0.349 + color.g * 0.686 + color.b * 0.168)),
min(RgbColor.bMax, (color.r * 0.272 + color.g * 0.534 + color.b * 0.131))).toCielabColor();
return new RgbColor(
min(RgbColor.rMax,
(color.r * 0.393 + color.g * 0.769 + color.b * 0.189)),
min(RgbColor.gMax,
(color.r * 0.349 + color.g * 0.686 + color.b * 0.168)),
min(RgbColor.bMax,
(color.r * 0.272 + color.g * 0.534 + color.b * 0.131)))
.toCielabColor();
}, RgbColor);

/**
* Creates a greyscale color with the same perceived luminance as the source color (as given by the L* value of the color in the CieLAB color space).
*/
static ColorFilter greyscale = new ColorFilter((Color inputColor, [List? args]) {
static ColorFilter greyscale =
new ColorFilter((Color inputColor, [List? args]) {
CielabColor color = inputColor.toCielabColor();
num rgbLevel = color.l * 255 / 100;
return new RgbColor(rgbLevel, rgbLevel, rgbLevel).toCielabColor();
Expand Down
Loading

0 comments on commit 11980f1

Please sign in to comment.