[OpenLayers-Dev] ModifyFeature for Geometry.Rectangle and others

Eric Lemoine eric.c2c at gmail.com
Tue Nov 13 13:36:10 EST 2007

On Nov 12, 2007 11:10 AM, Patrick Valsecchi
<patrick.valsecchi at camptocamp.com> wrote:
> Hi,
> I'm in the process to write an application where the user can edit geometries
> like polygons, rectangles and circles. When I say edit I don't mean create.
> For example, the user takes an existing circle and changes its center or
> diameter.
> With the current state of OpenLayers, I can use ModifyFeature to edit
> polygons. Works great. But for Geometry.Rectangle it's a no go. This class is
> not a Geometry.Collection and thus has no "components" attribute. Because of
> that, the ModifyFeature.collectVertices throws an error.
> Now, for the circle, I know that it's not OGC material and I guess you guys
> don't want to add that in OpenLayers. So I need a way to be able to plugin
> external logics in the ModifyFeature to support other kind of shapes.
> So here is my proposition:
>   1) Change ModifyFeature.collectVertices to use a hash table (a new
> ModifyFeature attribute) that will give the method to use (equivalent of the
> current collectComponentVertices) in function of the geometry.CLASS_NAME
> value.
>   2) Add the support for Geometry.Rectangle. The collectComponentVertices for
> this class would register 4 vertices which are Geometry.Point instances with
> a modified move method that would update the x, y, w and h attributes of the
> rectangle and update the 2 neighbor vertices so that they stay coherent (in a
> rectangular formation).
> What do you think?

Your approach sounds fine to, please open a ticket and possibly add a
patch. I'll review it.

I'd like to add a few things:

To me regular polygons must be .Geometry.Polygons. However, polygons
drawn with the RegularPolygon handler could have some shape-type
property set. For example, a polygon could have its 'circle' property
set to true. In this way, Control.ModifyFeature can recognize regular
polygons and behave appropriately. For example, two virtual vertices
(center + a vertex on the circle border) will be displayed when
modifying polygons with their 'circle' property set to true.

Serialization/deserialization using OpenLayers.Format's won't be a
problem as regular problems are polygons.


More information about the Dev mailing list