Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Open
stuporglue opened this Issue · 6 comments

5 participants

@stuporglue

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.

@jacobtoye
Owner

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
Closed

polygons that intersect themselves #92

@jduhls

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

@josephj

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

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

@linyatis

Hi @josephj! Is your solution already working?

@josephj

@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@9425d3b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.