yourcelf / olwidget

Javascript library to replace textareas that contain WKT data with editable OpenLayers maps, and a django app using it for django forms and admin.
Other
91 stars 44 forks source link

Editing collections: number of geometries is limited to number of geometries you start with, or 1 #67

Closed slinkp closed 13 years ago

slinkp commented 13 years ago

When editing collections, if there are no geometries, you can never add more than one. If there are already multiple geometries, you can decrease - but never increase - the number of geometries.

To reproduce this in django-olwidget:

1) Store this WKT in a GeometryField: https://gist.github.com/1007057

2) Hook up olwidget to your admin, ensure you have isCollection=True, and try clicking the "draw polygons" tool.

3) Notice that when you complete the first polygon, one of the existing polygons disappears. Every time you add a geometry, an existing geometry is removed, so there are always 3.

4) Try deleting one of the polygons by removing points. Save the geometry and reload the page. Now the number of geometries is capped at two!

5) Try clearing all geometries. Now the number of geometries is capped to one.

6) Try creating a new instance of your model. The number of geometries is capped to one.

slinkp commented 13 years ago

Found the problem. Although my Field class has isCollection=True by default, the rendered javascript had isCollection=False. Exploring this, I found that the widget created by apply_maps_to_modelform_fields, which uses utils.options_for_field(field).

My db field is a generic GeometryField, i.e. able to hold anything. But on line 102 of utils.py it says: is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION')

So because of that line, GeometryFields are not allowed to be collections.

I think that's wrong, as it limits GeometryField to holding non-Multi geometries.

yourcelf commented 13 years ago

Thanks, pushed this.