рисовать от руки на карте в arcgis для ios

Я делаю приложение для ios с использованием arcgis, которое позволяет пользователю свободно рисовать (выделять красную линию) на карте, перетаскивая их пальцем. Я попытался использовать пример слоя эскиза, предоставленный arcgis, чтобы реализовать это, но мне не повезло. Я также пробовал использовать opengl, но мой рисунок не соответствует тому месту, где он был нарисован. Проще говоря, то, что я пытаюсь сделать, - это нарисовать карту от руки, и когда я панорамирую и масштабирую карту, рисунок остается в своих координатах на карте, на которой он был нарисован, и растягивается и сжимается в зависимости от масштабирования.

используя представление 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];
     }
}

person hamza h    schedule 13.08.2012    source источник
comment
Привет. Ваш вопрос довольно непонятный. Что именно вы хотите знать? Никто здесь не будет писать код вашего приложения за вас. Пожалуйста, разместите код и укажите, где вы застряли.   -  person Rüdiger Hanke    schedule 14.08.2012
comment
@ RüdigerHanke добавил код. просто нужно знать, как брать координаты с карты в качестве сенсорного ввода и использовать их для рисования на моем представлении, вместо того, чтобы брать сенсорные координаты экрана и рисовать их.   -  person hamza h    schedule 15.08.2012


Ответы (1)


Для этого

«в настоящее время я получаю сенсорные координаты x и y на экране, и мне нужно изменить их на долготу и широту на карте, а затем преобразовать их в x и y на экране. Я не знаю, как это сделать».

Я бы посоветовал сохранить все координаты касания в массиве, а затем добавить эти координаты в AGSPolyline. Это можно сделать следующим образом

  1. создайте CGPoint для каждой координаты в вашем массиве.
  2. преобразовать CGPoint в AGSPoint с помощью [self.mapview toMapPoint: CGPoint]
  3. используйте метод addpointtopath, чтобы добавить точки к полилинии
person azmuhak    schedule 17.09.2013