//
//  JsonAnalysisTool.m
//  ArcGis
//
//  Created by Mac Book DQ02 on 16/3/22.
//  Copyright © 2016年 Xu Mengzhu. All rights reserved.
//

#import "JsonAnalysisTool.h"

@implementation JsonAnalysisTool

#pragma mark 路径规划的时候查询数据库中是否有输入的地点
+(AGSPoint *)selectPointInFileByRoutingEnding:(NSString *)endingName
{
    NSArray *fileArr=@[@"gtsplay",
                       @"gtstraveling",
                       @"attractions",
                       @"food",
                       @"seviceCenters"];
    int i;
    for (i=0; i<fileArr.count; i++) {
        NSString *filePath = [[NSBundle mainBundle]pathForResource:[fileArr objectAtIndex:i] ofType:@"json"];
        NSData *jsonData = [NSData dataWithContentsOfFile:filePath];
        NSError *error;
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
        NSArray *allObjectArr = [jsonDic objectForKey:@"RECORDS"];
        for (NSDictionary *dic in allObjectArr) {
           NSString *nameStr = [dic objectForKey:@"NAME"];
            AGSPoint *poin = [[AGSPoint alloc]initWithX:[[dic objectForKey:@"POINT_X"] doubleValue] y:[[dic objectForKey:@"POINT_Y"]doubleValue] spatialReference:[AGSSpatialReference wgs84SpatialReference]];
            if ([nameStr isEqualToString:endingName]) {
                return poin;
            }
        }
    }
    
    return nil;
}


//使用KVC取值, 没有找到对应的key
- (id)valueForUndefinedKey:(NSString *)key {
    //    NSLog(@"不能识别%@", key);
    return nil;
}

#pragma mark - KVC
//使用KVC赋值, 没有找到对应的key
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    //NSLog(@"不能识别%@", key);
    
}


+(NSArray *)spotsGraphicArrWithModelArr:(NSArray *)modelArr
{
    NSMutableDictionary *graphicAttributes;
    NSMutableArray *graphicArr =[[NSMutableArray alloc]initWithCapacity:10];
    for (MarkInfoModel *model in modelArr) {
        AGSPoint *point =[[AGSPoint alloc]initWithX:model.objPoint.x y:model.objPoint.y spatialReference:[AGSSpatialReference wgs84SpatialReference]];
        AGSPoint *mapPoint = [FMDataBaseTool transferToMapViewSpatialreference:point];
        NSString *imgname = [NSString stringWithFormat:@"type_%@.png",model.objType];
        AGSPictureMarkerSymbol *pt;
        
        pt=[AGSPictureMarkerSymbol pictureMarkerSymbolWithImageNamed:imgname];
        
        //初始化graphic的Attributes，给graphic架上标志位，用于区分
        graphicAttributes =[[NSMutableDictionary alloc]initWithObjectsAndKeys:model.objImgUrl, @"graphicImg",
                            model.objName, @"graphicName",
                            model.objCode, @"graphicCode",
                            model.objAudioUrl, @"graphicAudio",
                            nil];
        AGSGraphic * graphic = [[AGSGraphic alloc]initWithGeometry:mapPoint symbol:pt attributes:graphicAttributes];
        [graphicArr addObject:graphic];
    }
    return graphicArr;
    
}


@end
