Skip to content
Related Articles

Related Articles

Creating interactive maps and Geo Visualizations in Java
  • Last Updated : 20 May, 2020

Unfolding is a library to create interactive maps and geo visualizations in Processing and Java. In this article, we will discuss what are the features of unfolding and how it is used to create interactive maps in Java and Processing.

The main purpose of using unfolding is to create not only static maps but also interactive maps in both java and processing. It can easily be installed on eclipse by downloading the unfolding template from the official website. It is widely used due to the features provided by unfolding like:

  1. Interaction Events: In unfolding, we can easily create interactive maps. The basic interactions like zoom and pan are included in this library. Apart from these, more advanced features like overview, details or multitouch gestures can also be easily added to the maps.
  2. Data Visualization: This library is very robust that it even lets users create geo-positioned markers to display the data on a map. This visual style can be freely adapted. This library also supports users to load and display user-defined shapes like points, lines or polygons.
  3. Styled Maps: This library is a title-based map library. This library allows map titles to have various geographic features and styles. It also comes with map providers like OpenStreetMap or TileMill.
  4. Clean & Extendable Code: This library allows the beginners to easily create simple maps. Advanced users can also sketch their prototypes or create their own sophisticated visualizations.

In this implementation, let’s consider to draw two maps, one is Delhi and the other is Mumbai using this library. The map created is interactive as we can zoom in and zoom out. We need to set up our maps using the latitude and the longitude of the place. The draw function in the program runs repeatedly and draws the map repeatedly on the canvas.

Below is the implementation of the above approach:

// Java implementation of using
// unfolding maps
// Importing the libraries in eclipse
import processing.core.PApplet;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.geo.Location;
import de.fhpotsdam.unfolding
import de.fhpotsdam.unfolding
import de.fhpotsdam.unfolding
import de.fhpotsdam.unfolding
// Class to make the map
public class MakeYourMap extends PApplet {
    // To keep eclipse from reporting
    // a warning
    private static final long
        = 1L;
    // Initializing the height and
    // width of the map
    private static int mapWidth = 350;
    private static int mapHeight = 500;
    // This map is used to display Mumbai
    UnfoldingMap map1;
    // This map is used to display Delhi
    UnfoldingMap map2;
    // Function which implements the unfolds
    // library
    public void setup()
        // Set the Applet window to be
        // 900x600 width and height.
        // The OPENGL argument indicates
        // to use the Processing
        // library's 2D drawing
        size(900, 600, P2D);
        // This sets the background colour
        // for the Applet. Here, colour
        // blue is choosen
        this.background(0, 0, 128);
        // Select a map provider.
        // Here we are using google provider
        AbstractMapProvider provider
            = new Google.GoogleTerrainProvider();
        // Set a zoom level to focus on
        // our specified location
        int zoomLevel = 10;
        // Creating the first map
        map1 = new UnfoldingMap(
            this, 40, 50, mapWidth,
            mapHeight, provider);
        // This line zooms in and centers
        // the map at 28.7041 (latitude)
        // and  77.1025° (longitude) for Mumbai.
            new Location(28.7041f, 77.1025f));
        // This line makes the map interactive
        // as we can zoom in and out. And, here
        // we have zoomed our focus to the
        // Mumbai location by setting the
        // zoom level to 10.
                this, map1);
        // Creating the same map for
        // Delhi
        AbstractMapProvider provider2
            = new Google.GoogleMapProvider();
        map2 = new UnfoldingMap(
            this, 40 + mapWidth + 10, 50,
            mapWidth, mapHeight, provider2);
        // 19.0760 (latitude) and
        // 72.8777 (longitude) are for Delhi
            new Location(19.0760f, 72.8777f));
        // This line makes the map interactive
                this, map2);
    // Function to draw the applet window
    public void draw()
        // The draw method is implemented
        // repeatedly by drawing our maps
        // again and again on the canvas

Output: On running the above code, the following output is obtained:

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :