 
       widget = this
 
-      this.map.on "draw:created", (e) ->
-        widget.edition.addLayer e.layer
+      this.map.on "draw:created", (e) =>
+        #Attempt to add a geojson feature
+        try
+          feature = e.layer.toGeoJSON()
+          feature.properties['internal_id'] = new Date().getTime()
+          widget.edition.addData feature
+        catch
+          widget.edition.addLayer e.layer
+
         widget._saveUpdates()
         widget.element.trigger "mapchange"
 

      if this.reference?
        this.map.removeLayer this.reference
      if this.options.show?
        this.reference = L.GeoJSON.geometryToLayer(this.options.show).setStyle this.options.showStyle
        this.reference.addTo this.map
      this


        this.element.val JSON.stringify(this.edition.toGeoJSON())
      true

    update: ->
      this._saveUpdates()
      this.element.trigger "mapchange"

  $(document).ready ->
    $("input[data-map-editor]").each ->
      $(this).mapeditor()
