Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added showPin option to snapshotter #478

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions ios/Classes/TiMapSnapshotterProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

@implementation TiMapSnapshotterProxy

CLLocationDegrees latitudeCoord;
CLLocationDegrees longitudeCoord;
bool showPin = NO;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please save the resulting CLLocationCoordinate2D instead, also use the ObjC BOOL type

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh dear, this is old, I already forgot, I did this PR :-D
Ok, I will take care about this all next week ;-)


- (NSString *)apiName
{
return @"Ti.Map.Snapshotter";
Expand All @@ -31,6 +35,9 @@ - (MKCoordinateRegion)regionFromDict:(NSDictionary *)dict
CLLocationDegrees latitude = [TiUtils floatValue:@"latitude" properties:dict];
CLLocationDegrees longitude = [TiUtils floatValue:@"longitude" properties:dict];

latitudeCoord = latitude;
longitudeCoord = longitude;

return MKCoordinateRegionMake(CLLocationCoordinate2DMake(latitude, longitude), MKCoordinateSpanMake(latitudeDelta, longitudeDelta));
}

Expand All @@ -57,6 +64,12 @@ - (void)setMapType:(id)value
[[self options] setMapType:[TiUtils intValue:value]];
}

- (void)setShowPin:(id)value
{
ENSURE_TYPE(value, NSNumber);
showPin = [TiUtils boolValue:value];
}

- (void)setShowsBuildings:(id)value
{
ENSURE_TYPE(value, NSNumber);
Expand Down Expand Up @@ -91,8 +104,31 @@ - (void)takeSnapshot:(id)args
[self _fireEventToListener:@"blob" withObject:[TiUtils stringValue:error] listener:ErrorCallback thisObject:nil];
return;
}

TiBlob *blob = [[TiBlob alloc] initWithImage:snapshot.image];
TiBlob *blob;
if (showPin == YES) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No explicit == YES check necessary

CGRect finalImageRect = CGRectMake(0, 0, snapshot.image.size.width, snapshot.image.size.height);
MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:@""];
UIImage *pinImage = pin.image;
UIGraphicsBeginImageContextWithOptions(snapshot.image.size, YES, snapshot.image.scale);
[snapshot.image drawAtPoint:CGPointMake(0, 0)];

CGPoint point = [snapshot pointForCoordinate:CLLocationCoordinate2DMake(latitudeCoord, longitudeCoord)];
if (CGRectContainsPoint(finalImageRect, point)) {
CGPoint pinCenterOffset = pin.centerOffset;
point.x -= pin.bounds.size.width / 2.0;
point.y -= pin.bounds.size.height / 2.0;
point.x += pinCenterOffset.x;
point.y += pinCenterOffset.y;

[pinImage drawAtPoint:point];
}
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

blob = [[TiBlob alloc] initWithImage:finalImage];
} else {
blob = [[TiBlob alloc] initWithImage:snapshot.image];
}
[blob setMimeType:@"image/png" type:TiBlobTypeImage];

NSDictionary *event = [NSDictionary dictionaryWithObject:blob forKey:@"image"];
Expand Down
2 changes: 1 addition & 1 deletion ios/titanium.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
//
//
TITANIUM_SDK_VERSION = 10.0.1.GA
TITANIUM_SDK_VERSION = 10.0.0.GA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore the version change (pulling from main should use a recent one)


//
// THESE SHOULD BE OK GENERALLY AS-IS
Expand Down
Loading