Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. @implementation NodeInPath
  2.  
  3. @synthesize distance;
  4. @synthesize angle;
  5. @synthesize description;
  6.  
  7. - (id)initWithNodeInPath:(NodeInPath*)other
  8. {
  9. if((self = [super init]))
  10. {
  11. [self->dict release];
  12. self->dict = [[other->dict copy] retain];
  13.  
  14. self.distance = other.distance;
  15. self.angle = other.angle;
  16. self.description = [[other.description copy] autorelease];
  17. }
  18.  
  19. return self;
  20. }
  21.  
  22. - (void)dealloc
  23. {
  24. self.description = nil;
  25. [super dealloc];
  26. }
  27.  
  28. - (NSMutableDictionary*)dict
  29. {
  30. return dict;
  31. }
  32.  
  33. + (id)startNode:(StandModel*)stand
  34. {
  35. return [self startNode:stand.id name:stand.label];
  36. }
  37.  
  38. + (id)startNode:(NSString*)standId name:(NSString*)name
  39. {
  40. NSArray *mapElements = [MapElementModel findByStandId:standId];
  41.  
  42. if (mapElements.count == 0) {
  43. return nil;
  44. }
  45.  
  46. NSMutableArray *mapIds = [NSMutableArray array];
  47. for (MapElementModel *mapElement in mapElements) {
  48. if (![mapIds containsObject:mapElement.mapId]) {
  49. [mapIds addObject:mapElement.mapId];
  50. }
  51. }
  52. if (mapIds.count != 1) {
  53. return nil;
  54. }
  55. if (mapElements.count != 1) {
  56. return nil;
  57. }
  58. MapElementModel *mapElement = [mapElements objectAtIndex:0];
  59.  
  60. NodeInPath *node = [[[self alloc] init] autorelease];
  61.  
  62. [node.dict setValue:[NSString stringWithFormat:@"startNode.%@", standId] forKey:@"ID"];
  63.  
  64. NavigationManager *nm = [NavigationManager shared];
  65.  
  66. [node.dict setValue:mapElement.mapId forKey:@"ORIGIN_MAP_ID"];
  67.  
  68. if ([mapElement.mapId isEqualToString:@"0"]) {
  69. [node.dict setValue:[NSString stringWithFormat:@"%d", mapElement.x + mapElement.width / 2] forKey:@"X"];
  70. [node.dict setValue:[NSString stringWithFormat:@"%d", mapElement.y + mapElement.height / 2] forKey:@"Y"];
  71. } else {
  72. [node.dict setValue:[NSString stringWithFormat:@"%d", mapElement.x + mapElement.width / 2] forKey:@"ORIGIN_X"];
  73. [node.dict setValue:[NSString stringWithFormat:@"%d", mapElement.y + mapElement.height / 2] forKey:@"ORIGIN_Y"];
  74.  
  75. CLLocationCoordinate2D coord = [nm getCoordinateOfPoint:CGPointMake(mapElement.x + mapElement.width / 2, mapElement.y + mapElement.height / 2) inMap:mapElement.mapId];
  76.  
  77. CGPoint p = [nm getPointOf:coord inMap:@"0"];
  78.  
  79. [node.dict setValue:[NSString stringWithFormat:@"%d", (int)round(p.x)] forKey:@"X"];
  80. [node.dict setValue:[NSString stringWithFormat:@"%d", (int)round(p.y)] forKey:@"Y"];
  81. }
  82. [node.dict setValue:name forKey:@"NAME"];
  83. [node.dict setValue:mapElement.id forKey:@"KARTENELEMENT_ID"];
  84. return node;
  85. }
  86.  
  87. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement