Edit mode allows intersection even when polygon: {allowIntersection: false} #131

Open
stuporglue opened this Issue Apr 24, 2013 · 9 comments

Comments

Projects
None yet
8 participants

I have specified
polygon: { allowIntersection: false }
in my constructor.

For creating new features this is respected correctly.

When editing existing features intersections are allowed. It seems that edit mode should respect the allowIntersection parameter.

Owner

jacobtoye commented Apr 25, 2013

Ah yes, currently edit doesn't support this functionality :( The code subsides in Draw.Polyline.js, Need to update Edit.Polyline to support allowIntersection as well.

@jduhls jduhls referenced this issue in Turfjs/turf Feb 28, 2014

Closed

polygons that intersect themselves #92

jduhls commented Mar 8, 2014

I would also like to see this fixed. It is currently limiting my ability to use turf.js (morganherlocker/turf#92)

josephj commented Sep 11, 2014

I am trying to add this feature. I created an dragEnd event to check if it's intersected. If it is, then restoring the dragged marker back to previous position, also redrawing the polylines.

It's almost done. However, when I drag next or previous markers to trigger intersection, the restored polygon would lack of several points.

Anyone possibly to give me a hint?

    _onMarkerDragEnd: function (e) {

        // Allow intersection, stop here
        if (this.options.allowIntersection) {
            this._fireEdit();
            return;
        }

        var marker = e.target,
            intersects = false,
            polyLatLngs = this._poly.getLatLngs(),
            latlngs = [],
            polyLatLng,
            i;

        for (i in polyLatLngs) {
            if (polyLatLngs.hasOwnProperty(i)) {
                polyLatLng = polyLatLngs[i];
                if (this._poly.newLatLngIntersects(polyLatLng, true)) {
                    intersects = true;
                    polyLatLng = new L.LatLng(marker._srcLatLng.lat, marker._srcLatLng.lng);
                }
                latlngs.push(polyLatLng);
            }
        }

        // No intersection, stop here
        if (!intersects) {
            this._fireEdit();
            return;
        }

        // Reset this point in Polygon points array.
        this._poly.setLatLngs(latlngs);

        // Reset related markers
        marker.setLatLng(marker._srcLatLng);
        this.updateMarkers();
        this._poly.redraw();
    },

josephj commented Sep 14, 2014

I think it's all good now. The only thing left is I don't know how to make the allowIntersection:false option working when it instantiates.
http://lab.josephj.com/2014/Leaflet.draw/examples/polygon.html

Hi @josephj! Is your solution already working?

josephj commented Oct 16, 2014

@linyatis I still don't know how to make this option being configurable, but the feature works pretty good. You can check my commit. josephj/Leaflet.draw@9425d3b

Any news on this? I need this thingy configurable... don't know how to do it, either. ((

+1

I am using leaflet 1.0.3 version and leaflet draw 2.0.4 vrsion. the allowIntersection parameter is not working while creating a region.
currentDrawingRegion = new L.Draw.Rectangle(mapInstance, {
title: 'Draw a polygon!',
allowIntersection: false,
drawError: {
color: '#b00b00',
timeout: 2000
},
shapeOptions: {
// color: '#64b900',
color: '#fff',
weight: 1.5,
opacity: 0.2,
fillOpacity: 0.1,
fill: false
},
showArea: true
});
currentDrawingRegion.enable();

Please help me out .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment