Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation NodeInPath
- @synthesize distance;
- @synthesize angle;
- @synthesize description;
- - (id)initWithNodeInPath:(NodeInPath*)other
- {
- if((self = [super init]))
- {
- [self->dict release];
- self->dict = [[other->dict copy] retain];
- self.distance = other.distance;
- self.angle = other.angle;
- self.description = [[other.description copy] autorelease];
- }
- return self;
- }
- - (void)dealloc
- {
- self.description = nil;
- [super dealloc];
- }
- - (NSMutableDictionary*)dict
- {
- return dict;
- }
- + (id)startNode:(StandModel*)stand
- {
- return [self startNode:stand.id name:stand.label];
- }
- + (id)startNode:(NSString*)standId name:(NSString*)name
- {
- NSArray *mapElements = [MapElementModel findByStandId:standId];
- if (mapElements.count == 0) {
- return nil;
- }
- NSMutableArray *mapIds = [NSMutableArray array];
- for (MapElementModel *mapElement in mapElements) {
- if (![mapIds containsObject:mapElement.mapId]) {
- [mapIds addObject:mapElement.mapId];
- }
- }
- if (mapIds.count != 1) {
- return nil;
- }
- if (mapElements.count != 1) {
- return nil;
- }
- MapElementModel *mapElement = [mapElements objectAtIndex:0];
- NodeInPath *node = [[[self alloc] init] autorelease];
- [node.dict setValue:[NSString stringWithFormat:@"startNode.%@", standId] forKey:@"ID"];
- NavigationManager *nm = [NavigationManager shared];
- [node.dict setValue:mapElement.mapId forKey:@"ORIGIN_MAP_ID"];
- if ([mapElement.mapId isEqualToString:@"0"]) {
- [node.dict setValue:[NSString stringWithFormat:@"%d", mapElement.x + mapElement.width / 2] forKey:@"X"];
- [node.dict setValue:[NSString stringWithFormat:@"%d", mapElement.y + mapElement.height / 2] forKey:@"Y"];
- } else {
- [node.dict setValue:[NSString stringWithFormat:@"%d", mapElement.x + mapElement.width / 2] forKey:@"ORIGIN_X"];
- [node.dict setValue:[NSString stringWithFormat:@"%d", mapElement.y + mapElement.height / 2] forKey:@"ORIGIN_Y"];
- CLLocationCoordinate2D coord = [nm getCoordinateOfPoint:CGPointMake(mapElement.x + mapElement.width / 2, mapElement.y + mapElement.height / 2) inMap:mapElement.mapId];
- CGPoint p = [nm getPointOf:coord inMap:@"0"];
- [node.dict setValue:[NSString stringWithFormat:@"%d", (int)round(p.x)] forKey:@"X"];
- [node.dict setValue:[NSString stringWithFormat:@"%d", (int)round(p.y)] forKey:@"Y"];
- }
- [node.dict setValue:name forKey:@"NAME"];
- [node.dict setValue:mapElement.id forKey:@"KARTENELEMENT_ID"];
- return node;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement