Skip to content

Instantly share code, notes, and snippets.

@nitrag
Created December 14, 2015 19:46
Show Gist options
  • Select an option

  • Save nitrag/5d790ca6079dc659c322 to your computer and use it in GitHub Desktop.

Select an option

Save nitrag/5d790ca6079dc659c322 to your computer and use it in GitHub Desktop.
NSArray *features = [geoJson valueForKey:@"features"];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
NSUInteger l = [features count];
NTGeoJSONGeometryReader* geoJsonReader = [[NTGeoJSONGeometryReader alloc] init];
for (int i=0; i<l; i++) {
NSDictionary* feature = [features objectAtIndex:i];
NSDictionary *properties = [feature valueForKey:@"properties"];
if([properties valueForKey:@"color"] != nil ){
[lineStyleBuilder setColor:[[NTColor alloc] initWithColor:[self nColorConverter:[properties valueForKey:@"color"]]]];
}else{
[lineStyleBuilder setColor:[[NTColor alloc] initWithColor:[self nColorConverter:@""]]];
}
NSDictionary *geometry = [feature valueForKey:@"geometry"];
NSData *geomData = [NSJSONSerialization dataWithJSONObject:geometry
options:NSJSONWritingPrettyPrinted
error:nil];
NSString* geomJson = [[NSString alloc] initWithData:geomData encoding:NSUTF8StringEncoding];;
NTGeometry *geom = [geoJsonReader readGeometry:geomJson];
NTLine *lineElement = [[NTLine alloc] initWithGeometry:geom style:[lineStyleBuilder buildStyle]];
NSError * err;
NSData * jsonData = [NSJSONSerialization dataWithJSONObject:properties options:0 error:&err];
NSString * myString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
[ lineElement setMetaDataElement:@"properties" element:myString];
[dataSource add:lineElement];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment