OwnWeb / flutter_map_tappable_polyline

A tappable Polyline plugin for flutter_map
https://pub.dev/packages/flutter_map_tappable_polyline
MIT License
54 stars 45 forks source link

can you make polygon tappable? #55

Closed JokerSora closed 1 year ago

JokerSora commented 1 year ago

em,now polygon can't be tapped

MaxiStefan commented 1 year ago

You can safely use this function to determine if you tapped on a polygon.

` static bool isPointInPolygon(LatLng point, Polygon polygon) { double x = point.latitude, y = point.longitude;

bool inside = false;

for (var i = 0, j = polygon.points.length - 1;
    i < polygon.points.length;
    j = i++) {
  var xi = polygon.points[i].latitude, yi = polygon.points[i].longitude;
  var xj = polygon.points[j].latitude, yj = polygon.points[j].longitude;

  var intersect =
      ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);

  inside = intersect ? !inside : inside;
}

return inside;

}`

tuarrep commented 1 year ago

This package aims to make polylines tappable not polygons