Leaflet / Leaflet.draw

Vector drawing and editing plugin for Leaflet
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html
MIT License
1.98k stars 996 forks source link

leaflet.draw.js:9 Uncaught TypeError: Cannot set property 'original' of undefined #560

Open udos opened 8 years ago

udos commented 8 years ago

hi,

when I am executing code locally (see https://jsfiddle.net/udos/1035sp5x/) everything loads normally. when I click the leaflet.draw "edit layers" icon, I get error

after this also "Save" or "cancel" does not work anymore.

maybe it is due to geometry type MultiLineString.

note: on jsfiddle the error is

I'm not sure if it is a bug or I am using it the wrong way...

thanks, udo

yporret commented 8 years ago

i think leaflet-draw does not support MultiLine.

Do you really need to have a multiLine or can you try to make an array of polyLine instead (or something else) ?

udos commented 8 years ago

I prefer to use GeoJson objects. as a workaround I will try to do something you suggested. maybe a FeatureCollection of LineString...

udos commented 8 years ago

instead of using a GeoJSON Feature Object in which the geometry is of type MultiLineString as in

a GeoJSON Feature Collection Object in which the single geometries are of type LineString as in

will not cause the error I reported

jameslaneconkling commented 8 years ago

The docs should be clearer on not supporting multigeometries. Although it's not hard to cast from multigeometry to feature collection, there's no reason that a user should assume that the control doesn't support specific features covered by the spec.

jameslaneconkling commented 8 years ago

submitted a PR: https://github.com/Leaflet/Leaflet.draw/pull/569

dkarakostis commented 8 years ago

@jameslaneconkling can you please explain me how exactly its possible to cast multigeometry to feature collection? Is something like this possible to do using jquery and leaflet?

jameslaneconkling commented 8 years ago

@dkarakostis because geoJSON is just an object literal, you shouldn't need a library to do the conversion. See the geoJSON docs. Something like this should work:

function multiGeometry2FeatureCollection(multigeometry) {
  return {
    type: 'FeatureCollection'
    features: multigeometry.coordinates.map(function(coordinates) {
      return {type: multigeometry.type.replace('Multi', ''), coordinates: coordinates};
    })
  };
}
dkarakostis commented 8 years ago

Thanks. Double checking my response from the ajax request, I see that the returned geoJSON is already a FeatureColletction:

Object {type: "FeatureCollection", totalFeatures: 1, features: Array[1], crs: Object}

On Thu, Jul 28, 2016 at 1:29 AM, James Conkling notifications@github.com wrote:

@dkarakostis https://github.com/dkarakostis because geoJSON is just an object literal, you shouldn't need a library to do the conversion. See the geoJSON docs http://geojson.org/geojson-spec.html. Something like this should work:

function multiGeometry2FeatureCollection(multigeometry) { return { type: 'FeatureCollection' features: multigeometry.coordinates.map(function(coordinates) { return {type: multigeometry.type.replace('Multi', ''), coordinates: coordinates}; }) }; }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Leaflet/Leaflet.draw/issues/560#issuecomment-235752593, or mute the thread https://github.com/notifications/unsubscribe-auth/APfg_2tb9nuVhDyTLACLUO_7W7eUNMXtks5qZ-nxgaJpZM4JDKg9 .