2012-08-13 7 views
0

사용자가 자유롭게 손가락을 드래그하여지도에 (레드 라인으로) 그릴 수있는 arcgis를 사용하여 iOS 용 앱을 만들고 있습니다. arcgis가 제공 한 스케치 레이어 예제를 사용하여이 기능을 구현하려했지만 행운이 없었습니다. 나는 또한 OpenGL을 사용하여 시도했지만 그림이 그려지는 위치에 머무르지 않습니다. 간단히 말하면, 무엇을 하려는지 자유형 그리기는지도에 표시하고지도를 이동하고 확대/축소 할 때 도면은 그려진지도상의 좌표에 그대로 머물러 있으며 확대/축소를 기준으로 늘어나 축소됩니다.ios 용 arcgis지도에서 자유 그리기

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

헬로우 포인트를 추가 할. 귀하의 질문은 분명하지 않습니다. 정확히 당신이 알고 싶은 것은 무엇입니까? 여기에 누구도 앱 코드를 작성하지 않습니다. 몇 가지 코드를 게시하고 어디서 붙어 있는지 지적하십시오. –

+0

@ RüdigerHanke가 코드를 추가했습니다. 터치 좌표로지도에서 좌표를 가져 오는 방법을 알아야하고 화면의 좌표를 가져 와서 양식을 그리는 대신 내보기로 그리는 데 사용해야합니다. –

답변

1

"현재 나는 터치 화면에 x와 y 좌표 및지도에 위도와 경도로 변경 한 다음에 x와 y로 변환 할 필요가 무엇입니까 화면. 어떻게해야할지 모르겠다. "

터치 스트로크의 좌표를 모두 배열에 저장 한 다음이 좌표를 AGSPolyline에 추가하는 것이 좋습니다. 이를 수행하는 방법은 다음과 같습니다.

  1. 배열의 각 좌표에 대해 CGPoint를 만듭니다.
  2. 가 사용 AGSPoint로 변환 CGPoint [self.mapview toMapPoint : CGPoint]
  3. 사용 addpointtopath 방법은 agspolyline