站點模式下寞钥,起點和終點的規(guī)劃土铺。
主要的難點,是區(qū)域變更時丢早,如何處理標注。
我們先來討論兩種情況:不跳轉區(qū)域和跳轉區(qū)域
將S/E的屬性列為
- 站點名
- 站點坐標
- 是否在選定的區(qū)域內 —— 只在區(qū)域切換時賦值 isInChangedDistrict
- 索引 —— 賦值有兩處
- 當S/E 確實處于當前區(qū)域(isInChangedDistrict = YES)時秧倾,在
viewForAnnotation
時賦值怨酝。 -
Cell
選中時賦值
- 當S/E 確實處于當前區(qū)域(isInChangedDistrict = YES)時秧倾,在
根據上面的邏輯,切換區(qū)域時的具體操作步驟如下:
首先必定是移除所有的標注和覆蓋物那先。
- (IBAction)selectRelatedDistrict:(DistrictButton *)sender
中通過代理
在BottomView中添加覆蓋物和標注:
[bottomeView.delegate addOverlaysToDistrictWithName:districtName];
[bottomeView.delegate addAnnotationPointInDistrict:annotationArray];
addoverlay回調
去StationInfo中封裝一個方法农猬,判斷S/E.name是否在districtName所指向的區(qū)域中。在這里對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圖令蛉。
選中/不選中標注的邏輯如下:
對于didselectAnnotaion
和 didDeselectAnnotation
的做法是一樣的
- 對應的的annotation聚霜,若annotation.title == S/E.name,
不做任何事。這里可以在S/E中封裝一個方法言询,對于傳入的名稱俯萎,判斷是否為S/E.
否則,按正常去更改為選中的背景运杭。
Cell中“選中” —— 將標注定為S/E:
- 由于此時的“選中”是為底欄發(fā)起夫啊,也就是說此時處于備選的站點,一定是在區(qū)域內的辆憔,因此不用去考慮區(qū)域外的S/E站點情況撇眯。
- 選中后报嵌,判斷當前站點是否為S/E,若是熊榛,則不做任何操作锚国。若非,則繼續(xù)判斷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
規(guī)劃路徑時候的方法
難點在于盈魁,我們需要的是翔怎,規(guī)劃好路徑后,將所有的標注都移除杨耙,然后再生成兩個S/E的標注嗎赤套?如果上面的邏輯都成立,應該沒有問題珊膜。
// 先去掉所有的標注和覆蓋物容握,規(guī)劃路徑
[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];
// 通知底欄復位模式,讓底欄顯示出來的時候所有按鍵是未選中的狀態(tài),方便下次切換到站點搜索模式
[[NSNotificationCenter defaultCenter] postNotificationName:DISTRICT_BTN_SEL_RADIO
object:@"復位模式"];