This stackoverflow post was my original question. This page outlines the effort I went through in creating a usable javascript map of a city. The city I am interested is Delhi, India and I am specifically interested in its constituent assemblies. After a bit of research I found that in order to have usable image which can be manipulated via javascript the format to be targetted should be SVG. The final output is here.
1. Get the Official Map
The official constituent assembly map is in pdf format and is available from http://ceodelhi.gov.in/. The direct link is this. The below is the png version of the same.
For conversion from PDF to SVG, I used Inkscape. On the command prompt :
A couple steps involved here.
2. Convert PDF to SVG
inkscape.exe -l delhi.svg delhi.pdf
3. Process SVG
In Inkscape
In SVG-edit
4. Create JVector Map
We will use the excellent jvectormap library to create our map. The handy tool svgto.jvectormap will convert the svg from our last step to a jvectormap that we can finally use.
- Browse to the svgto.jvectormap tool.
- Copy the text of the SVG from the previous file and click convert to map. The default name of the map will be 'map'. You can change it.
- This will generate the vector map. You can now edit the ids and name of the paths as per your liking.
- Finally Save. This will give the output as a jvectormap. Save this file as js.
- Note to finally use it, you may have to change the json field "paths" to "pathes". A video which outlines the process :
5. Use the JVector Map
Now that the map is ready you can finally use it in any html page. Include the js file from the last step in a html page.
jQuery.fn.vectorMap('addMap', 'nameOfMap',{...,"pathes":{ ...
jQuery(document).ready(function() {
jQuery('#vmap').vectorMap(
{
map: 'nameOfMap',
...
}
You can refer as example to the html code from here
6. References
Note that the jvector map for delhi has ids which correspond to the official numbering for assembly constituents.
The encodings are as follows :
Encoding | Region |
---|---|
c | Central Delhi |
e | East Delhi |
nd | New Delhi |
n | Nort Delhi |
ne | North East Delhi |
nw | Nort West Delhi |
s | South Delhi |
sw | South West Delhi |