2012-08-13 59 views
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]; 
    } 
} 
+0

你好。你的问题很不明确。你想知道什么?此处没有人会为您编写应用程序代码。请张贴一些代码并指出你卡在哪里。 – 2012-08-14 06:04:22

+0

@RüdigerHanke添加了代码。只需要知道如何从地图获取坐标作为触摸输入,并使用它们来绘制我的视图,而不是使用屏幕的触摸坐标和绘图。 – 2012-08-15 16:08:59

回答

1

对于这个

“目前我得到的X和Y在屏幕上的触摸坐标,并且需要将其更改为经度和纬度的地图上,然后将其转换为x和y的屏幕上,我不知道该怎么做。“

我建议将触摸笔划的所有坐标保存在数组中,然后将这些坐标添加到AGSPolyline中。执行此操作的方法如下

  1. 为阵列中的每个坐标创建CGPoint。
  2. 使用变换CGPoint到AGSPoint [self.mapview toMapPoint:CGPoint]
  3. 使用addpointtopath方法将点添加到agspolyline