Skip to content

Commit

Permalink
fix #135 (LeafletWidget behaviour on GeometryCollectionField)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Jan 4, 2016
1 parent f2e57f1 commit bebb6fd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion leaflet/static/leaflet/leaflet.forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ L.FieldStore = L.Class.extend({
}

var geojson = geom.toGeoJSON();
if (is_multi && is_generic) {
var is_geometrycollection = (geojson.geometry.type == 'GeometryCollection');
if (is_multi && is_generic && !is_geometrycollection) {
var flat = {type: 'GeometryCollection', geometries: []};
for (var i=0; i < geojson.features.length; i++) {
flat.geometries.push(geojson.features[i].geometry);
Expand Down

1 comment on commit bebb6fd

@rukayaj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just noticed that this update is causing an javascript error (with multipoints in a map anyway):

TypeError: geojson.geometry is undefined
L.FieldStore<._serialize()
leaflet.forms.js:38
L.FieldStore<.save()
leaflet.forms.js:13
L.GeometryField<.onCreated()
leaflet.forms.js:201
L.GeometryField<.addTo/<()
leaflet.forms.js:139
o.Mixin.Events.fireEvent()
leaflet.js:6
L.Draw.Feature<._fireCreatedEvent()
leaflet.draw.js:9
L.Draw.Marker<._fireCreatedEvent()
leaflet.draw.js:9
L.Draw.Marker<._onClick()
leaflet.draw.js:9
o.Mixin.Events.fireEvent()
leaflet.js:6
o.Marker<._onMouseClick()
leaflet.js:7
o.DomEvent.addListener/s()
leaflet.js:8
leaflet.forms.js:38:13

Updating it to
var is_geometrycollection = (geojson.geometry && geojson.geometry.type == 'GeometryCollection'); fixes it. I will submit a pull request.

Please sign in to comment.