androidopenstreetmaposmdroid

Click inside the Path in Openstreetmap


I have two overlays in my openstreetmap app, Itemized overlay and Path overlay together. I want to provide click inside the path inside the path overlay and custom marker


Solution

  • Finally I got answer for the Above question...

    Add all path overlays into a single layer.

    In on single tap check isPointOnLine(lox,loy,ltx,lty, x, y)

    public boolean isPointOnLine(double lox, double loy, double ltx,
            double lty, double x, double y) {
        // determine if point is on line
        Double dx = x - lox;
        Double dy = y - loy;
        Double tx = ltx - lox;
        Double ty = lty - loy;
    
        // normalise the line vector
        Double t1 = new Double(1 / Math.sqrt(tx * tx + ty * ty));
    
        tx *= t1;
        ty *= t1;
    
        // calculate inverse length of secondary vector
        Double dl = new Double(1 / Math.sqrt(dx * dx + dy * dy));
    
        // take dot product of normalised line vector, and rotated normalised
        // secondary vector
        Double dot = (dy * tx - dx * ty) * dl;
        // Increase these values for less or more picky
        if (dot < -0.2 || dot > 0.2)
            return false;
    
        // calculate distance along line segment by taking dot product of
        // normalised
        // line vector and un-normalised secondary vector
        Double dis = tx * dx + ty * dy;
        if (dis < 0 || dis > 1 / t1)
            return false;
    
        return true;
    }