Giter VIP home page Giter VIP logo

clickzoomsvg's Introduction

ClickZoomSVG

Temporary project for adding click and zoom functionalities on SVG in Android

IMPORTANT

Project is used just for as a code sample. It is not final application, neither contains full code. I am not able to share full neither partial working code, but only this. So, this will not be maintained at all (but contains crutial parts for you to make it work :) ). Contact me for additional details or any help (I'll be glad to help if I can).

Code can be optimized a lot, for sure, so fee free to do whatever you want :)

Hints

Important Dependencies:

'Usage'

SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.world_map);

// Get image view (this is our SVG map that is going to be clickable and zoomable):
ImageView touchImageView = (ImageView) view.findViewById(R.id.touchImageView);

// Create drawable (will convert svg to drawable so we can set it to image view as a bitmap):
PictureDrawable image = svg.createPictureDrawable();
Bitmap b = drawableToBitmap(image); // refer to WorldMapFragment for source code of the converting method 
touchImageView.setImageBitmap(b);

// Create image with clickable areas from previous image view and set listener to id (listener of type OnClickableAreaClickedListener created in onAttach callback):
ClickableAreasImage clickableAreasImage = new ClickableAreasImage(new PhotoViewAttacher(touchImageView), listener);
  
// Define your clickable areas
// parameter values (pixels): (x coordinate, y coordinate, width, h	eight) and assign an object to it
List<ClickableArea> clickableAreas = new ArrayList<>();
Map<String, FintemCity> cities = svg.getCities();
for (String key : cities.keySet()){
  clickableAreas.add(cities.get(key).toClickableArea(getMetrics()));
}
  
// Set your clickable areas to the image
clickableAreasImage.setClickableAreas(clickableAreas);

Please refer primarly to WorldMapFragment for core of the solution. Other things are probably unnecesarry. Many details can be found on dependencies' repos, so look for it.

There is an World Map svg demo for which this code works.

Additionally, I'll be gratefull if someone use this and make a nice HowTo, I really don't have time for it.

Cheers!

clickzoomsvg's People

Contributors

alexmilutinovic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.