Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing Polygons with Leaflet Draw #22

Open
1marty4sale opened this issue Jun 3, 2015 · 4 comments
Open

Editing Polygons with Leaflet Draw #22

1marty4sale opened this issue Jun 3, 2015 · 4 comments
Labels

Comments

@1marty4sale
Copy link

Is it possible to edit polygons with Leaflet Draw with snapping enabled?

I have it working when creating new polygons. I have tried this code:

var polyline = L.polyline(...).addTo(map);
    polyline.snapediting = new L.Handler.PolylineSnap(map, polyline);
    polyline.snapediting.addGuideLayer(guideLayer);
    polyline.snapediting.enable();

Which doesn't work because there is no fill set. When I replace the polylineSnap with polygonSnap it tells me it is not a function.

This is how I enabled snapping for creating a polygon:

    var guideLayers = [lakes];
    var drawControl = new L.Control.Draw({
        polygon: {
            showArea: true,
            guideLayers: guideLayers, 
            snapDistance: 15,
            guidelineDistance: 10,
            shapeOptions: {
                color: shapeTypeObject[shapeType].color
            }
        }
    });
    createPolygon = new L.Draw.Polygon(map, drawControl.options.polygon);
    createPolygon.enable();

That works for creating but when I use the same method for editing it has no effect.

@fsauter
Copy link

fsauter commented Jun 29, 2015

I have the same problem:

var drawnItems = new L.FeatureGroup();

var drawControl = new L.Control.Draw({
        draw: {
            polyline: {
                guideLayers: drawnItems
            },
            polygon: false,
            rectangle: false,
            circle: false,
            marker: {
                guideLayers: drawnItems
            }
        },
        edit: {
            featureGroup: drawnItems
        }
    });

var routePolyline = new L.Polyline(routePoints, routePolylineOptions);
var routePolylineDrawn = drawnItems.addLayer(routePolyline);

routePolyline.snapediting = new L.Handler.PolylineSnap(Application.routes.map, routePolylineDrawn);
routePolyline.snapediting.addGuideLayer(drawnItems);
routePolyline.snapediting.enable();

Results in:

Uncaught TypeError: Cannot read property 'editing' of undefinedL.Edit.Poly.L.Handler.extend.addHooks @ leaflet.draw-src.self-3a363f7fa59b4aad45feb25ef226ed4b72b853f3bfccbaca9f91b367c0e02924.js?body=1:1154

It happens in this block:

if (!(poly instanceof L.Polygon)) {
    poly.options.editing.fill = false;
}

I use leaflet 0.7.3, draw 0.2.3 and the latest master file from snap.

Any ideas whats wrong?

@leplatrem
Copy link
Collaborator

I'm sorry I can't spend time to help you on this... (I don't work with these tools anymore)
Theorically it should work :)

@zakonnic
Copy link

This is a Leaflet.draw bug, the issue and workaround can be found here:
Leaflet/Leaflet.draw#364 (comment)

@bastyen
Copy link
Member

bastyen commented Aug 22, 2016

I think #30 solve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants