L.Control.LineStringSelect icon indicating copy to clipboard operation
L.Control.LineStringSelect copied to clipboard

Set a fixed start point that doesn't respond to drag

Open jb2b38 opened this issue 9 years ago • 6 comments
trafficstars

How would it be possible to set a starting point that doesn't move, and only allow the end handle to respond to drag events? This would need blocking the swapping of start and end points to go only in one direction.

jb2b38 avatar Jan 14 '16 10:01 jb2b38

yes, I can add an option for that

w8r avatar Jan 14 '16 12:01 w8r

@jb2b38, how do you want to define the first(fixed) point?

w8r avatar Jan 14 '16 18:01 w8r

I already know the coordinates of a point of interest that will be on the polyline, so passing those coordinates would be great :)

jb2b38 avatar Jan 14 '16 21:01 jb2b38

@w8r I was able to add a snapping functionality by changing the closestPointOnSegment a bit. It looks like this:

function closestPointOnSegment(p2, p0, p1) {

  var snap_distance = 30;

  var point0 = new L.latLng(p0[0], p0[1]);
  var point1 = new L.latLng(p1[0], p1[1]);
  var point2 = new L.latLng(p2[0], p2[1]);

  var distance;
  if (point2.distanceTo(point0) < point2.distanceTo(point1)) {
    distance = point2.distanceTo(point0);
    if (distance < snap_distance) {
      return p0;
    }
  } else {
    distance = point2.distanceTo(point1);
    if (distance < snap_distance) {
      return p1;
    }
  }

  var t = pointLineSegmentParameter(p2, p0, p1),
    x10 = p1[0] - p0[0],
    y10 = p1[1] - p0[1],
    p3 = [p0[0] + t * x10, p0[1] + t * y10];
  return p3;
}

jb2b38 avatar Jan 18 '16 13:01 jb2b38

@jb2b38, :+1: :+1:

Do you want me to include that as an option? something like

new LineStringSelect({ snapping: distance});

w8r avatar Jan 18 '16 13:01 w8r

@w8r I think it'd be more useful for other uses if you can make it an option. I only did this quickly to have it work the way I need it at the moment, but it'd be more flexible :) How can I help you to only have a selection forward? I'm trying to figure how works the code but I don't really know where to look for this behaviour.

jb2b38 avatar Jan 18 '16 13:01 jb2b38