2015-11-23 20 views
6

Nel frammento di codice seguente, ho installato il plugin leaflet.draw. Funziona bene per aggiungere feature (linee, marker, poligoni). Funziona bene per la modifica e l'eliminazione. Ma l'operazione di annullamento non funziona (né il semplice test di intersezione, ma posso vivere senza quello). Qualche idea su cosa ho sbagliato a configurare il plugin?leaflet.draw non si annulla correttamente

(Chrome V44, depliant 1.0 Beta 2, leaflet.draw (0.2.4-dev) (sembra venire a mancare anche in opuscolo '0.7.7')

Ecco l'errore:.

Uncaught TypeError: Cannot read property '0' of undefined 
L.Polyline.L.Path.extend._projectLatlngs @ leaflet-src.js:5535 
L.Polyline.L.Path.extend._projectLatlngs @ leaflet-src.js:5547 
L.Polyline.L.Path.extend._projectLatlngs @ leaflet-src.js:5547 
L.Polyline.L.Path.extend._project @ leaflet-src.js:5519 
L.SVG.L.Renderer.extend._updatePath @ leaflet-src.js:6042 
L.Path.L.Layer.extend.redraw @ leaflet-src.js:5130 
L.Polyline.L.Path.extend.setLatLngs @ leaflet-src.js:5411 
L.EditToolbar.Edit.L.Handler.extend._revertLayer @ leaflet.draw-src.js:2759 
(anonymous function) @ leaflet.draw-src.js:2716 
L.LayerGroup.L.Layer.extend.eachLayer @ leaflet-src.js:4865 
L.EditToolbar.Edit.L.Handler.extend.revertLayers @ leaflet.draw-src.js:2715 
L.EditToolbar.L.Toolbar.extend.disable @ leaflet.draw-src.js:2578handler @ leaflet-src.js:6953 

e qui è il codice che uso per impostare il leaflet.draw

 var theMap; 
    var mapLayer; 
    var carLayer; 
    var drawLayer; 
    var drawControl; 
    var trackerButton; 
    .... 
     this.setupDraw(); 

     theMap = L.map('mapCanvas', { 
      center: mCityCenter, 
      zoom: 20, 
      layers: [osmLight, mapLayer, carLayer, drawLayer] 
     }); 
     theMap.on("draw:created", this.addDrawing); 
     .... 
    this.setupDraw = function() { 
     drawLayer = new L.FeatureGroup(); 

     drawControl = new L.Control.Draw({ 
      draw: { 
       polygon: { 
        allowIntersection: false, // Restricts shapes to simple polygons 
        showArea: true, 
        drawError: { 
         color: '#e1e100', // Color the shape will turn when intersects 
         message: '<strong>Oh snap!<strong> you can\'t draw that!' // Message that will show when intersect 
        } 
       } 
      }, 
      edit: { 
       featureGroup: drawLayer 
      } 
     }); 
    } 
    this.addDrawing = function (e) { 
     var type = e.layerType; 
     var layer = e.layer; 

     if (type === 'marker') { } 
     drawLayer.addLayer(layer); 
    } 
+1

Potrebbe mettere questo su un violino? –

+0

Ho sbagliato. Funziona nel volantino 7.7, non funziona in 1.0 beta 2 –

+0

Vuoi dire 0.7, non c'è ancora 7.7. 1.0 è ancora un candidato alla release di oggi. Si prega di consultare la risposta dettagliata qui sotto. – nothingisnecessary

risposta

1

Quella versione di Leaflet.draw plugin non è compatibile con la versione di Volantino che si sta utilizzando.

Assicurati di leggere i documenti per il plugin, afferma che dovresti usare Leaflet.js 0.7.

Leaflet.draw: https://github.com/Leaflet/Leaflet.draw

Leaflet.JS: http://leafletjs.com/reference.html

Dalla pagina GitHub Leaflet.draw: "Leaflet.draw 0.2.3+ richiede Depliant 0.7.x."

Ad oggi ci sembra di essere un fork di Leaflet.draw che si sta sviluppando contro Volantino 1.0 RC: https://github.com/Leaflet/Leaflet.draw/tree/leaflet-master

Problemi correlati