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

Closest layer between Circle and Line #10

Open
prophe05 opened this issue Dec 12, 2013 · 2 comments
Open

Closest layer between Circle and Line #10

prophe05 opened this issue Dec 12, 2013 · 2 comments

Comments

@prophe05
Copy link

When line traverse circle in center, what is the closest layer in case of

  1. mouse is over border of circle
  2. line is the first layer in the layers array?
    Now line is the closest layer to mouse position. But correct - circle is the closest layer. Need to find closest distance to mouse position using latlng of circle center and it's radius!

maybe edit method closestLayer: function (map, layers, latlng);
like:

closestLayer: function (map, layers, latlng) {
        var mindist = Infinity,
            result = null,
            ll = null,
            distance = Infinity;

        for (var i = 0, n = layers.length; i < n; i++) {
            var layer = layers[i];
            // Single dimension, snap on points, else snap on closest
            if (typeof layer.getLatLng == 'function') {
                ll = layer.getLatLng();
                distance = L.GeometryUtil.distance(map, latlng, ll);

                if (layer instanceof L.Circle){
                    distance = distance - layer.getRadius();
                }
            }
            else {
                ll = L.GeometryUtil.closest(map, layer, latlng);
                if (ll) distance = ll.distance; // Can return null if layer has no points.
            }
            if (distance < mindist) {
                mindist = distance;
                result = {layer: layer, latlng: ll, distance: distance};
            }
        }
        return result;
    }
@leplatrem
Copy link
Collaborator

Indeed, currently, we ignore the circle radius to compute distances.

If you have any idea about a sound way to implement this, do not hesitate to contribute ! I would be glad to review your pull-request !

Thanks !

@danyhoron
Copy link
Contributor

I created a PR that finds the closest point on a Circle. #101

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

No branches or pull requests

3 participants