Search code examples
androidgraphicsvectorsvgimagemap

Android image map. - displaying an .svg and using it as an image map (touch zones)


I am looking for a way to display an image and have the user tap on different parts of the image to navigate and perform actions.

I was considering using an invisible color map to check which parts have been touched.

But since i also want to highlight the selected areas, i was thinking of using vectors. There is a nice library to render svg files into an image view here, but it doesn't handle touches.
Is there a library out there that does? Or any smarter way of doing this?

(I also checked out this project but it won't swallow .svg files and my vector image is far too complex to insert all the data by hand)


Solution

  • Interesting problem! I'm not convinced you can't use a combination of the libraries you mentioned.

    What I would do is first use SVG-Android to programmatically read in your SVG file. Looking at SVG-Android, it looks like it returns the final product as a PictureDrawable, which is a subclass of Drawable.

    Right after SVG-Android finishes processing the SVG graphics, I'd use ImageView.setImageDrawable to load the main ImageView with the PictureDrawable we just generated. Then I'd just use that ImageView as the base for the implementation of "Images with Clickable Areas" you linked in the original question.

    Honestly, I think the hardest part will be getting SVG-Android to work correctly (I've played with it a bit, and it's a bit finicky). However, I don't think you'll have much difficulty combining the SVG-generated drawable with the clickable areas. It's a simple change in the source of the base image.

    Good luck!