我是可可画的新手。我想绘制一个国家的地图,然后在地图上显示该国家的所有河流,桥梁,航空等。我在不同的层中进行所有绘图,例如一层中的河流,另一层中的桥梁等等。问题是我使用nsbezierpath绘制地图,我想在单独的图层中绘制它,但我无法做到这一点。代码如下。
(void) PlotMap
{
NSAutoreleasePool *poolPlotMap = [[NSAutoreleasePool alloc] init];
NSGraphicsContext* gc = [NSGraphicsContext currentContext];
// Save the current graphics context settings
[gc saveGraphicsState];
// Set the color in the current graphics context for future draw operations
[[NSColor whiteColor] setStroke];
[[NSColor greenColor] setFill];
NSBezierPath* bPath = [NSBezierPath bezierPath];
// Object Creation for Lambert
CLambertConformalConicProjection *lLambert = [CLambertConformalConicProjection new];
[lLambert CLambertConformalConicProjection];
int First_Index = 0;
double lslat,lslong;
bool binvalid_point = TRUE;
double PixX, PixY,OldX, OldY;
float fPakMapLineStyle[2] = {1,0};
float fTempMapLineStyle[2] = {2,1};
FIRST_POINT:
if (First_Index == [MapLatValues count])
{
// Exit from Method if NO Lat Long Available
return ;
}
// Extract Point
lslat = [ [MapLatValues objectAtIndex:First_Index] doubleValue];
lslong = [ [MapLongValues objectAtIndex:First_Index] doubleValue];
/* Is this point in zoom area
if ( ( lslat >= GStartLat || lslat <= GEndLat ) || ( lslong <= GStartLong || lslong >= GEndLong ) )
{
First_Index++;
goto FIRST_POINT;
}*/
// Convert to pixel
[lLambert getDisplayXYFromLatLong:lslat :lslong :&OldX :&OldY];
//printf("\nOldX : %f", lslong);
// Run through the map coord array
/********************************************************************/
int mapLatLongCount = 0;
int mapLatLongTotalCount = [MapLatValues count];
NSPoint PakMapPointArray[mapLatLongTotalCount];
int Coord_Index;
for (Coord_Index = First_Index; Coord_Index< [MapLatValues count]; Coord_Index++)
{
// Start of FOR LOOP
// Extract Point
lslat = [ [MapLatValues objectAtIndex:Coord_Index] doubleValue];
lslong = [ [MapLongValues objectAtIndex:Coord_Index] doubleValue];
//Is this point in zoom area
if ( ( lslat >= GStartLat || lslat <= GEndLat ) || ( lslong <= GStartLong || lslong >= GEndLong ) )
{
lslat = 0;
lslong = 9999;
}
// Convert to pixel
[lLambert getDisplayXYFromLatLong:lslat :lslong :&PixX :&PixY];
if ( ( floor(lslat) != 0 ) && ( floor(lslong) != 9999) )
{
if (binvalid_point)
{
PakMapPointArray[mapLatLongCount] = NSMakePoint(PixX, iMainDisplayY - PixY);
binvalid_point = FALSE;
mapLatLongCount++;
}
else
{
PakMapPointArray[mapLatLongCount] = NSMakePoint(OldX, iMainDisplayY - OldY);
mapLatLongCount++;
}
}
else
{
binvalid_point = TRUE;
}
// Make New Pixel Points the last point
OldX = PixX;
OldY = PixY;
//[bPath closePath];
}// END of FOR LOOP
//
[bPath appendBezierPathWithPoints:PakMapPointArray count:mapLatLongCount];
[bPath stroke];
[bPath fill];
// Restore the context to what it was before we messed with it
[gc restoreGraphicsState];
[lLambert release];
[poolPlotMap release];
}