[ios] Already added bookmark can be edited/deleted after click on a map

This commit is contained in:
Alex Zolotarev 2012-09-01 16:43:51 +03:00 committed by Alex Zolotarev
parent c5a04960df
commit 975ccf7b13
4 changed files with 64 additions and 15 deletions

View file

@ -9,6 +9,8 @@
SEL m_selector;
Framework::AddressInfo m_addressInfo;
// If we clicked already existing bookmark, it will be here
BookmarkAndCategory m_rawBookmark;
}
@property(nonatomic, retain) NSString * title;
@ -25,10 +27,17 @@
@property(nonatomic, assign) CGPoint globalPosition;
- (id) initWithTarget:(id)target andSelector:(SEL)selector;
- (void) showInView:(UIView *)view atPoint:(CGPoint)pt;
- (void) showInView:(UIView *)view atPoint:(CGPoint)pt withBookmark:(BookmarkAndCategory)bm;
- (void) updatePosition:(UIView *)view atPoint:(CGPoint)pt;
- (void) hide;
// Update baloon image with new title
- (void) updateTitle:(NSString *)newTitle;
// Kosher method to add bookmark into the Framework.
// It automatically "edits" bookmark if it's already exists
- (void) addOrEditBookmark;
// Deletes bookmark if we were editing it (clicked on already added bm)
// and does nothing if called for "new", not added bookmark
- (void) deleteBookmark;
@end

View file

@ -122,13 +122,15 @@
}
- (void) showInView:(UIView *)view atPoint:(CGPoint)pt
- (void) showInView:(UIView *)view atPoint:(CGPoint)pt withBookmark:(BookmarkAndCategory)bm
{
if (isDisplayed)
[self hide];
isDisplayed = YES;
m_rawBookmark = bm;
CGFloat const w = self.pinImage.bounds.size.width;
CGFloat const h = self.pinImage.bounds.size.height;
self.pinImage.frame = CGRectMake(pt.x - w/2, pt.y - h, w, h);
@ -196,4 +198,39 @@
m_titleView.image = [self createPopupImageWithName:newTitle andAddress:description];
}
- (void) deleteBMHelper
{
BookmarkCategory * cat = m_rawBookmark.first;
Bookmark const * bm = m_rawBookmark.second;
if (cat && bm)
{
for (size_t i = 0; i < cat->GetBookmarksCount(); ++i)
{
if (cat->GetBookmark(i) == bm)
{
cat->DeleteBookmark(i);
break;
}
}
}
}
- (void) addOrEditBookmark
{
// for an "edit" operation, delete old bookmark before adding "edited" one
[self deleteBMHelper];
GetFramework().AddBookmark([self.setName UTF8String],
Bookmark(m2::PointD(self.globalPosition.x, self.globalPosition.y),
[self.title UTF8String], [self.color UTF8String]));
// Clear!
m_rawBookmark = BookmarkAndCategory(0, 0);
}
- (void) deleteBookmark
{
[self deleteBMHelper];
// Clear!
m_rawBookmark = BookmarkAndCategory(0, 0);
}
@end

View file

@ -152,13 +152,14 @@
- (void)onAddClicked
{
GetFramework().AddBookmark([m_balloon.setName UTF8String],
Bookmark(m2::PointD(m_balloon.globalPosition.x, m_balloon.globalPosition.y),
[m_balloon.title UTF8String], [m_balloon.color UTF8String]));
[m_balloon addOrEditBookmark];
[m_balloon hide];
}
- (void)onRemoveClicked
{
[m_balloon deleteBookmark];
[m_balloon hide];
// // Don't forget to hide navbar
// [self.navigationController setNavigationBarHidden:YES animated:YES];
// [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
@ -198,7 +199,7 @@
else
{
// Remove pin
[m_balloon hide];
[self onRemoveClicked];
}
// Close place page
[self.navigationController popViewControllerAnimated:YES];

View file

@ -141,8 +141,8 @@
CGPoint const pixelPos = [point CGPointValue];
CGFloat const scaleFactor = self.view.contentScaleFactor;
Bookmark const * bm = GetFramework().GetBookmark(m2::PointD(pixelPos.x * scaleFactor, pixelPos.y * scaleFactor));
if (!bm)
BookmarkAndCategory res = GetFramework().GetBookmark(m2::PointD(pixelPos.x * scaleFactor, pixelPos.y * scaleFactor));
if (!res.first || !res.second)
{
if (m_bookmark.isDisplayed)
[m_bookmark hide];
@ -150,17 +150,19 @@
{
CGPoint const globalPos = [self viewPoint2GlobalPoint:pixelPos];
m_bookmark.globalPosition = globalPos;
[m_bookmark showInView:self.view atPoint:pixelPos];
[m_bookmark showInView:self.view atPoint:pixelPos withBookmark:res];
}
}
else
{
// Already added bookmark was clicked
m2::PointD const globalPos = bm->GetOrg();
m2::PointD const globalPos = res.second->GetOrg();
m_bookmark.globalPosition = CGPointMake(globalPos.x, globalPos.y);
// Override bookmark name which was set automatically according to the point address in previous line
m_bookmark.title = [NSString stringWithUTF8String:bm->GetName().c_str()];
[m_bookmark showInView:self.view atPoint:[self globalPoint2ViewPoint:m_bookmark.globalPosition]];
m_bookmark.title = [NSString stringWithUTF8String:res.second->GetName().c_str()];
m_bookmark.color = [NSString stringWithUTF8String:res.second->GetType().c_str()];
m_bookmark.setName = [NSString stringWithUTF8String:res.first->GetName().c_str()];
[m_bookmark showInView:self.view atPoint:[self globalPoint2ViewPoint:m_bookmark.globalPosition] withBookmark:res];
}
}