I’m sure this is more of a mathematical question, but I will formulate it in the context of UIView and the iPad-related goal of C
I am importing raw data from a mapping file that I created from some public domain material loaded in another location, and then split it to isolate different areas on the map. Each region has several subregions, such as the continental United States, and then various states that appear in the United States, and then each subregion is again divided into, say, counties.
Each state and each county has a bounding box that tells me where the origin, width and height come from.
In my initial setup, I created a separate view for each state, and then a different view for each county. The polygon representing the state / county area was visualized (obviously with a county on top of the state so that it was visible) relative to the view I created through the interface builder called mainContainerView. This initial setup worked correctly.
Now I'm trying to make a little difference by adding counties to the UIView while holding the polygon for the state, so I can apply the state as a clipping mask in the counties. The problem is that no matter what I try, I can not get the county to transfer to the right place in the state view.
It seems like it should be simple addition or subtraction, since the scaling for each element is exactly the same, and I am not trying to do any major transformations, so I do not think that the CFAffineTransformation family is necessary.
I can send the code if necessary, but I'm not trying to get someone to write my program for me; I just want someone to point me in the right direction here, offering me a suggestion on how to establish a county regarding the state in the state’s representation.
, , . , , . , , .SHP, ( ). , , , .
MASK_MAX_EASTING, MASK_MAX_NORTHING, MASK_MIN_EASTING MASK_MIN_NORTHING - , , .
DIST_MAX_EASTING, DIST_MAX_NORTHING, DIST_MIN_EASTING DIST_MIN_NORTHING - , , . , , , .
-(void)didLoadMap:(NSNotification *)notification {
id region = [notification object];
ShapePolyline *polygon = [region polygon];
if ([notification name] == @"MapsLoadingForState") {
CGFloat originX = ((polygon->m_nBoundingBox[0]-MASK_MIN_EASTING)*stateScaleMultiplier)+([mainContainerView frame].size.width/2);
CGFloat originY = ((MASK_MAX_NORTHING-(polygon->m_nBoundingBox[3]))*stateScaleMultiplier)+[mainContainerView frame].origin.y;
CGFloat width = polygon->m_nBoundingBox[2] - polygon->m_nBoundingBox[0];
CGFloat height = polygon->m_nBoundingBox[3] - polygon->m_nBoundingBox[1];
CGFloat scaledWidth = width*stateScaleMultiplier;
CGFloat scaledHeight = height*stateScaleMultiplier;
UIColor *subViewColor = [UIColor colorWithRed:0.0 green:1.0 blue:1.0 alpha:0.0];
stateMapView = [[DrawMap alloc] initWithFrame:CGRectMake(originX, originY, scaledWidth, scaledHeight)];
[stateMapView setBackgroundColor:subViewColor];
[stateMapView setStateScale:stateScaleMultiplier];
[stateMapView setCountyScale:countyScaleMultiplier];
[stateMapView setClippingMask:polygon];
UIColor *colorMask = [UIColor colorWithWhite:1.0 alpha:1.0];
[stateMapView setForeground:colorMask];
[states addObject:stateMapView];
[mapView addSubview:stateMapView];
} else {
CGFloat originX = (polygon->m_nBoundingBox[0]-DIST_MIN_EASTING);
originX *= countyScaleMultiplier;
originX += ([mainContainerView frame].size.width/2);
CGFloat originY = (DIST_MAX_NORTHING-polygon->m_nBoundingBox[3]); 4328997
originY *= countyScaleMultiplier;
originY -= [mainContainerView frame].origin.y;
CGRect frame = [stateMapView frame];
originX -= frame.origin.x;
originY -= frame.origin.y;
CGPoint countyOrigin = CGPointMake(originX,originY);
[stateMapView addCountyMap:[region polygon] withColor:winner translatedBy:countyOrigin];
[stateMapView setNeedsDisplay];
}
, , , , ( ), ...
DrawMap.m; , .
- (void)drawRect:(CGRect)rect {
for (int i=0;i<[countyMaps count];i++) {
[[countyColors objectAtIndex:i] setFill];
[self drawPolygon:[countyMaps objectAtIndex:i]
usingScale:stateScale
translatedBy:CGPointMake([[countyTranslations objectAtIndex:2*i] floatValue],
[[countyTranslations objectAtIndex:2*i+1] floatValue])];
}
CGContextSetBlendMode(context, kCGBlendModeMultiply);
[[UIColor colorWithWhite:1.0 alpha:1.0] setFill];
[self drawPolygon:clippingMask usingScale:stateScale translatedBy:CGPointMake(0,0)];
}
-(void)drawPolygon:(ShapePolyline *)aPolygon usingScale:(float)mapScale translatedBy:(CGPoint)trans {
for (int j=0;j<[aPolygon numParts];j++) {
UIBezierPath *path = [UIBezierPath bezierPath];
[path setLineJoinStyle:kCGLineJoinRound];
int startIndex = [[[aPolygon m_Parts] objectAtIndex:j] intValue];
int endIndex = [aPolygon numPoints];
CGPoint startPoint;
[[[aPolygon m_Points] objectAtIndex:startIndex] getValue:&startPoint];
startPoint.x *=mapScale;
startPoint.y *=mapScale;
startPoint.x -= trans.x;
startPoint.y -= trans.y;
[path moveToPoint:startPoint];
if (j+1 != [aPolygon numParts]){
endIndex = [[[aPolygon m_Parts] objectAtIndex:j+1] intValue];
}
for (int k=startIndex+1; k<endIndex; k++)
{
CGPoint nextPoint;
[[[aPolygon m_Points] objectAtIndex:k] getValue:&nextPoint];
nextPoint.x *= mapScale;
nextPoint.y *= mapScale;
nextPoint.x -= trans.x;
nextPoint.y -= trans.y;
[path addLineToPoint:nextPoint];
}
[path closePath];
[path fill];
}
}
, . , , , , ...