0
我正在使用arcgis製作一個應用程序,讓用戶在地圖上拖動自己的手指可以自由地繪製(劃線)。我曾嘗試使用由arcgis提供的素描圖層示例來實現此目的,但沒有運氣。我也嘗試過使用opengl,但是我的繪圖並沒有留在它被繪製的位置。簡單來說,我試圖做的是在地圖上徒手繪製,當我平移和縮放地圖時,繪圖停留在繪製的地圖上的cooridantes上,並根據縮放進行伸展和縮小。在arcgis的地圖上寫意畫ios
使用opengl視圖,我可以繪製。我的問題是我需要使圖紙停留在地理座標上。這裏是我的繪圖代碼。目前我正在屏幕上獲取x和y的觸摸座標,並且需要將其更改爲地圖上的經度和緯度,然後將其轉換爲屏幕上的x和y。我不知道如何做到這一點。
// Drawings a line onscreen based on where the user touches
- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end
{
static GLfloat* vertexBuffer = NULL;
static NSUInteger vertexMax = 64;
NSUInteger vertexCount = 0, count, i;
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
// Convert locations from Points to Pixels
CGFloat scale = self.contentScaleFactor;
start.x *= scale;
start.y *= scale;
end.x *= scale;
end.y *= scale;
// Allocate vertex array buffer
if(vertexBuffer == NULL)
vertexBuffer = malloc(vertexMax * 2 * sizeof(GLfloat));
// Add points to the buffer so there are drawing points every X pixels
count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y -start.y) * (end.y - start.y))/kBrushPixelStep), 1);
for(i = 0; i < count; ++i)
{
if(vertexCount == vertexMax)
{
vertexMax = 2 * vertexMax;
vertexBuffer = realloc(vertexBuffer, vertexMax * 2 * sizeof GLfloat));
}
vertexBuffer[2 * vertexCount + 0] = start.x + (end.x - start.x) * ((GLfloat)i/(GLfloat)count);
vertexBuffer[2 * vertexCount + 1] = start.y + (end.y - start.y) * ((GLfloat)i/(GLfloat)count);
vertexCount += 1;
}
// Render the vertex array
glVertexPointer(2, GL_FLOAT, 0, vertexBuffer);
glDrawArrays(GL_POINTS, 0, vertexCount);
// Display the buffer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
// Reads previously recorded points and draws them onscreen. This is the
Shake Me message that appears when the application launches.
- (void) playback:(NSMutableArray*)recordedPaths
{
NSData* data = [recordedPaths objectAtIndex:0];
CGPoint* point = (CGPoint*)[data bytes];
NSUInteger count = [data length]/sizeof(CGPoint), i;
// Render the current path
for(i = 0; i < count - 1; ++i, ++point)
[self renderLineFromPoint:*point toPoint:*(point + 1)];
// Render the next path after a short delay
[recordedPaths removeObjectAtIndex:0];
if([recordedPaths count])
[self performSelector:@selector(playback:) withObject:recordedPaths
afterDelay:0.01];
}
// Handles the start of a touchPaintingView.m 12-08-07 9:34 AM
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch* touch = [[event touchesForView:self] anyObject];
firstTouch = YES;
// Convert touch point from UIView referential to OpenGL one (upside-down flip)
location = [touch locationInView:self];
location.y = bounds.size.height - location.y;
}
// Handles the continuation of a touch.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch* touch = [[event touchesForView:self] anyObject];
// Convert touch point from UIView referential to OpenGL one (upside-down flip)
if (firstTouch)
{
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
previousLocation.y = bounds.size.height - previousLocation.y;
}
else
{
location = [touch locationInView:self];
location.y = bounds.size.height - location.y;
previousLocation = [touch previousLocationInView:self];
previousLocation.y = bounds.size.height - previousLocation.y;
}
// Render the stroke
[self renderLineFromPoint:previousLocation toPoint:location];
}
// Handles the end of a touch event when the touch is a tap.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch* touch = [[event touchesForView:self] anyObject];
if (firstTouch)
{
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
previousLocation.y = bounds.size.height - previousLocation.y;
[self renderLineFromPoint:previousLocation toPoint:location];
}
}
你好。你的問題很不明確。你想知道什麼?此處沒有人會爲您編寫應用程序代碼。請張貼一些代碼並指出你卡在哪裏。 – 2012-08-14 06:04:22
@RüdigerHanke添加了代碼。只需要知道如何從地圖獲取座標作爲觸摸輸入,並使用它們來繪製我的視圖,而不是使用屏幕的觸摸座標和繪圖。 – 2012-08-15 16:08:59