- (MKAnnotationView *)mapView:(MKMapView *)mapView1 viewForAnnotation:(id )annotation { // CPLog(@"View for Annotation is called"); if ([annotation isKindOfClass:[MarkChargePoint class]]) { MarkChargePoint *markPoint = (MarkChargePoint *)annotation; if([markPoint getChargingStationId] == -1) { MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:STR_CHARGEPOINT_LOWERCASE]; if (!annotationView) { annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:STR_CHARGEPOINT_LOWERCASE] autorelease]; } annotationView.userInteractionEnabled = TRUE; annotationView.canShowCallout = YES; annotationView.image = [Utils userLocationImage]; annotationView.rightCalloutAccessoryView = nil; return annotationView; } else { MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:STR_CHARGEPOINT_LOWERCASE]; if (!annotationView) { annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:STR_CHARGEPOINT_LOWERCASE] autorelease]; } annotationView.userInteractionEnabled = TRUE; annotationView.canShowCallout = YES; UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; disclosureButton.tag = markPoint.getChargePointId; annotationView.rightCalloutAccessoryView = disclosureButton; disclosureButton = nil; annotationView.image = [UIImage imageNamed:[Utils getAnnotatoinImageName:[markPoint getDeviceMask]]]; return annotationView; } } else if ([annotation isKindOfClass:[MKUserLocation class]]) { if (mapView.userLocationVisible == NO) { return [mapView viewForAnnotation:mapView.userLocation]; } else { return nil; } } return nil; } //------------------------------------------------------------------------- // Method: didAddAnnotationViews // // Description: event handler for didAddAnnotationViews on map view // // Parameter: MKMapView:mapView1 //-------------------------------------------------------------------------- -(void)mapView:(MKMapView *)mapView1 didAddAnnotationViews:(NSArray *)views { // CPLog(@"MapViewController: didAddAnnotationViews*****************************"); if ([Utils doesSupportiOS4]) { if (selectedAnnotation != nil && [selectedAnnotation getChargingStationId] > 0) { CPLog(@"MapViewController: didAddAnnotationViews"); for (MKAnnotationView *annView in views) { if ([[annView annotation] isKindOfClass:[MarkChargePoint class]]) { MarkChargePoint *markChargePoint = (MarkChargePoint *)[annView annotation]; if([markChargePoint getChargingStationId] == [selectedAnnotation getChargingStationId]) { [[annView superview] bringSubviewToFront:annView]; } else { [[annView superview] sendSubviewToBack:annView]; } } } } } if (selectedAnnotation != nil && [selectedAnnotation getChargingStationId] > 0) { [mapView1 deselectAnnotation:selectedAnnotation animated:YES]; [mapView1 selectAnnotation:selectedAnnotation animated:YES]; } } //------------------------------------------------------------------------- // Method: removeAnnotationViews // // Description: remove Annotation Views from the map // // Parameter: //-------------------------------------------------------------------------- -(void)removeAnnotationViews { CPLog(@"Removing Annotations: MapViewController ***"); NSArray *annotationArray = [mapView annotations]; if (annotationArray != nil) { NSMutableArray *mapAnnotationArray = [[NSMutableArray alloc]init]; for (MKAnnotationView *annotation in annotationArray) { if ([annotation isKindOfClass:[MKUserLocation class]] != YES) { MarkChargePoint *markChargePoint = (MarkChargePoint *)annotation; if (markChargePoint != nil) { [mapAnnotationArray addObject:markChargePoint]; } } } for (MarkChargePoint *markPoint in mapAnnotationArray) { [mapView removeAnnotation:markPoint]; } [mapAnnotationArray release]; mapAnnotationArray = nil; } } //------------------------------------------------------------------------- // Method: didSelectAnnotationView // // Description: Perfoerm actions on selecting an annotation // // Parameter: views:MKAnnotationView //-------------------------------------------------------------------------- -(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)views { if ([Utils doesSupportiOS4]) { [[views superview] bringSubviewToFront:views]; } } //------------------------------------------------------------------------- // Method: didDeselectAnnotationView // // Description: Perfoerm actions on deselecting an annotation // // Parameter: views:MKAnnotationView //-------------------------------------------------------------------------- -(void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)views { if ([Utils doesSupportiOS4]) { [[views superview] sendSubviewToBack:views]; } }