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

InfoMap bug with quick fix #3

Closed adonm closed 14 years ago

adonm commented 14 years ago

In olwidget/widgets.py under InfoMap this line (198): wkt_array = [[add_srid(collection_wkt(geom)), html] for geom, html in self.info] should be wkt_array = [[add_srid(get_wkt(geom)), html] for geom, html in self.info]

because each geom is a single spatial feature not an array?

I'm new to the whole submitting patches thing so I just made an issue.

yourcelf commented 14 years ago

It should in fact use collection_wkt, not get_wkt. Geodjango supports multi-geometry types, where a single model field is a collection of geometries. collection_wkt supports that case as well as the case where one is using just a single geometry, and since InfoMap is a read-only map, it doesn't matter if we make it a collection type.

elpaso commented 14 years ago

I think my issue is related with this:

TemplateSyntaxError at /resource/poi/1/

Caught an exception while rendering: 'float' object has no attribute 'ogr'

File "contrib/olwidget/widgets.py", line 283, in get_wkt ogr = value.ogr AttributeError: 'float' object has no attribute 'ogr'

This is my view code, p.geom is a PointField

def poi_view(request, object_id): p = get_object_or_404(Poi, pk=object_id)

map =  InfoMap([
    [ p.geom, p.name + p.description ],
], options = { 'layers': ['ve.hybrid'],  'default_zoom ' : 5 })

return render_to_response('resource/poi_detail.html', {
    'object': p,
    'map': map,
})

I dont' understand the line:

       # convert fields to wkt
        for geom, html in self.info:
            wkt_array = [[add_srid(collection_wkt(geom)), html] for geom, html in self.info]

Is seems like it's looping two times over the same collection...

yourcelf commented 14 years ago

Thanks elpaso, you (and adonm) are correct. The former code works properly only in the case where "geom" is a collection type, and thus iterable. This is fixed in 4f361c323ab932e9ecae97edb4583efde62d4a4c .

yourcelf commented 14 years ago

Oops, introduced a regression there for changelist maps. Fixed in latest master.