我有一个使用 Route-me 和静态地图(存储在 sqlite 数据库中的图块)的应用程序。下面的代码正确地将路线添加到地图。但是,我想让应用程序删除显示的路线并添加另一条路线。在代码中,该函数在这一行中获取一组新的路由点(变量 pathNodes)([route createRoute:whichRoute] 方法从 sqlite 数据库中提取数据点 - 这可以正常工作):
pathNodes = [route createRoute:whichRoute];
然后我删除此代码中的现有层:
// remove the current layer, which holds the previous route
if (currentLayer != nil) {
[mapView.contents.overlay removeSublayer:currentLayer];
}
并在其中添加一个新层:
[mapView.contents.overlay addSublayer:(CALayer *)walkRoute.path];
对于创建的第一条路线,这非常有效。But when a new route is chosen, the existing layer gets removed and the new sublayer is added to the mapView, but is never shown.
在我看来,这只是让 mapView 用新的子层重绘自身的问题,但我已经尝试了我能想到或在其他地方发现的一切,但没有任何效果。
如何让 mapView 重绘自身。还是我没有看到另一个问题?
所有帮助将不胜感激!
- (void) setRoute {
NSMutableArray *pathNodes;
int whichRoute = delegate.selectedRoute; // delegate.whichRoute will be an integer denoting which route the user has chosen
Route *route = [[Route alloc] init];// Route stores information about the route, and a way to create the path nodes from a sqlite database
pathNodes = [route createRoute:whichRoute];
CMRoute *walkRoute = [[CMRoute alloc] initWithNodes:pathNodes forMap:mapView];
// remove the current layer, which holds the previous route
if (currentLayer != nil) {
[mapView.contents.overlay removeSublayer:currentLayer];
}
[mapView.contents.overlay addSublayer:(CALayer *)walkRoute.path];
currentLayer = (CALayer *)walkRoute.path;
// set the map's center point, whkch is the startPointlat and long stored in route
CLLocationCoordinate2D demoCoordinate;
demoCoordinate.longitude = route.startPoint.longitude;
demoCoordinate.latitude = route.startPoint.latitude;
[mapView setNeedsDisplay];
[mapView moveToLatLong:demoCoordinate];
}