ThinkGeo.com    |     Documentation    |     Premium Support

How to programatically move points/lines/etc.?

Is there a way to move points/lines/polygons in the TrackShapeLayer programatically? Let’s say I have a single line with two vertices. I want to be able to move the entire line (it’s center position) to a new x, y position, as well as being able to change individual vertices of the line as well. I’m assuming I would get the feature by ID first, but I can’t find an update position function or something related to that.

Thanks,
Dan

Hi Dan,

If you want to move the shape by code, please view the sample:8697.zip (10.0 KB)

If you want to move them by mouse, please view this topic for detail: Drag Multiple Features

Regards,

Ethan

Thanks for the response. This isn’t quite what I was looking for. I want to be able to move shapes/vertices by giving new x,y coordinates. Is there any way to do it besides making a new collection of vertices and then a new shape and setting the old equal to it? Is there a property to change that will move the entire shape to new coordinates?

Thanks,
Dan

Hi Dan,

It’s not an exactly requirement, because in fact your shape is a group of vertexes, you want to move “it” to new lon&lat, we need to make sure you want to move a specified vertex in the shape to this new coordinate or move the barycenter point to new coordinate. If you means you want to move entire shape, that’s still need to choose a vertex as the flag between old coordinate and new coordinate.

And in fact all the “move” operation is not the really move, it’s remove and add, or edit one or more vertexes in the shape. For easier handle that, we suggest to remove feature, edit it and add it back.

Any further question please let me know.

Regards,

Ethan

How do you move the barycenter? Would moving that move the entire shape to that coordinate?

Hi Dan,

I just make a sample, our shape don’t contains a existing barycenter point, that’s a virtual point, you need to calculate that.

If you want to move the barycenter, that means you want to move the entire shape. So the solution should be:

  1. Calculate the barycenter point.
  2. Calculate the distance from the barycenter and target coordinates
  3. Loop all vertexes and calculate the new vertexes by the distance
  4. Create the new shape and delete original shape

Wish that’s helpful.

Regards,

Ethan