1. - (MKAnnotationView *)mapView:(MKMapView *)mapView1 viewForAnnotation:(id <MKAnnotation>)annotation
  2. {
  3. // CPLog(@"View for Annotation is called");
  4.  
  5. if ([annotation isKindOfClass:[MarkChargePoint class]])
  6. {
  7. MarkChargePoint *markPoint = (MarkChargePoint *)annotation;
  8. if([markPoint getChargingStationId] == -1)
  9. {
  10. MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:STR_CHARGEPOINT_LOWERCASE];
  11. if (!annotationView)
  12. {
  13. annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:STR_CHARGEPOINT_LOWERCASE] autorelease];
  14. }
  15.  
  16. annotationView.userInteractionEnabled = TRUE;
  17. annotationView.canShowCallout = YES;
  18. annotationView.image = [Utils userLocationImage];
  19. annotationView.rightCalloutAccessoryView = nil;
  20. return annotationView;
  21. }
  22. else
  23. {
  24. MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:STR_CHARGEPOINT_LOWERCASE];
  25. if (!annotationView)
  26. {
  27. annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:STR_CHARGEPOINT_LOWERCASE] autorelease];
  28. }
  29.  
  30. annotationView.userInteractionEnabled = TRUE;
  31. annotationView.canShowCallout = YES;
  32.  
  33. UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  34. disclosureButton.tag = markPoint.getChargePointId;
  35. annotationView.rightCalloutAccessoryView = disclosureButton;
  36. disclosureButton = nil;
  37.  
  38. annotationView.image = [UIImage imageNamed:[Utils getAnnotatoinImageName:[markPoint getDeviceMask]]];
  39.  
  40.  
  41. return annotationView;
  42. }
  43. }
  44. else if ([annotation isKindOfClass:[MKUserLocation class]])
  45. {
  46. if (mapView.userLocationVisible == NO)
  47. {
  48. return [mapView viewForAnnotation:mapView.userLocation];
  49. }
  50. else
  51. {
  52. return nil;
  53. }
  54. }
  55.  
  56. return nil;
  57. }
  58.  
  59. //-------------------------------------------------------------------------
  60. // Method: didAddAnnotationViews
  61. //
  62. // Description: event handler for didAddAnnotationViews on map view
  63. //
  64. // Parameter: MKMapView:mapView1
  65. //--------------------------------------------------------------------------
  66. -(void)mapView:(MKMapView *)mapView1 didAddAnnotationViews:(NSArray *)views
  67. {
  68. // CPLog(@"MapViewController: didAddAnnotationViews*****************************");
  69. if ([Utils doesSupportiOS4])
  70. {
  71. if (selectedAnnotation != nil && [selectedAnnotation getChargingStationId] > 0)
  72. {
  73. CPLog(@"MapViewController: didAddAnnotationViews");
  74. for (MKAnnotationView *annView in views)
  75. {
  76. if ([[annView annotation] isKindOfClass:[MarkChargePoint class]])
  77. {
  78. MarkChargePoint *markChargePoint = (MarkChargePoint *)[annView annotation];
  79. if([markChargePoint getChargingStationId] == [selectedAnnotation getChargingStationId])
  80. {
  81. [[annView superview] bringSubviewToFront:annView];
  82. }
  83. else
  84. {
  85. [[annView superview] sendSubviewToBack:annView];
  86. }
  87. }
  88. }
  89. }
  90. }
  91.  
  92. if (selectedAnnotation != nil && [selectedAnnotation getChargingStationId] > 0)
  93. {
  94. [mapView1 deselectAnnotation:selectedAnnotation animated:YES];
  95. [mapView1 selectAnnotation:selectedAnnotation animated:YES];
  96. }
  97. }
  98.  
  99. //-------------------------------------------------------------------------
  100. // Method: removeAnnotationViews
  101. //
  102. // Description: remove Annotation Views from the map
  103. //
  104. // Parameter:
  105. //--------------------------------------------------------------------------
  106. -(void)removeAnnotationViews
  107. {
  108. CPLog(@"Removing Annotations: MapViewController ***");
  109.  
  110. NSArray *annotationArray = [mapView annotations];
  111. if (annotationArray != nil)
  112. {
  113. NSMutableArray *mapAnnotationArray = [[NSMutableArray alloc]init];
  114.  
  115. for (MKAnnotationView *annotation in annotationArray)
  116. {
  117. if ([annotation isKindOfClass:[MKUserLocation class]] != YES)
  118. {
  119. MarkChargePoint *markChargePoint = (MarkChargePoint *)annotation;
  120. if (markChargePoint != nil)
  121. {
  122. [mapAnnotationArray addObject:markChargePoint];
  123. }
  124. }
  125. }
  126.  
  127. for (MarkChargePoint *markPoint in mapAnnotationArray)
  128. {
  129. [mapView removeAnnotation:markPoint];
  130. }
  131.  
  132. [mapAnnotationArray release];
  133. mapAnnotationArray = nil;
  134. }
  135. }
  136.  
  137. //-------------------------------------------------------------------------
  138. // Method: didSelectAnnotationView
  139. //
  140. // Description: Perfoerm actions on selecting an annotation
  141. //
  142. // Parameter: views:MKAnnotationView
  143. //--------------------------------------------------------------------------
  144. -(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)views
  145. {
  146. if ([Utils doesSupportiOS4])
  147. {
  148. [[views superview] bringSubviewToFront:views];
  149. }
  150. }
  151.  
  152. //-------------------------------------------------------------------------
  153. // Method: didDeselectAnnotationView
  154. //
  155. // Description: Perfoerm actions on deselecting an annotation
  156. //
  157. // Parameter: views:MKAnnotationView
  158. //--------------------------------------------------------------------------
  159. -(void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)views
  160. {
  161. if ([Utils doesSupportiOS4])
  162. {
  163. [[views superview] sendSubviewToBack:views];
  164. }
  165. }