日志文档--站点导航模式下的逻辑顺序

站点模式下,起点和终点的规划。
主要的难点,是区域变更时,如何处理标注。
我们先来讨论两种情况:不跳转区域和跳转区域

将S/E的属性列为

  • 站点名
  • 站点坐标
  • 是否在选定的区域内 —— 只在区域切换时赋值 isInChangedDistrict
  • 索引 —— 赋值有两处
    • 当S/E 确实处于当前区域(isInChangedDistrict = YES)时,在viewForAnnotation时赋值。
    • Cell选中时赋值

根据上面的逻辑,切换区域时的具体操作步骤如下:

首先必定是移除所有的标注和覆盖物。
- (IBAction)selectRelatedDistrict:(DistrictButton *)sender中通过代理
在BottomView中添加覆盖物和标注:

[bottomeView.delegate addOverlaysToDistrictWithName:districtName];
[bottomeView.delegate addAnnotationPointInDistrict:annotationArray];

addoverlay回调

去StationInfo中封装一个方法,判断S/E.name是否在districtName所指向的区域中。在这里对S/E.isInChangedDsitrict赋值。

  • addoverlay引起的ViewForOverlay的相应代理,不需做修改。

addAnnotationPoint回调

在原有的基础上,封装一个函数,用于添加S/E生成的标注。具体的做法:

  • 判断S/E.name是否为空,为空就不去生成标注。也就是不添加
  • 判断S/E.isInChangedDsitrict, 若为YES, 也不去添加。否则,去生成一个新的标注,标注类为“termiAnnotation”添加之。
  • addAnnotation引起的ViewForAnnotation的相应代理,变更如下:
    • 需要判断annotation.title 是否和 S/E.name 相同。若相同,则将annotationView.img改为对应的S/E图。

选中/不选中标注的逻辑如下:

对于didselectAnnotaiondidDeselectAnnotation的做法是一样的

  • 对应的的annotation,若annotation.title == S/E.name,
    不做任何事。这里可以在S/E中封装一个方法,对于传入的名称,判断是否为S/E.
    否则,按正常去更改为选中的背景。

Cell中“选中” —— 将标注定为S/E:

  • 由于此时的“选中”是为底栏发起,也就是说此时处于备选的站点,一定是在区域内的,因此不用去考虑区域外的S/E站点情况。
  • 选中后,判断当前站点是否为S/E,若是,则不做任何操作。若非,则继续判断S/E哪个为空就写入哪个。
  • 同时,取出对应的annotation View,更改他的背景图
BMKAnnotationView *annotationView = [self.BaseBaiduMapView viewForAnnotation:annotation];
annotationView.image = [UIImage imageNamed:@"起始站点"];
S/E.isInChangedDsitrict = YES

删除站点为S/E的逻辑如下:

  • 判断当前S/E.isInChangedDsitrict, 若为NO,remove termiAnnotation类的annotation
// termiAnnotation有两个,S/E,要判断传进来的是哪一个
[annotation isKindOfClass:[terminalStationAnnotation class]] && [[annotation title] isEqualToString:station.name]

同时,将S/E.name = nil, 不用去管坐标, 坐标用不到。

  • 若为YES,根据S/E.index,得到annotation,再得到annotationView,此时务必将他强转为(MyPinAnnotationView否则会出错),然后去更改背景, 最后复位S/E.index,同时将S/E.name = nil,isInChangedDsitrict=NO

规划路径时候的方法

难点在于,我们需要的是,规划好路径后,将所有的标注都移除,然后再生成两个S/E的标注吗?如果上面的逻辑都成立,应该没有问题。

            // 先去掉所有的标注和覆盖物,规划路径
            [self.BaseBaiduMapView removeAnnotations:self.BaseBaiduMapView.annotations];
            [self.BaseBaiduMapView removeOverlays:self.BaseBaiduMapView.overlays];
            CLLocationCoordinate2D startPoint = self.guideStartStation.coordiate;
            CLLocationCoordinate2D endPoint   = self.guideEndStation.coordiate;
            [[BaiduRouteSearchTool shareInstance] pathGuideWithStart:startPoint end:endPoint];
            [self stopMapviewTransform];
            // 再添加标注
            self.guideStartStation.isInChangedDistrict = NO;
            self.guideEndStation.isInChangedDistrict = NO;
            [self addTermiStationAnnotations];

            // 通知底栏复位模式,让底栏显示出来的时候所有按键是未选中的状态,方便下次切换到站点搜索模式
            [[NSNotificationCenter defaultCenter] postNotificationName:DISTRICT_BTN_SEL_RADIO
                                                                object:@"复位模式"];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,986评论 19 139
  • 出自http://my.oschina.net/are1OfBlog/blog/420034 摘要 现在很多社交、...
    JJO阅读 4,176评论 4 19
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,767评论 18 399
  • http://www.cnblogs.com/kenshincui/p/4125570.html 摘要: 现在很多...
    大崔老师阅读 3,320评论 1 2
  • 今天第二遍看《肖申克的救赎》,不是特别能用语言来完全表达内心的感受,先说说让自己印象深刻的部分。 一个...
    紫澜阅读 226评论 3 0