https://kotlinlang.org logo
#compose
Title
# compose
c

Cyril Kym

04/24/2022, 12:24 PM
Hi Everybody, I'm currently working on a custom input composable for an app. The goal is to display a map of Switzerland and it's cantons ("same thing as states in the US"). I then want to be able to recognize the user tapping on one of the cantons. My current approach is to convert an SVG of Switzerland with the Cantons as paths to a list of points with coordinates (using https://spotify.github.io/coordinator/). I then draw these coordinates to a canvas using drawPath(). I'm currently not sure if this is the most effective approach, therefore I'd like to ask for your feedback. Also I'm not sure how I will be able to recognize the touch of a canton with my approach. I was planning on drawing each canton as it's own path, but I don't think compose provides an event listener for the tap on a path (or am I wrong?). So I think I would need to get the coordinates of a tap and then match them to the correct canton.
👀 1
m

Michael Paus

04/24/2022, 1:42 PM
Your overall approach seems to be all right. As you have already mentioned you will have to do the intersection test yourself. This may be a little bit over the top for just a simple point inside path test but for more ambitious projects I like to use this (Java) library. https://github.com/locationtech/jts It works on all Java platforms (Android, JVM)
👍 1
2 Views