Can anyone recommend a Java component that lets you create a pretty looking image of a world map, highlighting certain countries (based on some statistics). Something similar to this image:
Something similar to Google Geo Charts (but for Java): https://developers.google.com/chart/interactive/docs/gallery/geochart but runs on the server side, without an internet connection. Ideally I'd like to attach weight to a few countries which would highlight them proportionally.
Either open source or commercial (as long as it's not something ridiculously priced).
As a start you could easily roll a component or rather a function like that yourself using an SVG worldmap (e.g this). Keep a
java.util.Map
of country names to path elements as given in the SVG source. Your function would take a set of country names and essentially return the svg for the map as a string. Where the id of the path matches one in the set you would add a fill attribute with the color you want ...Here is the code. You will need to download this and have it as
world.svg
in the same folder. Then pass in the countries you want highlighted as arguments. The program will write a fileout.svg
which you can open in a browser (I used Firefox). I hope it does the trick. I only tried running it from eclipse ...I couldn't find a java library to do what you were looking for, so I looked into taking an SVG and modifying its style, and converting it to an image. First thought that came to my mind for this task: Apache Batik.
I chose to use the open source svg maps available on wikimedia (similar to Gregor Opheys answer) because not does it make it so you're not concerned about licensing, it also is already ready-made for simple CSS modifications by country. (See the SVG comments for instructions). There is one hitch, some of those image on wikimedia were generated by a python script, which puts the CSS styling also in the elements. If you want to use one of these SVG files, you'll have to handle for that.
To my happy surprise, there was almost a perfect example on the batik wiki, needing just a couple tweaks. I was able to produce a modified image (png) with one small syntax change (their outfile file is named .jpg but its using a png transcoder) and a small change to load the svg from the project resources instead of disk. Below is the example code with my minor changes:
As I mentioned, the way this works is by adding CSS to the SVG prior to converting it to the raster image you need. The secret sauce is the
SVGStyleElement
, here you can see that the United States is turned green. For any other country, you would simply use their 2-letter digraph and chose the color you would like to fill. Of course, since it's CSS, you can also do things like change the border colors or use a background image instead of a color, so you have a lot of flexibility there.I did have to play with the dependencies a bit, so to get you past this hurdle, I'll include my maven dependencies:
If you use a different build manager, let me know, and I can dump the transitive dependency tree.
I think better for you :
source : gvSIG Wikipedia
Have a look at GeoTools, it may have what you need.
Haven't used it and not sure if it is appropriate for your needs but you can have a look at Nasa WorldWind. It features an SDK and it seems like that there is an off-line mode available.
Check :
http://worldwind.arc.nasa.gov/java/ and http://goworldwind.org/demos/
http://goworldwind.org/examples/#network (for offline mode)
Well, you can make a GWT App for that. GWT(Google Web ToolKit) is a Java based app making plateform. It provides same kind of visualization APIs as you see in Google Charts javascript API but in java code.Checkout this link for Java based Chart API and live example of geo chart in Java Code http://gwt-charts.appspot.com/#geochart . Hope this helps :)